1 Ext.ns('Gilbert.lib.plugins.auth');
4 Gilbert.lib.plugins.auth.Plugin = Ext.extend(Gilbert.lib.plugins.Plugin, {
6 init: function (application) {
7 Gilbert.lib.plugins.auth.Plugin.superclass.init.call(this, application);
11 Gilbert.api.plugins.auth.whoami(function (whoami) {
12 application.mainmenu.add({
18 iconCls: 'icon-user-silhouette',
19 text: '<span style="font-weight: bolder;">' + whoami + '</span>',
23 menu: outer.build_theme_menu(),
25 xtype: 'menuseparator',
27 text: 'Change password',
28 iconCls: 'icon-key--pencil',
29 handler: function(button, event) {
30 Gilbert.api.plugins.auth.get_passwd_form(function(formspec) {
31 var formspec = formspec;
32 for (var item_index in formspec.items) {
33 var item = formspec.items[item_index];
35 plugins: [ Ext.ux.FieldLabeler ],
38 var change_password_window = application.create_window({
41 title: 'Change password',
42 iconCls: 'icon-key--pencil',
45 items: change_password_form = new Ext.FormPanel(Ext.applyIf({
51 bodyStyle: 'padding: 5px;',
54 text: 'Change password',
55 iconCls: 'icon-key--pencil',
56 handler: function(button, event) {
57 change_password_form.getForm().submit({
58 success: function(form, action) {
59 Ext.MessageBox.alert('Password changed', 'Your password has been changed.');
65 submit: Gilbert.api.plugins.auth.save_passwd_form,
69 change_password_window.doLayout();
70 change_password_window.show(button.el);
76 iconCls: 'icon-door-open-out',
77 handler: function(button, event) {
78 Gilbert.api.plugins.auth.logout(function(success) {
80 window.onbeforeunload = undefined;
81 document.location.reload();
83 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.');
89 application.do_layout();
93 build_theme_menu: function () {
94 var application = this.application;
96 var theme_switcher = function (menuitem) {
97 var theme_name = menuitem.theme_name;
98 Gilbert.api.plugins.auth.set_preference('gilbert.theme', theme_name, function () {
99 application._set_theme(theme_name);
100 application.do_layout();
101 application.windows.each(function (win) {
109 Ext.each(document.getElementsByClassName('gilbert.theme'), function (theme_element) {
110 var theme_id = theme_element.id;
111 var theme_name = theme_id.match(/gilbert.theme.(.*)/)[1];
112 var current_theme = false;
113 if (!theme_element.disabled) {
114 current_theme = true;
119 text: theme_name.capfirst(),
120 checked: current_theme,
122 theme_name: theme_name,
123 handler: theme_switcher,
133 Gilbert.on('ready', function (application) {
134 application.register_plugin('auth', new Gilbert.lib.plugins.auth.Plugin());