Normalize patron profile search function in "Search for Patrons" UI
authordbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 13 Mar 2011 22:09:06 +0000 (22:09 +0000)
committerdbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 13 Mar 2011 22:09:06 +0000 (22:09 +0000)
Use util.widgets.make_menulist for a more consistent approach to
generating the menulist and use a row/label/hbox layout to normalize the
appearance of the patron profile filter in the search menu.

git-svn-id: svn://svn.open-ils.org/ILS/trunk@19727 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/xul/staff_client/server/patron/search_form.js
Open-ILS/xul/staff_client/server/patron/search_form_overlay.xul

index b472252..9c3acec 100644 (file)
@@ -232,7 +232,7 @@ patron.search_form.prototype = {
                             };
                         }
                     ],
-                    'profile' : [ ['render'],function(e) {
+                    'profile' : [ ['render'], function(e) {
                             return function() {};
                         } 
                     ],
@@ -243,7 +243,7 @@ patron.search_form.prototype = {
                     'search_depth' : [ ['render'],function(e) {
                             return function() {};
                         }
-                    ],
+                    ]
                 }
             }
         );
@@ -286,7 +286,7 @@ patron.search_form.prototype = {
         util.widgets.load_attributes(file);
         ml.value = ml.getAttribute('value');
         if (! ml.value) {
-            ml.value = 0
+            ml.value = 0;
             ml.setAttribute('value',ml.value);
         }
 
@@ -299,14 +299,34 @@ patron.search_form.prototype = {
         );
         cb.checked = cb.getAttribute('value') == "true" ? true : false;
 
-        var menupopup = document.getElementById('profile').firstChild;
-        for (var i = 0; i < obj.OpenILS.data.list.pgt.length; i++) { 
-            var my_pgt = obj.OpenILS.data.list.pgt[i]; 
-            var menuitem = document.createElement('menuitem'); 
-            menuitem.setAttribute('label',my_pgt.name()); 
-            menuitem.setAttribute('value',my_pgt.id());
-            menupopup.appendChild(menuitem); 
-        };
+        /* Populate the Patron Profile filter */
+        util.widgets.remove_children(obj.controller.view.profile);
+        var profile_ml = util.widgets.make_menulist(
+            util.functional.map_list( obj.OpenILS.data.list.pgt,
+                function(el,idx) {
+                    return [ el.name(), el.id() ]
+                }
+            ).sort(
+                function(a,b) {
+                    if (a[0] < b[0]) return -1;
+                    if (a[0] > b[0]) return 1;
+                    return 0;
+                }
+            )
+        );
+        profile_ml.addEventListener('command', function() {
+                profile_ml.parentNode.setAttribute('value', profile_ml.value);
+            }, false
+        );
+        profile_ml.setAttribute('id','profile_ml');
+
+        /* Add an empty menu item as the default profile */
+        var empty = document.createElement('menuitem'); 
+        profile_ml.firstChild.insertBefore(empty, profile_ml.firstChild.firstChild);
+        empty.setAttribute('label', '');
+        empty.setAttribute('value', ''); 
+        obj.controller.view.profile.appendChild(profile_ml);
+        profile_ml.value = profile_ml.getAttribute('value');
     },
 
     'on_submit' : function(q) {
@@ -326,7 +346,7 @@ patron.search_form.prototype = {
                     query[id] = node.getAttribute('value');
                     obj.error.sdump('D_DEBUG','id = ' + id + '  value = ' + node.getAttribute('value') + '\n');
                 } else if (id == 'profile') {
-                    query[id] = node.selectedItem.getAttribute('value');
+                    query[id] = node.firstChild.getAttribute('value');
                     obj.error.sdump('D_DEBUG','id = ' + id + '  value = ' + node.getAttribute('value') + '\n');
                 } else {
                     if (id == 'search_depth') {
index ad71b41..660b75a 100644 (file)
                 accesskey="&staff.patron_search_form.post_code.accesskey;"/>
             <textbox id="post_code" group="1" context="clipboard"/>
         </row>
-        <vbox flex="1" style="overflow: auto">
-            <groupbox flex="1">
-                <caption label="&staff.patron_search_form.profile.label;" />
-                <menulist id="profile">
-                    <menupopup>
-                        <menuitem label="" value=""/>
-                    </menupopup>
-                </menulist>
-            </groupbox>
-        </vbox>
+        <row>
+            <label value="&staff.patron_search_form.profile.label;"/>
+            <hbox id="profile" />
+        </row>
         <row id="psr12">
             <spacer id="pss12"/>
             <button id="search" label="&staff.patron_search_form.search.label;"