]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/patron/display.js
1fe11c6b86f28cefdf926448da3d64c90856f088
[Evergreen.git] / Open-ILS / xul / staff_client / server / patron / display.js
1 dump('entering patron/display.js\n');
2
3 if (typeof patron == 'undefined') patron = {};
4 patron.display = function (params) {
5
6         JSAN.use('util.error'); this.error = new util.error();
7         JSAN.use('util.window'); this.window = new util.window();
8         JSAN.use('util.network'); this.network = new util.network();
9         this.w = window;
10 }
11
12 patron.display.prototype = {
13
14         'retrieve_ids' : [],
15
16         'init' : function( params ) {
17
18                 var obj = this;
19
20                 obj.session = params['session'];
21                 obj.barcode = params['barcode'];
22                 obj.id = params['id'];
23
24                 JSAN.use('OpenILS.data'); this.OpenILS = {}; 
25                 obj.OpenILS.data = new OpenILS.data(); obj.OpenILS.data.init({'via':'stash'});
26
27                 JSAN.use('util.deck'); 
28                 obj.right_deck = new util.deck('patron_right_deck');
29                 obj.left_deck = new util.deck('patron_left_deck');
30
31                 function spawn_checkout_interface() {
32                         obj.right_deck.set_iframe(
33                                 urls.remote_checkout
34                                 + '?session=' + window.escape( obj.session )
35                                 + '&patron_id=' + window.escape( obj.patron.id() ),
36                                 {},
37                                 { 
38                                         'on_checkout' : function(checkout) {
39                                                 var c = obj.summary_window.g.summary.patron.checkouts();
40                                                 c.push( checkout );
41                                                 obj.summary_window.g.summary.patron.checkouts( c );
42                                                 obj.summary_window.g.summary.controller.render('patron_checkouts');
43                                         }
44                                 }
45                         );
46                         dump('obj.right_deck.node.childNodes.length = ' + obj.right_deck.node.childNodes.length + '\n');
47                 }
48
49                 JSAN.use('util.controller'); obj.controller = new util.controller();
50                 obj.controller.init(
51                         {
52                                 control_map : {
53                                         'cmd_broken' : [
54                                                 ['command'],
55                                                 function() { alert('Not Yet Implemented'); }
56                                         ],
57                                         'cmd_patron_retrieve' : [
58                                                 ['command'],
59                                                 function(ev) {
60                                                         if (typeof window.xulG == 'object' && typeof window.xulG.new_tab == 'function') {
61                                                                 for (var i = 0; i < obj.retrieve_ids.length; i++) {     
62                                                                         try {
63                                                                                 var url = urls.remote_patron_display 
64                                                                                         + '?session=' + window.escape(obj.session) 
65                                                                                         + '&id=' + window.escape( obj.retrieve_ids[i] );
66                                                                                 window.xulG.new_tab(
67                                                                                         url
68                                                                                 );
69                                                                         } catch(E) {
70                                                                                 alert(E);
71                                                                         }
72                                                                 }
73                                                         }
74                                                 }
75                                         ],
76                                         'cmd_search_form' : [
77                                                 ['command'],
78                                                 function(ev) {
79                                                         obj.controller.view.cmd_search_form.setAttribute('disabled','true');
80                                                         obj.left_deck.node.selectedIndex = 0;
81                                                         obj.controller.view.patron_name.setAttribute('value','No Patron Selected');
82                                                 }
83                                         ],
84                                         'cmd_patron_refresh' : [
85                                                 ['command'],
86                                                 function(ev) {
87                                                         obj.controller.view.patron_name.setAttribute(
88                                                                 'value','Retrieving...'
89                                                         );
90                                                         try { obj.summary_window.refresh(); } catch(E) { dump(E + '\n'); }
91                                                         try { obj.refresh_deck(); } catch(E) { dump(E + '\n'); }
92                                                 }
93                                         ],
94                                         'cmd_patron_checkout' : [
95                                                 ['command'],
96                                                 spawn_checkout_interface
97                                         ],
98                                         'cmd_patron_items' : [
99                                                 ['command'],
100                                                 function(ev) {
101                                                         obj.right_deck.set_iframe(
102                                                                 urls.remote_patron_items
103                                                                 + '?session=' + window.escape( obj.session )
104                                                                 + '&patron_id=' + window.escape( obj.patron.id() ),
105                                                                 {},
106                                                                 {
107                                                                         'checkouts' : obj.patron.checkouts()
108                                                                 }
109                                                         );
110                                                         dump('obj.right_deck.node.childNodes.length = ' + obj.right_deck.node.childNodes.length + '\n');
111                                                 }
112                                         ],
113                                         'cmd_patron_holds' : [
114                                                 ['command'],
115                                                 function(ev) {
116                                                         obj.right_deck.set_iframe(
117                                                                 urls.remote_patron_holds        
118                                                                 + '?session=' + window.escape( obj.session )
119                                                                 + '&patron_id=' + window.escape( obj.patron.id() ),
120                                                                 {},
121                                                                 {
122                                                                         'holds' : obj.patron.hold_requests()
123                                                                 }
124                                                         );
125                                                         dump('obj.right_deck.node.childNodes.length = ' + obj.right_deck.node.childNodes.length + '\n');
126                                                 }
127                                         ],
128                                         'cmd_patron_bills' : [
129                                                 ['command'],
130                                                 function(ev) {
131                                                         obj.right_deck.set_iframe(
132                                                                 urls.remote_patron_bills
133                                                                 + '?session=' + window.escape( obj.session )
134                                                                 + '&patron_id=' + window.escape( obj.patron.id() ),
135                                                                 {},
136                                                                 {
137                                                                         /* FIXME */
138                                                                         'bills' : obj.patron.bills
139                                                                 }
140                                                         );
141                                                         dump('obj.right_deck.node.childNodes.length = ' + obj.right_deck.node.childNodes.length + '\n');
142                                                 }
143                                         ],
144                                         'cmd_patron_edit' : [
145                                                 ['command'],
146                                                 function(ev) {
147                                                         obj.right_deck.set_iframe(
148                                                                 urls.remote_patron_edit
149                                                                 + '?ses=' + window.escape( obj.session )
150                                                                 + '&usr=' + window.escape( obj.patron.id() ),
151                                                                 {}, {}
152                                                         );
153                                                         dump('obj.right_deck.node.childNodes.length = ' + obj.right_deck.node.childNodes.length + '\n');
154                                                 }
155                                         ],
156                                         'cmd_patron_info' : [
157                                                 ['command'],
158                                                 function(ev) {
159                                                         obj.right_deck.set_iframe(urls.remote_patron_info);
160                                                         dump('obj.right_deck.node.childNodes.length = ' + obj.right_deck.node.childNodes.length + '\n');
161                                                 }
162                                         ],
163                                         'patron_name' : [
164                                                 ['render'],
165                                                 function(e) {
166                                                         return function() { 
167                                                                 e.setAttribute('value',
168                                                                         obj.patron.family_name() + ', ' + obj.patron.first_given_name() + ' ' +
169                                                                         ( obj.patron.second_given_name() ? obj.patron.second_given_name() : '' )
170                                                                 );
171                                                                 e.setAttribute('style','background-color: lime');
172                                                                 if (obj.summary_window) {
173                                                                         //FIXME//bills should become a virtual field
174                                                                         if (obj.summary_window.g.summary.patron.bills.length > 0)
175                                                                                 e.setAttribute('style','background-color: yellow');
176                                                                         if (obj.summary_window.g.summary.patron.standing() == 2)
177                                                                                 e.setAttribute('style','background-color: lightred');
178                                                                 }
179
180                                                         };
181                                                 }
182                                         ],
183                                         'PatronNavBar' : [
184                                                 ['render'],
185                                                 function(e) {
186                                                         return function() {}
187                                                 }
188                                         ],
189                                 }
190                         }
191                 );
192
193                 if (obj.barcode || obj.id) {
194                         if (typeof window.xulG == 'object' && typeof window.xulG.set_tab_name == 'function') {
195                                 try { window.xulG.set_tab_name('Retrieving Patron...'); } catch(E) { alert(E); }
196                         }
197
198                         obj.controller.view.PatronNavBar.selectedIndex = 1;
199                         obj.controller.view.cmd_patron_refresh.setAttribute('disabled','true');
200                         obj.controller.view.cmd_patron_checkout.setAttribute('disabled','true');
201                         obj.controller.view.cmd_patron_items.setAttribute('disabled','true');
202                         obj.controller.view.cmd_patron_holds.setAttribute('disabled','true');
203                         obj.controller.view.cmd_patron_bills.setAttribute('disabled','true');
204                         obj.controller.view.cmd_patron_edit.setAttribute('disabled','true');
205                         obj.controller.view.cmd_patron_info.setAttribute('disabled','true');
206                         obj.controller.view.patron_name.setAttribute('value','Retrieving...');
207                         var frame = obj.left_deck.set_iframe(
208                                 urls.remote_patron_summary
209                                 +'?session=' + window.escape(obj.session)
210                                 +'&barcode=' + window.escape(obj.barcode) 
211                                 +'&id=' + window.escape(obj.id), 
212                                 {},
213                                 {
214                                         'on_finished' : function(patron) {
215
216                                                 obj.patron = patron; obj.controller.render();
217
218                                                 obj.controller.view.cmd_patron_refresh.setAttribute('disabled','false');
219                                                 obj.controller.view.cmd_patron_checkout.setAttribute('disabled','false');
220                                                 obj.controller.view.cmd_patron_items.setAttribute('disabled','false');
221                                                 obj.controller.view.cmd_patron_holds.setAttribute('disabled','false');
222                                                 obj.controller.view.cmd_patron_bills.setAttribute('disabled','false');
223                                                 obj.controller.view.cmd_patron_edit.setAttribute('disabled','false');
224                                                 obj.controller.view.cmd_patron_info.setAttribute('disabled','false');
225
226                                                 if (typeof window.xulG == 'object' && typeof window.xulG.set_tab_name == 'function') {
227                                                         try { 
228                                                                 window.xulG.set_tab_name(
229                                                                         'Patron: ' + patron.family_name() + ', ' + patron.first_given_name() + ' ' 
230                                                                                 + (patron.second_given_name() ? patron.second_given_name() : '' ) 
231                                                                 ); 
232                                                         } catch(E) { 
233                                                                 obj.error.sdump('D_ERROR',E);
234                                                         }
235                                                 }
236
237                                                 if (!obj._checkout_spawned) {
238                                                         spawn_checkout_interface();
239                                                         obj._checkout_spawned = true;
240                                                 }
241                                         }
242                                 }
243                         );
244                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
245                         obj.summary_window = frame.contentWindow;
246                 } else {
247                         if (typeof window.xulG == 'object' && typeof window.xulG.set_tab_name == 'function') {
248                                 try { window.xulG.set_tab_name('Patron Search'); } catch(E) { alert(E); }
249                         }
250
251                         obj.controller.view.PatronNavBar.selectedIndex = 0;
252                         obj.controller.view.cmd_patron_retrieve.setAttribute('disabled','true');
253                         obj.controller.view.cmd_search_form.setAttribute('disabled','true');
254                         var form_frame = obj.left_deck.set_iframe(
255                                 urls.remote_patron_search_form
256                                 +'?session=' + window.escape(obj.session),
257                                 {},
258                                 {
259                                         'on_submit' : function(query) {
260                                                 obj.controller.view.cmd_patron_retrieve.setAttribute('disabled','true');
261                                                 var list_frame = obj.right_deck.reset_iframe(
262                                                         urls.remote_patron_search_result
263                                                         +'?session=' + window.escape(obj.session) + '&' + query,
264                                                         {},
265                                                         {
266                                                                 'on_select' : function(list) {
267                                                                         obj.controller.view.cmd_patron_retrieve.setAttribute('disabled','false');
268                                                                         obj.controller.view.cmd_search_form.setAttribute('disabled','false');
269                                                                         obj.retrieve_ids = list;
270                                                                         obj.controller.view.patron_name.setAttribute('value','Retrieving...');
271                                                                         setTimeout(
272                                                                                 function() {
273                                                                                         var frame = obj.left_deck.set_iframe(
274                                                                                                 urls.remote_patron_summary
275                                                                                                         +'?session=' + window.escape(obj.session)
276                                                                                                         +'&id=' + window.escape(list[0]), 
277                                                                                                         {},
278                                                                                                         {
279                                                                                                                 'on_finished' : function(patron) {
280                                                                                                                         obj.patron = patron;
281                                                                                                                         obj.controller.render();
282                                                                                                                 }
283                                                                                                         }
284                                                                                         );
285                                                                                         netscape.security.PrivilegeManager.enablePrivilege(
286                                                                                                 "UniversalXPConnect"
287                                                                                         );
288                                                                                         obj.summary_window = frame.contentWindow;
289                                                                                         obj.patron = obj.summary_window.g.summary.patron;
290                                                                                         obj.controller.render('patron_name');
291                                                                                 }, 0
292                                                                         );
293                                                                 }
294                                                         }
295                                                 );
296                                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
297                                                 obj.search_result = list_frame.contentWindow;
298                                         }
299                                 }
300                         );
301                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
302                         obj.search_window = form_frame.contentWindow;
303                         obj._checkout_spawned = true;
304                 }
305         },
306
307         '_checkout_spawned' : false,
308
309         'refresh_deck' : function() {
310                 var obj = this;
311                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
312                 for (var i = 0; i < obj.right_deck.node.childNodes.length; i++) {
313                         try {
314
315                                 var f = obj.right_deck.node.childNodes[i];
316                                 var w = f.contentWindow;
317                                 if (typeof w.refresh == 'function') {
318                                         w.refresh();
319                                 }
320
321                         } catch(E) {
322                                 dump('refresh_deck: ' + E + '\n');
323                         }
324                 }
325         },
326 }
327
328 dump('exiting patron/display.js\n');