for now, let's slow things down and flesh one row at a time.. paging interface is...
[Evergreen.git] / Open-ILS / xul / staff_client / server / patron / search_result.js
1 dump('entering patron/search_result.js\n');
2
3 if (typeof patron == 'undefined') patron = {};
4 patron.search_result = function (params) {
5
6         JSAN.use('util.error'); this.error = new util.error();
7         JSAN.use('util.network'); this.network = new util.network();
8         this.w = window;
9 }
10
11 patron.search_result.prototype = {
12
13         'init' : function( params ) {
14
15                 var obj = this;
16
17                 obj.session = params['session'];
18                 obj.query = params['query'];
19
20                 JSAN.use('OpenILS.data'); this.OpenILS = {}; 
21                 obj.OpenILS.data = new OpenILS.data(); obj.OpenILS.data.init({'via':'stash'});
22
23                 JSAN.use('util.list'); obj.list = new util.list('patron_list');
24                 function getString(s) { return obj.OpenILS.data.entities[s]; }
25
26                 JSAN.use('patron.util');
27                 var columns = patron.util.columns(
28                         {
29                                 'standing' : { 'hidden' : 'false' },
30                                 'active' : { 'hidden' : 'false' },
31                                 'family_name' : { 'hidden' : 'false' },
32                                 'first_given_name' : { 'hidden' : 'false' },
33                                 'second_given_name' : { 'hidden' : 'false' },
34                                 'dob' : { 'hidden' : 'false' },
35                         }
36                 );
37                 obj.list.init(
38                         {
39                                 'columns' : columns,
40                                 'map_row_to_column' : patron.util.std_map_row_to_column(),
41                                 'retrieve_row' : function(params) {
42                                         var id = params.retrieve_id;
43                                         var au_obj = patron.util.retrieve_au_via_id( obj.session, id );
44
45                                         var row = params.row;
46                                         if (typeof row.my == 'undefined') row.my = {};
47                                         row.my.au = au_obj;
48                                         if (typeof params.on_retrieve == 'function') {
49                                                 params.on_retrieve(row);
50                                         }
51                                         return row;
52                                 },
53                                 'on_select' : function(ev) {
54                                         JSAN.use('util.functional');
55                                         var sel = obj.list.retrieve_selection();
56                                         var list = util.functional.map_list(
57                                                 sel,
58                                                 function(o) { return o.getAttribute('retrieve_id'); }
59                                         );
60                                         if (typeof obj.on_select == 'function') {
61                                                 obj.on_select(list);
62                                         }
63                                         if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
64                                                 obj.error.sdump('D_PATRON','patron.search_result: Calling external .on_select()\n');
65                                                 window.xulG.on_select(list);
66                                         } else {
67                                                 obj.error.sdump('D_PATRON','patron.search_result: No external .on_select()\n');
68                                         }
69                                 }
70                         }
71                 );
72                 JSAN.use('util.controller'); obj.controller = new util.controller();
73                 obj.controller.init(
74                         {
75                                 control_map : {
76                                         'cmd_broken' : [
77                                                 ['command'],
78                                                 function() { alert('Not Yet Implemented'); }
79                                         ],
80                                         'cmd_search_print' : [
81                                                 ['command'],
82                                                 function() {
83                                                         dump( js2JSON( obj.list.dump() ) );
84                                                         alert( js2JSON( obj.list.dump() ) );
85                                                 }
86                                         ],
87                                 }
88                         }
89                 );
90
91                 if (obj.query) obj.search(obj.query);
92         },
93
94         'search' : function(query) {
95                 var obj = this;
96                 var search_hash = {};
97                 for (var i in query) {
98                         switch( i ) {
99                                 case 'phone': case 'ident': 
100                                 
101                                         search_hash[ i ] = {};
102                                         search_hash[ i ].value = query[i];
103                                         search_hash[i].group = 2; 
104                                 break;
105
106                                 case 'street1': case 'street2': case 'city': case 'state': case 'post_code': 
107                                 
108                                         search_hash[ i ] = {};
109                                         search_hash[ i ].value = query[i];
110                                         search_hash[i].group = 1; 
111                                 break;
112
113                                 case 'family_name': case 'first_given_name': case 'second_given_name': case 'email':
114
115                                         search_hash[ i ] = {};
116                                         search_hash[ i ].value = query[i];
117                                         search_hash[i].group = 0; 
118                                 break;
119                         }
120                 }
121                 try {
122                         var results = this.network.request(
123                                 api.FM_AU_IDS_RETRIEVE_VIA_HASH.app,
124                                 api.FM_AU_IDS_RETRIEVE_VIA_HASH.method,
125                                 [ this.session, search_hash ]
126                         );
127                         //this.list.append( { 'retrieve_id' : results[i], 'row' : {} } );
128                         var funcs = [];
129
130                                 function gen_func(r) {
131                                         return function() {
132                                                 obj.list.append( { 'retrieve_id' : r, 'row' : {} } );
133                                         }
134                                 }
135
136                         for (var i = 0; i < results.length; i++) {
137                                 funcs.push( gen_func(results[i]) );
138                         }
139                         JSAN.use('util.exec'); var exec = new util.exec();
140                         exec.chain( funcs );
141
142                 } catch(E) {
143                         this.error.sdump('D_ERROR','patron.search_result.search: ' + js2JSON(E));
144                         alert(E);
145                 }
146         }
147
148 }
149
150 dump('exiting patron/search_result.js\n');