liberate this perm-cognizant lib menu generator
authorJason Etheridge <jason@esilibrary.com>
Thu, 15 Mar 2012 06:30:31 +0000 (02:30 -0400)
committerMike Rylander <mrylander@gmail.com>
Mon, 2 Apr 2012 11:45:07 +0000 (07:45 -0400)
for re-use in other interfaces

Signed-off-by: Jason Etheridge <jason@esilibrary.com>
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/xul/staff_client/chrome/content/util/widgets.js
Open-ILS/xul/staff_client/server/admin/do_not_auto_attempt_print_setting.js

index 4867256..bf8b644 100644 (file)
@@ -27,7 +27,8 @@ util.widgets.EXPORT_OK    = [
     'set_text',
     'save_attributes',
     'load_attributes',
-    'find_descendants_by_name'
+    'find_descendants_by_name',
+    'render_perm_org_menu'
 ];
 util.widgets.EXPORT_TAGS    = { ':all' : util.widgets.EXPORT_OK };
 
@@ -475,4 +476,56 @@ util.widgets.find_descendants_by_name = function(top_node,name) {
     return top_node.getElementsByAttribute('name',name);
 }
 
+util.widgets.render_perm_org_menu = function (perm,org) {
+    try {
+        JSAN.use('util.functional'); JSAN.use('util.fm_utils');
+        JSAN.use('OpenILS.data'); JSAN.use('util.network');
+        var data = new OpenILS.data(); data.stash_retrieve();
+        var network = new util.network();
+
+        var work_ous = network.simple_request(
+            'PERM_RETRIEVE_WORK_OU',
+            [ ses(), perm]
+        );
+        if (work_ous.length == 0) {
+            return false;
+        }
+
+        var my_libs = [];
+        for (var i = 0; i < work_ous.length; i++ ) {
+            var perm_depth = data.hash.aout[ data.hash.aou[ work_ous[i] ].ou_type() ].depth();
+
+            var my_libs_tree = network.simple_request(
+                'FM_AOU_DESCENDANTS_RETRIEVE',
+                [ work_ous[i], perm_depth ]
+            );
+            if (!instanceOf(my_libs_tree,aou)) { /* FIXME - workaround for weird descendants call result */
+                my_libs_tree = my_libs_tree[0];
+            }
+            my_libs = my_libs.concat( util.fm_utils.flatten_ou_branch( my_libs_tree ) );
+        }
+
+        var default_lib = org || my_libs[0].id();
+
+        var ml = util.widgets.make_menulist(
+            util.functional.map_list(
+                my_libs,
+                function(obj) {
+                    return [
+                        obj.shortname() + ' : ' + obj.name(),
+                        obj.id(),
+                        false,
+                        ( data.hash.aout[ obj.ou_type() ].depth() )
+                    ];
+                }
+            ),
+            default_lib
+        );
+
+        return ml;
+
+    } catch(E) {
+        alert('Error in util.widgets.render_perm_org_menu(): ' + E);
+    }
+}
 dump('exiting util/widgets.js\n');
index e1eaea0..461b09f 100644 (file)
@@ -28,7 +28,14 @@ function my_init() {
             false
         );
 
-        render_lib_menu();
+        var ml = util.widgets.render_perm_org_menu('ADMIN_ORG_UNIT_SETTING_TYPE');
+        if (ml) {
+            document.getElementById('apply').disabled = false;
+            ml.setAttribute('id','lib_menulist');
+            var x = document.getElementById('menu');
+            util.widgets.remove_children(x);
+            x.appendChild(ml);
+        }
 
     } catch(E) {
         try { error.standard_unexpected_error_alert('main/test.xul',E); } catch(F) { alert(E); }
@@ -105,57 +112,4 @@ function render_current_setting() {
 }
 
 
-function render_lib_menu() {
-    try {
-        JSAN.use('util.functional'); JSAN.use('util.fm_utils'); JSAN.use('util.widgets');
-
-        var work_ous = network.simple_request(
-            'PERM_RETRIEVE_WORK_OU',
-            [ ses(), 'ADMIN_ORG_UNIT_SETTING_TYPE']
-        );
-        if (work_ous.length == 0) {
-            return;
-        } else {
-            document.getElementById('apply').disabled = false;
-        }
-
-        var my_libs = [];
-        for (var i = 0; i < work_ous.length; i++ ) {
-            var perm_depth = data.hash.aout[ data.hash.aou[ work_ous[i] ].ou_type() ].depth();
-
-            var my_libs_tree = network.simple_request(
-                'FM_AOU_DESCENDANTS_RETRIEVE',
-                [ work_ous[i], perm_depth ]
-            );
-            if (!instanceOf(my_libs_tree,aou)) { /* FIXME - workaround for weird descendants call result */
-                my_libs_tree = my_libs_tree[0];
-            }
-            my_libs = my_libs.concat( util.fm_utils.flatten_ou_branch( my_libs_tree ) );
-        }
-
-        var x = document.getElementById('menu');
-        util.widgets.remove_children( x );
-
-        var default_lib = my_libs[0].id();
-
-        var ml = util.widgets.make_menulist(
-            util.functional.map_list(
-                my_libs,
-                function(obj) {
-                    return [
-                        obj.shortname(),
-                        obj.id(),
-                        false,
-                        ( data.hash.aout[ obj.ou_type() ].depth() )
-                    ];
-                }
-            ),
-            default_lib
-        );
-        ml.setAttribute('id','lib_menulist');
 
-        x.appendChild( ml );
-    } catch(E) {
-        alert('Error in do_not_auto_attempt_print_setting.js, render_lib_menu(): ' + E);
-    }
-}