/* Copyright (c) 2010 Synology Inc. All rights reserved. */

Ext.ns("SYNO.SDS");SYNO.SDS.ModalWindow=Ext.extend(Ext.Window,{constructor:function(a){var b=Ext.apply(a||{},{modal:true,closable:false});SYNO.SDS.ModalWindow.superclass.constructor.call(this,b)}});Ext.override(Ext.Container,{getMsgBox:function(){return SYNO.SDS.MessageBox}});SYNO.SDS.AppInstance={};Ext.apply(SYNO.SDS.AppInstance,{getUserSettings:function(a){return SYNO.SDS.UserSettings.getProperty("SYNO.SDS.App.FileStation3",a)},setUserSettings:function(a,b){return SYNO.SDS.UserSettings.setProperty("SYNO.SDS.App.FileStation3",a,b)}});Ext.override(Ext.Component,{getTaskRunner:function(){if(!this.taskRunner){this.taskRunner=new SYNO.SDS.TaskRunner();this.addManagedComponent(this.taskRunner)}return this.taskRunner},addTask:function(a){return this.getTaskRunner().createTask(a)},addAjaxTask:function(a){return this.getTaskRunner().createAjaxTask(a)},getTask:function(a){if(!this.taskRunner){return null}return this.taskRunner.getTask(a)},removeTask:function(b){var a=this.getTask(b);if(a){a.remove()}return a},addManagedComponent:function(a){this.components=this.components||[];this.components.push(a);return a},removeManagedComponent:function(a){this.components=this.components||[];this.components.remove(a);return a},beforeDestroy:function(){this.taskRunner=null;this.components=this.components||[];for(var a=0;a<this.components.length;++a){try{this.components[a].destroy()}catch(b){if(Ext.isDefined(SYNO.SDS.JSDebug)){SYNO.Debug(this.id+" sub-components["+a+"] destroy failed.");SYNO.Debug(this.components[a]);throw b}}}delete this.components}});SYNOFILESTATION_LOGINDIALOG=function(b){Ext.apply(this,b||{});var a=this.init();var c={modal:true,width:450,height:350,shadow:true,minWidth:370,minHeight:300,closable:false,collapsible:false,constrain:true,plain:true,title:g_LoginTitle,layout:"fit",items:new Ext.TabPanel({deferredRender:false,activeTab:0,defaults:{autoScroll:false},items:a}),buttons:[{text:g_Submit,scope:this,handler:this.onClickSubmit}],keys:[{key:[10,13],fn:this.onClickSubmit,scope:this}],listeners:{afterlayout:{fn:this.center,scope:this,single:true},show:{fn:function(){this.findById("username").focus(true,600)},scope:this},beforeshow:{fn:this.reset,scope:this}}};SYNOFILESTATION_LOGINDIALOG.superclass.constructor.call(this,c)};Ext.extend(SYNOFILESTATION_LOGINDIALOG,Ext.Window,{form:null,messageContainer:null,text_field_username:null,text_field_password:null,photo_url:null,init:function(){this.messageContainer=new Ext.form.DisplayField({style:"margin-bottom: 20px; font-size: 12px",hideLabel:true,autoScroll:false,value:g_LoginDesc});this.text_field_username=new Ext.form.TextField({id:"username",fieldLabel:g_LoginAccount,name:"username",allowBlank:false,width:170,validateOnBlur:true,validationEvent:"blur"});this.text_field_password=new Ext.form.TextField({fieldLabel:g_LoginPasswd,name:"passwd",inputType:"password",width:170,validateOnBlur:true,validationEvent:"blur"});this.form=new Ext.form.FormPanel({title:g_Login,labelWidth:100,labelAlign:"right",buttonAlign:"right",trackResetOnLoad:true,width:300,defaluts:{autoScroll:false},border:false,bodyStyle:"padding: 20px",items:[this.messageContainer,this.text_field_username,this.text_field_password]});this.form.form.on("actioncomplete",function(b,c){var a=this.messageContainer.getEl();if(c.result.success=="login_error"){a.dom.innerHTML="<font size='+1'>"+g_WelcomeMsg+"</br></font><font color='#FF0000'>"+g_LoginError+"</font><br>"+g_LoginDesc}else{if(c.result.success=="disable_account"){a.dom.innerHTML="<font size='+1'>"+g_WelcomeMsg+"</br></font><font color='#FF0000'>"+g_LoginAccDis+"</font><br>"+g_LoginDesc}else{if(c.result.success=="error_guest"){a.dom.innerHTML="<font size='+1'>"+g_WelcomeMsg+"</br></font><font color='#FF0000'>"+g_LoginGuestErr+"</font><br>"+g_LoginDesc}else{if(c.result.success=="error_noprivilege"){a.dom.innerHTML="<font size='+1'>"+g_WelcomeMsg+"</br></font><font color='#FF0000'>"+g_LoginPriErr+"</font><br>"+g_LoginDesc}else{if(c.result.success=="error_systemfull"){a.dom.innerHTML="<font size='+1'>"+g_WelcomeMsg+"</br></font><font color='#FF0000'>"+g_LoginSysFull+"</font><br>"+g_LoginDesc}else{window.location="/index.cgi";this.close()}}}}}},this);return this.form},reset:function(){this.form.form.reset();var a=this.messageContainer.getEl();a.setWidth(a.getWidth());a.dom.innerHTML="<font size='+1'>"+g_WelcomeMsg+"</br></font>"+g_LoginDesc},onClickSubmit:function(){if(this.form.form.isValid()){this.form.form.submit({url:"login.cgi",waitTitle:g_Login,waitMsg:g_PlzWait,params:{action:"login",username:this.text_field_username.getValue(),passwd:this.text_field_password.getValue()}})}},show_dialog:function(){this.show()}});