modify search_result.js
authorJason Etheridge <jason@esilibrary.com>
Tue, 1 Oct 2013 20:20:26 +0000 (16:20 -0400)
committerJason Etheridge <jason@esilibrary.com>
Tue, 1 Oct 2013 21:06:17 +0000 (17:06 -0400)
Open-ILS/xul/staff_client/server/patron/search_result.js

index 49c4522..aa92693 100644 (file)
@@ -21,7 +21,8 @@ patron.search_result.prototype = {
         obj.query = params['query'];
         obj.search_limit = params['search_limit'];
         obj.search_sort = params['search_sort'];
-
+        obj.patron_parts = params['patron_parts']
+            || ["card","billing_address","mailing_address"];
         JSAN.use('OpenILS.data'); this.OpenILS = {}; 
         obj.OpenILS.data = new OpenILS.data(); obj.OpenILS.data.init({'via':'stash'});
         var obscure_dob = String( obj.OpenILS.data.hash.aous['circ.obscure_dob'] ) == 'true';
@@ -100,7 +101,7 @@ patron.search_result.prototype = {
                     var au_obj = patron.util.retrieve_fleshed_au_via_id(
                         ses(),
                         id,
-                        ["card","billing_address","mailing_address"],
+                        obj.patron_parts,
                         function(req) {
                             try {
                                 var row = params.row;
@@ -198,7 +199,7 @@ patron.search_result.prototype = {
         var search_hash = {};
         obj.search_term_count = 0;
         var inactive = false;
-        var search_depth = 0;
+        var search_ou = 0;
         for (var i in query) {
             switch( i ) {
                 case 'card':
@@ -236,8 +237,9 @@ patron.search_result.prototype = {
                     if (query[i] == 'checked' || query[i] == 'true') inactive = true;
                 break;
 
-                case 'search_depth':
-                    search_depth = function(a){return a;}(query[i]);
+                case 'search_depth' /* bad name, but keeping for the moment */:
+                case 'search_ou' /* truthful name */:
+                    search_ou = function(a){return a;}(query[i]);
                 break;
             }
         }
@@ -263,10 +265,13 @@ patron.search_result.prototype = {
             } else {
                 params.push(0);
             }
-            params.push(search_depth);
+            params.push(search_ou);
             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 );
+                if (typeof obj.on_select == 'function') {
+                    obj.on_finished(results);
+                }
                 if ( results == null ) results = [];
                 if (typeof results.ilsevent != 'undefined') throw(results);
                 if (results.length == 0) {
@@ -282,21 +287,33 @@ patron.search_result.prototype = {
                 return;
             }
 
-            obj.list.clear();
-            //this.list.append( { 'retrieve_id' : results[i], 'row' : {} } );
-            var funcs = [];
+            if (results.length == 1 && obj.skip_render_of_single_result) {
+                // no-op
+            } else {
+                obj.list.clear();
+                var funcs = [];
 
                 function gen_func(r) {
                     return function() {
-                        obj.list.append( { 'retrieve_id' : r, 'row' : {}, 'to_bottom' : true, 'no_auto_select' : true } );
+                        obj.list.append({
+                            'retrieve_id' : r,
+                            'row' : {},
+                            'to_bottom' : true,
+                            'no_auto_select' : true
+                        });
                     }
                 }
 
-            for (var i = 0; i < results.length; i++) {
-                funcs.push( gen_func(results[i]) );
+                for (var i = 0; i < results.length; i++) {
+                    funcs.push( gen_func(results[i]) );
+                }
+                JSAN.use('util.exec'); var exec = new util.exec(4);
+                exec.chain( funcs );
+            }
+
+            if (results.length == 1 && typeof obj.single_result_callback == 'function') {
+                obj.single_result_callback(results[0]);
             }
-            JSAN.use('util.exec'); var exec = new util.exec(4);
-            exec.chain( funcs );
 
         } catch(E) {
             this.error.standard_unexpected_error_alert('patron.search_result.search',E);