1 GILBERT_PLUGINS.push(new (function() {
3 init: function(application) {
4 if (GILBERT_LOGGED_IN) {
5 application.on('ready', this.addUserMenu, this, {
9 application.on('ready', this.showLoginWindow, this, {
14 addUserMenu: function(application) {
15 Gilbert.api.auth.whoami(function(result) {
16 application.mainmenu.add({
22 iconCls: 'user-silhouette',
23 text: '<span style="font-weight: bolder;">' + result + '</span>',
25 text: 'Change password',
26 iconCls: 'key--pencil',
27 handler: function(button, event) {
28 Gilbert.api.auth.get_passwd_form(function(formspec) {
29 var change_password_window = application.createWindow({
32 title: 'Change password',
33 iconCls: 'key--pencil',
36 items: change_password_form = new Ext.FormPanel(Ext.applyIf({
38 bodyStyle: 'padding: 5px 5px 0',
40 text: 'Change password',
41 iconCls: 'key--pencil',
42 handler: function(button, event) {
43 change_password_form.getForm().submit({
44 success: function(form, action) {
45 Ext.MessageBox.alert('Password changed', 'Your password has been changed.');
51 submit: Gilbert.api.auth.submit_passwd_form,
55 change_password_window.show();
61 iconCls: 'door-open-out',
62 handler: function(button, event) {
63 Gilbert.api.auth.logout(function(result) {
65 document.location.reload();
67 Ext.MessageBox.alert('Log out failed', 'You have <strong>not</strong> been logged out. This could mean that your connection with the server has been severed. Please try again.');
73 application.doLayout();
76 showLoginWindow: function(application) {
77 application.mainmenu.hide();
78 application.doLayout();
79 var login_window = application.createWindow({
87 items: login_form = new Ext.FormPanel({
89 bodyStyle: 'padding: 5px 5px 0',
92 fieldLabel: 'Username',
97 fieldLabel: 'Password',
100 inputType: 'password',
106 iconCls: 'door-open-in',
107 handler: function(button, event) {
108 var the_form = login_form.getForm().el.dom;
109 var username = the_form[0].value;
110 var password = the_form[1].value;
111 Gilbert.api.auth.login(username, password, function(result) {
113 document.location.reload();
115 Ext.MessageBox.alert('Log in failed', 'Unable to authenticate using the credentials provided. Please try again.', function() {
116 login_form.getForm().reset();