function _meta_(v,m){var ms=v['__meta__']||{};for(var k in m){ms[k]=m[k]};v['__meta__']=ms;return v}
var login={}
var __this__=login
login.Login=Extend.Class({name:'login.Login',parent:forms.Form,properties:{ui:undefined,callback:undefined},initialize:_meta_(function(selector,callback){var __this__=this
selector=selector===undefined?".Login":selector
__this__.getSuper(login.Login.getParent())(selector)
if((callback==undefined))
{__this__.callback=__this__.defaultCallback;}
else if(true)
{__this__.callback=callback;}
$(__this__.ui)[0]._model=__this__;},{arguments:[{'flags':'=','name':'selector'},{'name':'callback'}]}),methods:{bindUI:_meta_(function(){var __this__=this
__this__.getSuper(login.Login.getParent()).bindUI()
if(((window.location.hash!=undefined)&&(window.location.hash=="#ForgotPassword")))
{__this__.do_showForgotPassword()}
else if(true)
{__this__.do_showLogin()}},{arguments:[]}),hidePanels:_meta_(function(){var __this__=this
__this__.hideErrors()
$(".panel",__this__.ui).hide()},{arguments:[]}),do_showLogin:_meta_(function(){var __this__=this
__this__.hidePanels()
$(".panel.Main",__this__.ui).show()
$(".panel.Main .error",__this__.ui).html("&nbsp;").hide()
$(".panel.Main .errorBox .error",__this__.ui).html("&nbsp;").show()
$(".panel.Main input",__this__.ui).removeClass("invalid")},{arguments:[]}),do_showForgotPassword:_meta_(function(){var __this__=this
__this__.hidePanels()
username=__this__.input("username");if((username.indexOf("@")>0))
{__this__.input("email",username)}
$(".panel.ForgotPassword",__this__.ui).show()
$(".panel.ForgotPassword .error",__this__.ui).html("&nbsp;").hide()
$("form.forgot input:first",__this__.ui).select().focus()},{arguments:[]}),do_showSentPassword:_meta_(function(){var __this__=this
__this__.hidePanels()
$(".panel.SentPassword .out-email",__this__.ui).html(__this__.input("email"))
$(".panel.SentPassword",__this__.ui).show()
$(".forgot .in-email",__this__.ui).val("")},{arguments:[]}),do_login:_meta_(function(event){var __this__=this
event.preventDefault()
__this__.hideErrors()
$(".operations del.button, .operations span.button, .operations .working-indicator",__this__.ui).toggle()
var f=Application.world.User.$login(__this__.input("username"),__this__.input("password"),false);f.onSucceed(_meta_(function(user){__this__.callback(user)},{arguments:[{'name':'user'}]}))
f.onFail(_meta_(function(status,response,channel){$(".operations del.button, .operations span.button, .operations .working-indicator",__this__.ui).toggle()
var e=AkohaGenericError.makeFailure(status,channel);__this__.assertException(e,"AKOHA_INVALID_LOGIN")
__this__.setFieldStatus("id_username",e.context.username)
__this__.setFieldStatus("id_password",e.context.password)
__this__.displayError("Oops!",e.reason)},{arguments:[{'name':'status'},{'name':'response'},{'name':'channel'}]}))
return false},{arguments:[{'name':'event'}]}),do_recover:_meta_(function(event){var __this__=this
event.preventDefault()
__this__.hideErrors()
var f=Application.world.User.$recover_password(__this__.input("email"),false);$(".operations del.button, .operations span.button, .operations .working-indicator",__this__.ui).toggle()
f.onSucceed(_meta_(function(){$(".operations del.button, .operations span.button, .operations .working-indicator",__this__.ui).toggle()
__this__.do_showSentPassword()},{arguments:[]}))
f.onFail(_meta_(function(status,response,channel){$(".operations del.button, .operations span.button, .operations .working-indicator",__this__.ui).toggle()
var e=AkohaGenericError.makeFailure(status,channel);__this__.assertException(e,"AKOHA_INVALID_EMAIL")
__this__.setFieldStatus("id_email",e.context.email)
__this__.displayError("Uh oh!",e.reason)},{arguments:[{'name':'status'},{'name':'response'},{'name':'channel'}]}))
return false},{arguments:[{'name':'event'}]}),validate_login:_meta_(function(){var __this__=this
return Application.world.User.$login(__this__.input("username"),__this__.input("password"),true)},{arguments:[]}),check_username:_meta_(function(){var __this__=this
__this__.handleFieldStatus(__this__.validate_login(),"username","AKOHA_INVALID_LOGIN")},{arguments:[]}),check_password:_meta_(function(){var __this__=this
__this__.handleFieldStatus(__this__.validate_login(),"password","AKOHA_INVALID_LOGIN")},{arguments:[]}),check_email:_meta_(function(){var __this__=this
var future=Application.world.User.$recover_password(__this__.input("email"),true);__this__.handleFieldStatus(future,"email","AKOHA_INVALID_EMAIL")},{arguments:[]}),setDefaultCallback:_meta_(function(callback){var __this__=this
__this__.callback=callback;},{arguments:[{'name':'callback'}]}),defaultCallback:_meta_(function(user){var __this__=this
destination=__this__.input("destination");if(destination)
{Application.redirect(destination)}
else if(true)
{Application.redirect("/home/")}},{arguments:[{'name':'user'}]})}})
login.init=_meta_(function(){var __this__=login;$(document).ready(_meta_(function(){if($("#Login").length)
{new login.Login()}},{arguments:[]}))},{arguments:[]})
login.init()