Added theme switching to auth plugin. Tries to do it live, but some windows may need...
authorJoseph Spiros <joseph.spiros@ithinksw.com>
Tue, 22 Mar 2011 18:30:47 +0000 (14:30 -0400)
committerJoseph Spiros <joseph.spiros@ithinksw.com>
Tue, 22 Mar 2011 18:30:47 +0000 (14:30 -0400)
contrib/gilbert/media/gilbert/lib/app.js
contrib/gilbert/media/gilbert/plugins/auth.js
contrib/gilbert/media/gilbert/plugins/models.js
contrib/gilbert/plugins/auth.py

index 2c3f59c..d68e10c 100644 (file)
@@ -204,21 +204,25 @@ Gilbert.lib.app.Application = Ext.extend(Ext.util.Observable, {
                });
                Gilbert.api.plugins.auth.get_preference('gilbert.theme', function (theme) {
                        if (theme) {
-                               var link_element = document.getElementById('gilbert.theme.' + theme);
-                               if (link_element) {
-                                       Ext.each(document.getElementsByClassName('gilbert.theme'), function (theme_element) {
-                                               if (theme_element != link_element) {
-                                                       theme_element.disabled = true;
-                                               } else {
-                                                       theme_element.disabled = false;
-                                               }
-                                       });
-                               }
+                               outer._set_theme(theme);
                        }
                        outer.init();
                });
        },
        
+       _set_theme: function(theme) {
+               var link_element = document.getElementById('gilbert.theme.' + theme);
+               if (link_element) {
+                       Ext.each(document.getElementsByClassName('gilbert.theme'), function (theme_element) {
+                               if (theme_element != link_element) {
+                                       theme_element.disabled = true;
+                               } else {
+                                       theme_element.disabled = false;
+                               }
+                       });
+               }
+       },
+       
        init: function () {
                Ext.QuickTips.init();
                
index e31d6fd..6983748 100644 (file)
@@ -1,23 +1,12 @@
 Ext.ns('Gilbert.lib.plugins.auth');
 
 
-Gilbert.lib.plugins.auth.PreferencesWindow = Ext.extend(Ext.Window, {
-       constructor: function (config, application) {
-               Gilbert.lib.plugins.auth.PreferencesWindow.superclass.constructor.call(this, Ext.applyIf(config||{},{
-                       width: 320,
-                       height: 200,
-                       title: 'Preferences',
-               }));
-       }
-});
-
-
 Gilbert.lib.plugins.auth.Plugin = Ext.extend(Gilbert.lib.plugins.Plugin, {
        
        init: function (application) {
                Gilbert.lib.plugins.auth.Plugin.superclass.init.call(this, application);
                
-               var preferences_window = new Gilbert.lib.plugins.auth.PreferencesWindow({}, application);
+               var outer = this;
                
                Gilbert.api.plugins.auth.whoami(function (whoami) {
                        application.mainmenu.add({
@@ -29,11 +18,9 @@ Gilbert.lib.plugins.auth.Plugin = Ext.extend(Gilbert.lib.plugins.Plugin, {
                                iconCls: 'icon-user-silhouette',
                                text: '<span style="font-weight: bolder;">' + whoami + '</span>',
                                menu: [{
-                                               text: 'Preferences...',
-                                               iconCls: 'icon-switch',
-                                               handler: function (button, event) {
-                                                       preferences_window.show();
-                                               },
+                                               text: 'Theme',
+                                               iconCls: 'icon-mask',
+                                               menu: outer.build_theme_menu(),
                                        },{
                                                xtype: 'menuseparator',
                                        },{
@@ -102,7 +89,44 @@ Gilbert.lib.plugins.auth.Plugin = Ext.extend(Gilbert.lib.plugins.Plugin, {
                        application.do_layout();
                });
        },
-
+       
+       build_theme_menu: function () {
+               var application = this.application;
+               
+               var theme_switcher = function (menuitem) {
+                       var theme_name = menuitem.theme_name;
+                       Gilbert.api.plugins.auth.set_preference('gilbert.theme', theme_name, function () {
+                               application._set_theme(theme_name);
+                               application.do_layout();
+                               application.windows.each(function (win) {
+                                       win.doLayout();
+                               });
+                       });
+               };
+               
+               var menu = [];
+               
+               Ext.each(document.getElementsByClassName('gilbert.theme'), function (theme_element) {
+                       var theme_id = theme_element.id;
+                       var theme_name = theme_id.match(/gilbert.theme.(.*)/)[1];
+                       var current_theme = false;
+                       if (!theme_element.disabled) {
+                               current_theme = true;
+                       }
+                       
+                       
+                       menu.push({
+                               text: theme_name.capfirst(),
+                               checked: current_theme,
+                               group: 'theme',
+                               theme_name: theme_name,
+                               handler: theme_switcher,
+                       });
+               });
+               
+               return menu;
+       },
+       
 });
 
 
index afe2a10..61fa7fb 100644 (file)
@@ -231,7 +231,7 @@ Gilbert.lib.plugins.models.ui.ModelPanel = Ext.extend(Ext.Panel, {
                                                        '->',
                                                        {
                                                                xtype: 'button',
-                                                               text: 'Yes',
+                                                               text: 'Delete',
                                                                handler: function () {
                                                                        consequences_win.close();
                                                                        store.remove(records);
index e964559..0daaf85 100644 (file)
@@ -18,7 +18,7 @@ class Auth(Plugin):
        def icon_names(self):
                return super(Auth, self).icon_names + [
                        'user-silhouette',
-                       'switch',
+                       'mask',
                        'key--pencil',
                        'door-open-out',
                ]