Skip to content

Instantly share code, notes, and snippets.

@sprite2005
Created December 21, 2010 00:17
Show Gist options
  • Save sprite2005/749280 to your computer and use it in GitHub Desktop.
Save sprite2005/749280 to your computer and use it in GitHub Desktop.
class LoginFormComponent < Netzke::Base
js_base_class "Ext.form.FormPanel"
def configuration
super.merge({
:items => [{
:xtype => :fieldset,
:title => 'Login Form',
:items => [
{
:xtype => :emailfield,
:name => :email,
:label => 'Email'
},
{
:xtype => :passwordfield,
:name => :password,
:label => 'Password'
}]
},
{
:xtype => :button,
:text => 'Login',
:handler => :do_login,
}
]
})
end
js_method :do_login, <<-JS
function()
{
Ext.Ajax.request({
url: '/users/sign_in',
method: 'post',
params: { email: this.getValues().email, password : this.getValues().password },
failure : function(response){
data = Ext.decode(response.responseText);
Ext.Msg.alert('Login Error', data.errorMessage, Ext.emptyFn);
},
success: function(response, opts) {
data = Ext.decode(response.responseText);
if (data.errors != null)
{
Ext.Msg.alert('Login Error', data.errors.reason, Ext.emptyFn);
} else {
Ext.Msg.alert('Login Ok', "Ok", Ext.emptyFn);
}
}
});
}
JS
endpoint :new_user_session do |params|
logger.info "Called new user session"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment