UI for patron search range/depth selection
authorphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 15 Aug 2007 21:51:26 +0000 (21:51 +0000)
committerphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 15 Aug 2007 21:51:26 +0000 (21:51 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_2@7684 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
Open-ILS/xul/staff_client/server/patron/search_result.js

index a6c1c49..6f4c8ef 100644 (file)
@@ -187,7 +187,14 @@ patron.search_form.prototype = {
                                                        };
                                                }
                                        ],
-                                       'inactive' : [ ['render'], function(e) { return function() {}; } ],
+                                       'inactive' : [ ['render'], function(e) { 
+                            return function() {}; 
+                        } 
+                    ],
+                    'search_depth' : [ ['render'],function(e) {
+                            return function() {};
+                        }
+                    ],
                                }
                        }
                );
@@ -202,6 +209,47 @@ patron.search_form.prototype = {
                }
                document.getElementById('family_name').focus();
 
+        JSAN.use('util.file'); JSAN.use('util.widgets'); JSAN.use('util.functional');
+        util.widgets.remove_children(obj.controller.view.search_depth);
+        var ml = util.widgets.make_menulist(
+            util.functional.map_list( obj.OpenILS.data.list.aout, 
+                function(el,idx) {
+                    return [ el.opac_label(), el.depth() ]
+                }
+            ).sort(
+                function(a,b) {
+                    if (a[1] < b[1]) return -1;
+                    if (a[1] > b[1]) return 1;
+                    return 0;
+                }
+            )
+        );
+        ml.addEventListener('command', function() {
+                ml.parentNode.setAttribute('value',ml.value);
+                var file = new util.file('patron_search_prefs.'+obj.OpenILS.data.server_unadorned);
+                util.widgets.save_attributes(file, { 'search_depth_ml' : [ 'value' ], 'inactive' : [ 'value' ] });
+            }, false
+        );
+        ml.setAttribute('id','search_depth_ml');
+        obj.controller.view.search_depth.appendChild(ml);
+
+               var file = new util.file('patron_search_prefs.'+obj.OpenILS.data.server_unadorned);
+               util.widgets.load_attributes(file);
+               ml.value = ml.getAttribute('value');
+               if (! ml.value) {
+                       ml.value = 0
+                       ml.setAttribute('value',ml.value);
+               }
+
+        var cb = obj.controller.view.inactive;
+        cb.addEventListener('command',function() { 
+                cb.setAttribute('value',cb.checked ? "true" : "false");
+                var file = new util.file('patron_search_prefs.'+obj.OpenILS.data.server_unadorned);
+                util.widgets.save_attributes(file, { 'search_depth_ml' : [ 'value' ], 'inactive' : [ 'value' ] });
+            }, false
+        );
+        cb.checked = cb.getAttribute('value') == "true" ? true : false;
+
        },
 
        'on_submit' : function(q) {
@@ -214,27 +262,31 @@ patron.search_form.prototype = {
                var obj = this;
                var query = {};
                for (var i = 0; i < obj.controller.render_list.length; i++) {
-               var id = obj.controller.render_list[i][0];
-               var node = document.getElementById(id);
+               var id = obj.controller.render_list[i][0];
+               var node = document.getElementById(id);
                        if (node && node.value != '') {
                                if (id == 'inactive') {
                                        query[id] = node.getAttribute('value');
                                        obj.error.sdump('D_DEBUG','id = ' + id + '  value = ' + node.getAttribute('value') + '\n');
-                               } else {
-                                       var value = node.value.replace(/^\s+/,'').replace(/[\\\s]+$/,'');
-                                       //value = value.replace(/\d/g,'');
-                                       switch(id) {
-                                               case 'family_name' :
-                                               case 'first_given_name' :
-                                               case 'second_given_name' :
-                                                       value = value.replace(/^\W+/g,'').replace(/\W+$/g,'');
-                                               break;
-                                       }
-                                       if (value != '') {
-                                               query[id] = value;
-                                               obj.error.sdump('D_DEBUG','id = ' + id + '  value = ' + value + '\n');
-                                       }
-                               }
+                } else {
+                    if (id == 'search_depth') {
+                        query[id] = node.firstChild.getAttribute('value'); 
+                               } else {
+                                       var value = node.value.replace(/^\s+/,'').replace(/[\\\s]+$/,'');
+                                       //value = value.replace(/\d/g,'');
+                                       switch(id) {
+                                               case 'family_name' :
+                                               case 'first_given_name' :
+                                               case 'second_given_name' :
+                                                       value = value.replace(/^\W+/g,'').replace(/\W+$/g,'');
+                                               break;
+                                       }
+                                       if (value != '') {
+                                               query[id] = value;
+                                               obj.error.sdump('D_DEBUG','id = ' + id + '  value = ' + value + '\n');
+                                       }
+                               }
+                }
                        }
                }
                if (typeof obj.on_submit == 'function') {
index 8535f7b..3dfaba9 100644 (file)
        </columns>
        <rows id="psr">
                <row>
-                       <spacer />
-                       <hbox>
-                               <label control="inactive" accesskey="I" value="Include inactive patrons?"/>
-                               <checkbox id="inactive" value="unchecked" oncommand="if (this.getAttribute('value') == 'unchecked') this.setAttribute('value','checked'); else this.setAttribute('value','unchecked');"/>
-                       </hbox>
+                       <label control="inactive" accesskey="I" value="Include inactive patrons?"/>
+                       <checkbox id="inactive" />
+        </row>
+        <row>
+                       <label control="search_range_menu" value="Limit results to patrons in"/>
+            <hbox id="search_depth" />
                </row>
                <row id="psr1">
                        <label id="psl1" control="family_name" 
index 412da46..c27793f 100644 (file)
@@ -154,6 +154,7 @@ patron.search_result.prototype = {
                var search_hash = {};
                obj.search_term_count = 0;
                var inactive = false;
+        var search_depth = 0;
                for (var i in query) {
                        switch( i ) {
                                case 'phone': case 'ident': 
@@ -183,6 +184,10 @@ patron.search_result.prototype = {
                                case 'inactive':
                                        if (query[i] == 'checked') inactive = true;
                                break;
+
+                case 'search_depth':
+                    search_depth = function(a){return a;}(query[i]);
+                break;
                        }
                }
                try {
@@ -195,7 +200,10 @@ patron.search_result.prototype = {
                                        document.getElementById('active').setAttribute('hidden','false');
                                        document.getElementById('active').hidden = false;
                                }
-                       }
+                       } else {
+                params.push(0);
+            }
+            params.push(search_depth);
                        if (obj.search_term_count > 0) {
                                //alert('search params = ' + obj.error.pretty_print( js2JSON( params ) ) );
                                results = this.network.simple_request( 'FM_AU_IDS_RETRIEVE_VIA_HASH', params );