[open-ils-commits] r19953 - in trunk/Open-ILS/xul/staff_client/chrome/content: auth main util (phasefx)

svn at svn.open-ils.org svn at svn.open-ils.org
Mon Apr 4 12:38:43 EDT 2011


Author: phasefx
Date: 2011-04-04 12:38:40 -0400 (Mon, 04 Apr 2011)
New Revision: 19953

Modified:
   trunk/Open-ILS/xul/staff_client/chrome/content/auth/controller.js
   trunk/Open-ILS/xul/staff_client/chrome/content/main/main.js
   trunk/Open-ILS/xul/staff_client/chrome/content/main/menu.js
   trunk/Open-ILS/xul/staff_client/chrome/content/util/network.js
Log:
Client Permission Overhaul

Menu/Toolbar commands can have a perm= attribute added, containing a space-seperated list of permissions.
Without it they stay enabled at all times (or disabled if they are manually disabled in the file).
With it they disable unless the user has at least one permission listed.

In addition, made *all* new or active windows get UI updates when changing operators, including updated menu enable/disable.

Will need a check on the permissions from previous commit, and probably a pile more from those who understand what needs what.

Signed-off-by: Thomas Berezansky <tsbere at mvlc.org>


Modified: trunk/Open-ILS/xul/staff_client/chrome/content/auth/controller.js
===================================================================
--- trunk/Open-ILS/xul/staff_client/chrome/content/auth/controller.js	2011-04-04 16:38:37 UTC (rev 19952)
+++ trunk/Open-ILS/xul/staff_client/chrome/content/auth/controller.js	2011-04-04 16:38:40 UTC (rev 19953)
@@ -548,6 +548,8 @@
         this.controller.render('ws_deck');
 
         this.session.close();
+        this.data.menu_perms = false;
+        this.data.stash('menu_perms');
 
         /* FIXME - need some locking or object destruction for the async tests */
         /* this.test_server( this.controller.view.server_prompt.value ); */

Modified: trunk/Open-ILS/xul/staff_client/chrome/content/main/main.js
===================================================================
--- trunk/Open-ILS/xul/staff_client/chrome/content/main/main.js	2011-04-04 16:38:37 UTC (rev 19952)
+++ trunk/Open-ILS/xul/staff_client/chrome/content/main/main.js	2011-04-04 16:38:40 UTC (rev 19953)
@@ -187,6 +187,39 @@
     }
 }
 
+// Returns false if we can't get an actual perm list
+// Returns an array of perms with boolean has/hasn't flag
+function get_menu_perms(indocument) {
+    // If we don't have our static perm list, and we have a remote window, go looking.
+    // We never need to look twice unless a dev is manually editing their files.
+    // Shame on them, they can restart the entire client ;)
+    if(typeof(get_menu_perms.perm_list) == 'undefined' && indocument != null)
+    {
+        get_menu_perms.perm_list = [ ];
+        var commands = indocument.getElementById('universal_cmds').getElementsByTagName('command');
+        for (var i = 0; i < commands.length; i++) { 
+            if (commands[i].hasAttribute('perm')) {
+                get_menu_perms.perm_list = get_menu_perms.perm_list.concat(commands[i].getAttribute('perm').split(' '));
+            }           
+        }
+    }
+    // 
+    if(typeof(get_menu_perms.perm_list) == 'object') {
+        G.data.stash_retrieve();
+        if(!G.data.menu_perms) {
+            JSAN.use('util.network');
+            var network = new util.network();
+            var r = network.simple_request('BATCH_PERM_RETRIEVE_WORK_OU', [ G.data.session.key, get_menu_perms.perm_list ]);
+            for(p in r)
+                r[p] = (typeof(r[p][0]) == 'number');
+            G.data.menu_perms = r;
+            G.data.stash('menu_perms');
+        }
+        return G.data.menu_perms;
+    }
+    return false;
+}
+
 function main_init() {
     dump('entering main_init()\n');
     try {

Modified: trunk/Open-ILS/xul/staff_client/chrome/content/main/menu.js
===================================================================
--- trunk/Open-ILS/xul/staff_client/chrome/content/main/menu.js	2011-04-04 16:38:37 UTC (rev 19952)
+++ trunk/Open-ILS/xul/staff_client/chrome/content/main/menu.js	2011-04-04 16:38:40 UTC (rev 19953)
@@ -69,6 +69,13 @@
             if (y) y.setAttribute('hidden','true');
         }
 
+        var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
+                    getService(Components.interfaces.nsIWindowMediator);
+        wm.getMostRecentWindow('eg_main').get_menu_perms(document);
+        JSAN.use('util.network');
+        var network = new util.network();
+        network.set_user_status();
+
         function open_conify_page(path, labelKey, event) {
 
             // tab label
@@ -1072,18 +1079,17 @@
                     try {
                         obj.data.stash_retrieve();
                         JSAN.use('util.network'); var network = new util.network();
-                        var x = document.getElementById('oc_menuitem');
-                        var x_label = x.getAttribute('label_orig');
                         var temp_au = js2JSON( obj.data.list.au[0] );
                         var temp_ses = js2JSON( obj.data.session );
                         if (obj.data.list.au.length > 1) {
                             obj.data.list.au = [ obj.data.list.au[1] ];
                             obj.data.stash('list');
                             network.reset_titlebars( obj.data );
-                            x.setAttribute('label', x_label );
                             network.simple_request('AUTH_DELETE', [ obj.data.session.key ] );
                             obj.data.session = obj.data.previous_session;
+                            obj.data.menu_perms = obj.data.previous_menu_perms;
                             obj.data.stash('session');
+                            obj.data.stash('menu_perms');
                             try {
                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                                 var ios = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
@@ -1098,18 +1104,20 @@
                             alert(offlineStrings.getFormattedString(main.session_cookie.error, [E]));
                         }
 
-                            removeCSSClass(document.getElementById('main_tabbox'),'operator_change');
                         } else {
                             if (network.get_new_session(offlineStrings.getString('menu.cmd_chg_session.label'),{'url_prefix':obj.url_prefix})) {
                                 obj.data.stash_retrieve();
                                 obj.data.list.au[1] = JSON2js( temp_au );
                                 obj.data.stash('list');
                                 obj.data.previous_session = JSON2js( temp_ses );
+                                obj.data.previous_menu_perms = obj.data.menu_perms;
+                                obj.data.menu_perms = false;
                                 obj.data.stash('previous_session');
-                                x.setAttribute('label', offlineStrings.getFormattedString('menu.cmd_chg_session.operator.label', [obj.data.list.au[1].usrname()]) );
-                                addCSSClass(document.getElementById('main_tabbox'),'operator_change');
+                                obj.data.stash('previous_menu_perms');
+                                obj.data.stash('menu_perms');
                             }
                         }
+                        network.set_user_status();
                     } catch(E) {
                         obj.error.standard_unexpected_error_alert('cmd_change_session',E);
                     }
@@ -1501,6 +1509,26 @@
         }
     },
 
+    'set_menu_access' : function(perms) {
+        if(perms === false) return;
+        var commands = document.getElementById('universal_cmds').getElementsByTagName('command');
+        var commandperms;
+commands:
+        for (var i = 0; i < commands.length; i++) { 
+            if (commands[i].hasAttribute('perm')) {
+                commandperms = commands[i].getAttribute('perm').split(' ');
+                for (var j = 0; j < commandperms.length; j++) {
+                    if (perms[commandperms[j]]) {
+                        commands[i].setAttribute('disabled','false');
+                        continue commands;
+                    }
+                }
+                commands[i].setAttribute('disabled','true');
+            }           
+        }
+
+    },
+
     'page_meter' : {
         'node' : document.getElementById('page_progress'),
         'on' : function() {

Modified: trunk/Open-ILS/xul/staff_client/chrome/content/util/network.js
===================================================================
--- trunk/Open-ILS/xul/staff_client/chrome/content/util/network.js	2011-04-04 16:38:37 UTC (rev 19952)
+++ trunk/Open-ILS/xul/staff_client/chrome/content/util/network.js	2011-04-04 16:38:40 UTC (rev 19953)
@@ -301,6 +301,36 @@
         }
     },
 
+    'set_user_status' : function() {
+        data.stash_retrieve();
+        try {
+            var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
+            var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
+            var permlist = windowManagerInterface.getMostRecentWindow('eg_main').get_menu_perms(null);
+            var offlinestrings;
+            var enumerator = windowManagerInterface.getEnumerator('eg_menu');
+
+            var w;
+            var x;
+            while ( w = enumerator.getNext() ) {
+                x = w.document.getElementById('oc_menuitem');
+
+                if(!offlinestrings) w.document.getElementById('offlineStrings');
+                if(permlist) w.g.menu.set_menu_access(permlist);
+                if(data.list.au.length > 1) {
+                    addCSSClass(w.document.getElementById('main_tabbox'),'operator_change');
+                    x.setAttribute('label', offlineStrings.getFormattedString('menu.cmd_chg_session.operator.label', [data.list.au[1].usrname()]) );
+                }
+                else {
+                    removeCSSClass(w.document.getElementById('main_tabbox'),'operator_change');
+                    x.setAttribute('label', x.getAttribute('label_orig'));
+                }
+            }
+        } catch(E) {
+            obj.error.standard_unexpected_error_alert(offlineStrings.getString('network.window_title.error'),E);
+        }
+    },
+
     'get_new_session' : function(name,xulG,text) {
         var obj = this;
         try {



More information about the open-ils-commits mailing list