var LoginModule=function(a,b){this.main=Ext.get("loginmod-"+a);this.form=Ext.get("loginmod-"+a+"-form");this.email=Ext.get("loginmod-"+a+"-email");this.password=Ext.get("loginmod-"+a+"-password");this.login=Ext.get("loginmod-"+a+"-login");this.recover=Ext.get("loginmod-"+a+"-recover");this.error=Ext.get("loginmod-"+a+"-error");this.texts=b;this.form.on("submit",this.onSubmit,this);this.recover.on("mouseover",this.onRecoverOver,this);this.recover.on("mouseout",this.onRecoverOut,this);this.recover.on("click",this.onForgotPassword,this);this.email.on("keydown",this.onKeydown,this);this.password.on("keydown",this.onKeydown,this);Ext.onReady(function(){this.email.focus()},this)};LoginModule.prototype={emailRegex:/^(\w+)([\-+.][\w]+)*@(\w[\-\w]*\.){1,5}([A-Za-z]){2,6}$/,tt:function(a){return this.texts[a]},onKeydown:function(a){if(a.ctrlKey&&a.getKey()==13){a.stopEvent();this.onForgotPassword.call(this)}this.hideError.call(this)},onSubmit:function(a){a.stopEvent();if(this.form.loading){return false}this.form.loading=true;if(this.email.dom.value.length==0||this.password.dom.value.length==0){this.displayError(this.tt("empty_fields"));return false}this.addLoading();Ext.Ajax.request({url:"/users/login",scope:this,params:{ext:"true","data[User][username]":this.email.dom.value,"data[User][password]":this.password.dom.value,"data[User][remember]":"on"},success:function(b,c){var d=Ext.util.JSON.decode(b.responseText);if(d.success){window.location.href="/profile"}else{this.form.loading=false;this.resetSubmitBtn();this.displayError(this.tt("invalid_login"))}}})},onForgotPassword:function(){if(this.form.loading){return false}this.form.loading=true;if(this.email.dom.value.length==0){this.displayError(this.tt("email_is_empty"));return false}if(!this.emailRegex.test(this.email.dom.value)){this.displayError(this.tt("invalid_email"));return false}this.recover.addClass("t-loading");Ext.Ajax.request({url:"/profile/changePasswordSendUrl",scope:this,params:{email:this.email.dom.value},success:function(a,b){this.form.loading=false;this.recover.removeClass("t-loading");var c=Ext.util.JSON.decode(a.responseText);if(c.success){this.afterForgotPasswordSuccess()}else{this.displayError(c.errorInfo)}}})},afterForgotPasswordSuccess:function(){if(!this.forgotPwdTpl){this.forgotPwdTpl=new Ext.Template('<div class="forgot-pwd-success">{text}</div>')}this.forgotPwdTpl.overwrite(this.main.dom,{text:this.tt("forgot_pwd_success_msg").replace("{email}",this.email.dom.value)})},addLoading:function(){this.login.addClass("t-loading");this.login.dom.value=this.tt("please_wait")},onRecoverOver:function(){this.form.addClass("recover-hover")},onRecoverOut:function(){this.form.removeClass("recover-hover")},displayError:function(a){this.form.addClass("error");this.error.update("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+a);this.errorDisplayed=true},hideError:function(){if(!this.errorDisplayed){return}this.form.removeClass("error");this.form.loading=false;this.errorDisplayed=false},resetSubmitBtn:function(){if(this.form.loading){return}this.login.removeClass("t-loading");this.login.dom.value=this.tt("submit_button")}};
