// Copyright (c) 2008 Synology Inc. All rights reserved.
SYNOPHOTO_LOGINDIALOG=function(_1,_2){var _3={modal:true,autoTabs:true,autoCreate:true,width:370,height:250,shadow:true,minWidth:370,minHeight:250,proxyDrag:true,closable:true,collapsible:false,center:{autoScroll:false,tabPosition:"top",closeOnTab:true,titlebar:false,alwaysShowTabs:true}};_2=_2?Ext.applyIf(_2,_3):_3;SYNOPHOTO_LOGINDIALOG.superclass.constructor.call(this,_1,_2);this.addButton(photo_str_btnOK,this.onClickSubmit,this);if(_2.closable){this.addButton(photo_str_btnClose,this.hide,this);this.addKeyListener(27,this.hide,this);}this.init();this.getLayout().getRegion("center").showPanel(0);this.addKeyListener([10,13],this.onClickSubmit,this);};Ext.extend(SYNOPHOTO_LOGINDIALOG,Ext.LayoutDialog,{form:null,messageContainer:Ext.id(),text_field_username:null,text_field_password:null,photo_url:null,init:function(){var _4=Ext.id();var _5=String.format("<div style=\"margin:20px; font-size:12px;\" id=\"{0}\">{1}</div><div style=\"margin:20px;\" id=\"{2}\"></div>",this.messageContainer,photo_login_hint,_4);var _6=this.getLayout();_6.beginUpdate();var cp=_6.add("center",new Ext.ContentPanel(Ext.id(),{autoCreate:true,title:photo_login,background:true}));_6.endUpdate();cp.setContent(_5);this.form=new Ext.form.Form({labelWidth:100,labelAlign:"right",buttonAlign:"right",trackResetOnLoad:true,el:"login_form"});this.text_field_username=new Ext.form.TextField({fieldLabel:photo_username,name:"username",allowBlank:false,width:170,validateOnBlur:true,validationEvent:"blur",el:"login_username"});this.text_field_password=new Ext.form.TextField({fieldLabel:photo_password,name:"passwd",inputType:"password",width:170,validateOnBlur:true,validationEvent:"blur",el:"login_passwd"});this.form.column({width:300},this.text_field_username,this.text_field_password);if(!Ext.isSafari){Ext.fly("login_form").on("submit",Ext.emptyFn,this,{stopEvent:true});}Ext.fly("login_form").appendTo(_4);this.form.render(_4);SYNOBLOG_UTILS.SetTextMaxLen(this.form,"username",15);SYNOBLOG_UTILS.SetTextMaxLen(this.form,"passwd",128);this.on("show",function(_8){if(typeof onKeyMapSwitch=="function"){onKeyMapSwitch(false);}_8.text_field_username.focus();_8.text_field_username.focus();});this.on("hide",function(_9){if(typeof onKeyMapSwitch=="function"){onKeyMapSwitch(true);}});var el;this.form.on("actioncomplete",function(_b,_c){if(_c.result.success=="login_error"){el=Ext.get(this.messageContainer);el.dom.innerHTML="<font color='#FF0000'>"+photo_login_failed+"</font><br>"+photo_login_hint;}else{if(_c.result.success=="disable_account"){el=Ext.get(this.messageContainer);el.dom.innerHTML="<font color='#FF0000'>"+photo_login_disabled+"</font><br>"+photo_login_hint;}else{if(_c.result.success=="login_noprivilege"){el=Ext.get(this.messageContainer);el.dom.innerHTML="<font color='#FF0000'>"+photo_login_noprivilege+"</font><br>"+photo_login_hint;}else{this.hide();var _d="/photo/index.php";if(this.photo_url!=null&&this.photo_url!=""){_d=this.photo_url;}window.location=_d;}}}},this);},reset:function(){this.form.reset();var el=Ext.get(this.messageContainer);el.dom.innerHTML=photo_login_hint;},onClickSubmit:function(){if(this.form.isValid()){Ext.fly("login_submit").dom.click();this.form.submit({url:"/blog/login.php",waitTitle:" ",waitMsg:photo_str_plz_wait,params:{action:"login",url:this.photo_url,username:this.text_field_username.getValue(),passwd:this.text_field_password.getValue()}});}},show_dialog:function(_f){this.photo_url=_f;this.show();}});function onLogin(url){var _11=Ext.DialogManager.get("login-dlg");if(!_11){_11=new SYNOPHOTO_LOGINDIALOG("login-dlg");}_11.reset();_11.show_dialog(url);}Ext.namespace("SYNOBLOG_UTILS");Ext.Ajax.on("requestcomplete",function(_1,_2,_3){if(SYNOBLOG_UTILS.checkServerError(_2)){_1.purgeListeners();}});SYNOBLOG_UTILS.SetTextMaxLen=function(_4,_5,_6){var _7=_4.findField(_5);if(_7){_7.getEl().dom.setAttribute("maxLength",_6);}};SYNOBLOG_UTILS.checkServerError=function(_8){var _9=false;var _a=window.location.href;if(_a.indexOf("/blog")>=0){_9=true;}if(_8&&_8.getResponseHeader){var _b=_8.getResponseHeader["x-request-error"];if(_b){_b=Ext.util.Format.trim(_b);var _c;if(_9){_c=blog_str_common_error;}else{_c=photo_str_common_error;}if(_b=="error_timeout"){if(_9){_c=blog_str_common_session_timeout;}else{_c=photo_str_common_session_timeout;}}alert(_c);if(_9){window.location="/blog/index.php";}else{window.location="/photo/index.php";}return true;}}return false;};SYNOBLOG_UTILS.arrayFindIndex=function(_d,_e){var i,_10=-1;for(i in _d){if(_d[i]==_e){_10=i;break;}}return _10;};Ext.form.SRadio=function(cfg){if(cfg.indent&&cfg.indent>0){var _12=13*cfg.indent;var _13=String.format("display: inline;width:{0}px;",_12);cfg.labelStyle=_13;cfg.labelSeparator="";}Ext.form.SRadio.superclass.constructor.apply(this,arguments);};Ext.extend(Ext.form.SRadio,Ext.form.Radio,{setValue:function(v){var _15=this.el.up("form").query("input[name="+this.el.dom.name+"]");if(typeof v=="string"){for(var j=0;j<_15.length;j++){var _17=Ext.getCmp(_15[j].id);if(_15[j].value==v){_15[j].checked=true;}else{_15[j].checked=false;}_17.checked=_15[j].checked;_17.fireEvent("check",_17,_17.checked);}}else{if(typeof v=="boolean"){if(v===true){this.setValue(this.el.dom.value);}}}},onClick:function(){if(this.el.dom.checked!=this.checked){this.setValue(this.el.dom.value);}}});