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 var change_password_window = application.createWindow({
31 title: 'Change password',
32 iconCls: 'key--pencil',
35 items: change_password_form = new Ext.FormPanel({
37 bodyStyle: 'padding: 5px 5px 0',
39 fieldLabel: 'Current password',
40 name: 'current_password',
42 inputType: 'password',
44 fieldLabel: 'New password',
47 inputType: 'password',
49 fieldLabel: 'New password (confirm)',
50 name: 'new_password_confirm',
52 inputType: 'password',
55 text: 'Change password',
56 iconCls: 'key--pencil',
57 handler: function(button, event) {
58 var the_form = change_password_form.getForm().el.dom;
59 var current_password = the_form[0].value;
60 var new_password = the_form[1].value;
61 var new_password_confirm = the_form[2].value;
62 Gilbert.api.auth.passwd(current_password, new_password, new_password_confirm, function(result) {
64 Ext.MessageBox.alert('Password changed', 'Your password has been changed.');
66 Ext.MessageBox.alert('Password unchanged', 'Unable to change your password.', function() {
67 change_password_form.getForm().reset();
75 change_password_window.show();
79 iconCls: 'door-open-out',
80 handler: function(button, event) {
81 Gilbert.api.auth.logout(function(result) {
83 document.location.reload();
85 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.');
91 application.doLayout();
94 showLoginWindow: function(application) {
95 application.mainmenu.hide();
96 application.doLayout();
97 var login_window = application.createWindow({
105 items: login_form = new Ext.FormPanel({
107 bodyStyle: 'padding: 5px 5px 0',
110 fieldLabel: 'Username',
115 fieldLabel: 'Password',
118 inputType: 'password',
124 iconCls: 'door-open-in',
125 handler: function(button, event) {
126 var the_form = login_form.getForm().el.dom;
127 var username = the_form[0].value;
128 var password = the_form[1].value;
129 Gilbert.api.auth.login(username, password, function(result) {
131 document.location.reload();
133 Ext.MessageBox.alert('Log in failed', 'Unable to authenticate using the credentials provided. Please try again.', function() {
134 login_form.getForm().reset();