]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/patron/display.js
the not important bug fixed
[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_patron_refresh' : [
77                                                 ['command'],
78                                                 function(ev) {
79                                                         obj.controller.view.patron_name.setAttribute(
80                                                                 'value','Retrieving...'
81                                                         );
82                                                         try { obj.summary_window.refresh(); } catch(E) { dump(E + '\n'); }
83                                                         try { obj.refresh_deck(); } catch(E) { dump(E + '\n'); }
84                                                 }
85                                         ],
86                                         'cmd_patron_checkout' : [
87                                                 ['command'],
88                                                 spawn_checkout_interface
89                                         ],
90                                         'cmd_patron_items' : [
91                                                 ['command'],
92                                                 function(ev) {
93                                                         obj.right_deck.set_iframe(
94                                                                 urls.remote_patron_items
95                                                                 + '?session=' + window.escape( obj.session )
96                                                                 + '&patron_id=' + window.escape( obj.patron.id() ),
97                                                                 {},
98                                                                 {
99                                                                         'checkouts' : obj.patron.checkouts()
100                                                                 }
101                                                         );
102                                                         dump('obj.right_deck.node.childNodes.length = ' + obj.right_deck.node.childNodes.length + '\n');
103                                                 }
104                                         ],
105                                         'cmd_patron_holds' : [
106                                                 ['command'],
107                                                 function(ev) {
108                                                         obj.right_deck.set_iframe(
109                                                                 urls.remote_patron_holds        
110                                                                 + '?session=' + window.escape( obj.session )
111                                                                 + '&patron_id=' + window.escape( obj.patron.id() ),
112                                                                 {},
113                                                                 {
114                                                                         //FIXME//'holds' : obj.patron.holds()
115                                                                 }
116                                                         );
117                                                         dump('obj.right_deck.node.childNodes.length = ' + obj.right_deck.node.childNodes.length + '\n');
118                                                 }
119                                         ],
120                                         'cmd_patron_bills' : [
121                                                 ['command'],
122                                                 function(ev) {
123                                                         obj.right_deck.set_iframe(
124                                                                 urls.remote_patron_bills
125                                                                 + '?session=' + window.escape( obj.session )
126                                                                 + '&patron_id=' + window.escape( obj.patron.id() ),
127                                                                 {},
128                                                                 {
129                                                                         //FIXME//'bills' : obj.patron.bills()
130                                                                 }
131                                                         );
132                                                         dump('obj.right_deck.node.childNodes.length = ' + obj.right_deck.node.childNodes.length + '\n');
133                                                 }
134                                         ],
135                                         'cmd_patron_edit' : [
136                                                 ['command'],
137                                                 function(ev) {
138                                                         obj.right_deck.set_iframe(
139                                                                 urls.remote_patron_edit
140                                                                 + '?ses=' + window.escape( obj.session )
141                                                                 + '&usr=' + window.escape( obj.patron.id() ),
142                                                                 {}, {}
143                                                         );
144                                                         dump('obj.right_deck.node.childNodes.length = ' + obj.right_deck.node.childNodes.length + '\n');
145                                                 }
146                                         ],
147                                         'cmd_patron_info' : [
148                                                 ['command'],
149                                                 function(ev) {
150                                                         obj.right_deck.set_iframe(urls.remote_patron_info);
151                                                         dump('obj.right_deck.node.childNodes.length = ' + obj.right_deck.node.childNodes.length + '\n');
152                                                 }
153                                         ],
154                                         'patron_name' : [
155                                                 ['render'],
156                                                 function(e) {
157                                                         return function() { 
158                                                                 e.setAttribute('value',
159                                                                         obj.patron.family_name() + ', ' + obj.patron.first_given_name()
160                                                                 );
161                                                                 e.setAttribute('style','background-color: lime');
162                                                                 if (obj.summary_window) {
163                                                                         //FIXME//bills should become a virtual field
164                                                                         if (obj.summary_window.g.summary.patron.bills.length > 0)
165                                                                                 e.setAttribute('style','background-color: yellow');
166                                                                         if (obj.summary_window.g.summary.patron.standing() == 2)
167                                                                                 e.setAttribute('style','background-color: lightred');
168                                                                 }
169
170                                                         };
171                                                 }
172                                         ],
173                                         'PatronNavBar' : [
174                                                 ['render'],
175                                                 function(e) {
176                                                         return function() {}
177                                                 }
178                                         ],
179                                 }
180                         }
181                 );
182
183                 if (obj.barcode || obj.id) {
184                         if (typeof window.xulG == 'object' && typeof window.xulG.set_tab_name == 'function') {
185                                 try { window.xulG.set_tab_name('Retrieving Patron...'); } catch(E) { alert(E); }
186                         }
187
188                         obj.controller.view.PatronNavBar.selectedIndex = 1;
189                         obj.controller.view.cmd_patron_refresh.setAttribute('disabled','true');
190                         obj.controller.view.cmd_patron_checkout.setAttribute('disabled','true');
191                         obj.controller.view.cmd_patron_items.setAttribute('disabled','true');
192                         obj.controller.view.cmd_patron_holds.setAttribute('disabled','true');
193                         obj.controller.view.cmd_patron_bills.setAttribute('disabled','true');
194                         obj.controller.view.cmd_patron_edit.setAttribute('disabled','true');
195                         obj.controller.view.cmd_patron_info.setAttribute('disabled','true');
196                         obj.controller.view.patron_name.setAttribute('value','Retrieving...');
197                         var frame = obj.left_deck.set_iframe(
198                                 urls.remote_patron_summary
199                                 +'?session=' + window.escape(obj.session)
200                                 +'&barcode=' + window.escape(obj.barcode) 
201                                 +'&id=' + window.escape(obj.id), 
202                                 {},
203                                 {
204                                         'on_finished' : function(patron) {
205
206                                                 obj.patron = patron; obj.controller.render();
207
208                                                 obj.controller.view.cmd_patron_refresh.setAttribute('disabled','false');
209                                                 obj.controller.view.cmd_patron_checkout.setAttribute('disabled','false');
210                                                 obj.controller.view.cmd_patron_items.setAttribute('disabled','false');
211                                                 obj.controller.view.cmd_patron_holds.setAttribute('disabled','false');
212                                                 obj.controller.view.cmd_patron_bills.setAttribute('disabled','false');
213                                                 obj.controller.view.cmd_patron_edit.setAttribute('disabled','false');
214                                                 obj.controller.view.cmd_patron_info.setAttribute('disabled','false');
215
216                                                 if (typeof window.xulG == 'object' && typeof window.xulG.set_tab_name == 'function') {
217                                                         try { window.xulG.set_tab_name('Patron: ' + patron.family_name() + ', ' + patron.first_given_name() + ' ' + (patron.second_given_name() ? patron.second_given_name() : '' ) ); } 
218                                                         catch(E) { alert(E); }
219                                                 }
220
221                                                 if (!obj._checkout_spawned) {
222                                                         spawn_checkout_interface();
223                                                         obj._checkout_spawned = true;
224                                                 }
225                                         }
226                                 }
227                         );
228                         obj.summary_window = frame.contentWindow;
229                 } else {
230                         if (typeof window.xulG == 'object' && typeof window.xulG.set_tab_name == 'function') {
231                                 try { window.xulG.set_tab_name('Patron Search'); } catch(E) { alert(E); }
232                         }
233
234                         obj.controller.view.PatronNavBar.selectedIndex = 0;
235                         obj.controller.view.cmd_patron_retrieve.setAttribute('disabled','true');
236                         var form_frame = obj.left_deck.set_iframe(
237                                 urls.remote_patron_search_form
238                                 +'?session=' + window.escape(obj.session),
239                                 {},
240                                 {
241                                         'on_submit' : function(query) {
242                                                 obj.controller.view.cmd_patron_retrieve.setAttribute('disabled','true');
243                                                 var list_frame = obj.right_deck.reset_iframe(
244                                                         urls.remote_patron_search_result
245                                                         +'?session=' + window.escape(obj.session) + '&' + query,
246                                                         {},
247                                                         {
248                                                                 'on_select' : function(list) {
249                                                                         obj.controller.view.cmd_patron_retrieve.setAttribute('disabled','false');
250                                                                         obj.retrieve_ids = list;
251                                                                 }
252                                                         }
253                                                 );
254                                                 obj.search_result = list_frame.contentWindow;
255                                         }
256                                 }
257                         );
258                         obj.search_window = form_frame.contentWindow;
259                         obj._checkout_spawned = true;
260                 }
261         },
262
263         '_checkout_spawned' : false,
264
265         'refresh_deck' : function() {
266                 var obj = this;
267                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
268                 for (var i = 0; i < obj.right_deck.node.childNodes.length; i++) {
269                         try {
270
271                                 var f = obj.right_deck.node.childNodes[i];
272                                 var w = f.contentWindow;
273                                 if (typeof w.refresh == 'function') {
274                                         w.refresh();
275                                 }
276
277                         } catch(E) {
278                                 dump('refresh_deck: ' + E + '\n');
279                         }
280                 }
281         },
282 }
283
284 dump('exiting patron/display.js\n');