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];
38 var change_password_form = new Gilbert.lib.ui.DjangoForm(Ext.applyIf({
39 title: 'Change password',
41 iconCls: 'icon-key--pencil',
42 bodyStyle: 'padding: 10px;',
46 submit: Gilbert.api.plugins.auth.save_passwd_form,
49 var change_password_window = application.create_window({
51 title: change_password_form.title,
52 iconCls: change_password_form.iconCls,
53 bodyStyle: 'padding: 5px; background: solid;',
57 items: [change_password_form],
61 text: 'Change password',
62 iconCls: 'icon-key--pencil',
63 handler: function(button, event) {
64 change_password_form.getForm().submit({
65 success: function(form, action) {
66 Ext.MessageBox.alert('Password changed', 'Your password has been changed.');
67 change_password_window.close();
74 change_password_window.doLayout();
75 change_password_window.show(button.el);
81 iconCls: 'icon-door-open-out',
82 handler: function(button, event) {
83 Gilbert.api.plugins.auth.logout(function(success) {
85 window.onbeforeunload = undefined;
86 document.location.reload();
88 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.');
94 application.do_layout();
98 build_theme_menu: function () {
99 var application = this.application;
101 var theme_switcher = function (menuitem) {
102 var theme_name = menuitem.theme_name;
103 Gilbert.api.plugins.auth.set_preference('gilbert.theme', theme_name, function () {
104 application._set_theme(theme_name);
105 application.do_layout();
106 application.windows.each(function (win) {
114 Ext.each(document.getElementsByClassName('gilbert.theme'), function (theme_element) {
115 var theme_id = theme_element.id;
116 var theme_name = theme_id.match(/gilbert.theme.(.*)/)[1];
117 var current_theme = false;
118 if (!theme_element.disabled) {
119 current_theme = true;
124 text: theme_name.capfirst(),
125 checked: current_theme,
127 theme_name: theme_name,
128 handler: theme_switcher,
138 Gilbert.on('ready', function (application) {
139 application.register_plugin('auth', new Gilbert.lib.plugins.auth.Plugin());