]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/patron/display.js
barcode
[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('main.window'); this.window = new main.window();
8         JSAN.use('main.network'); this.network = new main.network();
9         this.w = window;
10 }
11
12 patron.display.prototype = {
13
14         'init' : function( params ) {
15
16                 this.session = params['session'];
17                 this.barcode = params['barcode'];
18
19                 JSAN.use('OpenILS.data'); this.OpenILS = {}; 
20                 this.OpenILS.data = new OpenILS.data( { 'session' : params.session } ); this.OpenILS.data.init(true);
21
22                 var obj = this;
23                 obj.view = {}; obj.render_list = [];
24
25                 var control_map = {
26                         'cmd_broken' : [
27                                 ['command'],
28                                 function() { alert('Not Yet Implemented'); }
29                         ],
30                         'patron_name' : [
31                                 ['render'],
32                                 function(e) {
33                                         return function() { 
34                                                 e.setAttribute('value',obj.patron.family_name() + ', ' 
35                                                         + obj.patron.first_given_name());
36                                         };
37                                 }
38                         ],
39                         'patron_profile' : [
40                                 ['render'],
41                                 function(e) {
42                                         return function() { 
43                                                 e.setAttribute('value',
44                                                         obj.OpenILS.data.hash.pgt[
45                                                                 obj.patron.profile()
46                                                         ].name()
47                                                 );
48                                         };
49                                 }
50                         ],
51                         'patron_credit' : [
52                                 ['render'],
53                                 function(e) {
54                                         return function() { 
55                                                 JSAN.use('util.money');
56                                                 e.setAttribute('value',
57                                                         util.money.cents_as_dollars(
58                                                                 obj.patron.credit_forward_balance()
59                                                         )
60                                                 );
61                                         };
62                                 }
63                         ],
64                         'patron_bill' : [
65                                 ['render'],
66                                 function(e) {
67                                         return function() { 
68                                                 JSAN.use('util.money');
69                                                 var total = 0;
70                                                 //FIXME//adjust when .bills becomes a virtual field
71                                                 for (var i = 0; i < obj.patron.bills.length; i++) {
72                                                         total += util.money.dollars_float_to_cents_integer( 
73                                                                 obj.patron.bills[i].balance_owed() 
74                                                         );
75                                                 }
76                                                 e.setAttribute('value',
77                                                         util.money.cents_as_dollars( total )
78                                                 );
79                                         };
80                                 }
81                         ],
82                         'patron_checkouts' : [
83                                 ['render'],
84                                 function(e) {
85                                         return function() { 
86                                                 e.setAttribute('value',
87                                                         obj.patron.checkouts.length     
88                                                 );
89                                         };
90                                 }
91                         ],
92                         'patron_overdue' : [
93                                 ['render'],
94                                 function(e) {
95                                         return function() { 
96                                                 //FIXME//Get Bill to do this correctly on server side
97                                                 JSAN.use('util.date');
98                                                 var total = 0;
99                                                 for (var i = 0; i < obj.patron.checkouts().length; i++) {
100                                                         var item = obj.patron.checkouts()[i];
101                                                         var due_date = item.circ.due_date();
102                                                         due_date = due_date.substr(0,4) 
103                                                                 + due_date.substr(5,2) + due_date.substr(8,2);
104                                                         var today = util.date.formatted_date( new Date() , '%Y%m%d' );
105                                                         if (today > due_date) total++;
106                                                 }
107                                                 e.setAttribute('value',
108                                                         total
109                                                 );
110                                         };
111                                 }
112                         ],
113                         'patron_holds' : [
114                                 ['render'],
115                                 function(e) {
116                                         return function() { 
117                                                 e.setAttribute('value',
118                                                         obj.patron.hold_requests.length
119                                                 );
120                                         };
121                                 }
122                         ],
123                         'patron_holds_available' : [
124                                 ['render'],
125                                 function(e) {
126                                         return function() { 
127                                                 var total = 0;
128                                                 for (var i = 0; i < obj.patron.hold_requests().length; i++) {
129                                                         var hold = obj.patron.hold_requests()[i];
130                                                         if (hold.capture_time()) total++;
131                                                 }
132                                                 e.setAttribute('value',
133                                                         total
134                                                 );
135                                         };
136                                 }
137                         ],
138                         'patron_card' : [
139                                 ['render'],
140                                 function(e) {
141                                         return function() { 
142                                                 e.setAttribute('value',
143                                                         obj.patron.card().barcode()
144                                                 );
145                                         };
146                                 }
147                         ],
148                         'patron_ident_type_1' : [
149                                 ['render'],
150                                 function(e) {
151                                         return function() { };
152                                 }
153                         ],
154                         'patron_ident_value_1' : [
155                                 ['render'],
156                                 function(e) {
157                                         return function() { };
158                                 }
159                         ],
160                         'patron_ident_type_2' : [
161                                 ['render'],
162                                 function(e) {
163                                         return function() { };
164                                 }
165                         ],
166                         'patron_date_of_birth' : [
167                                 ['render'],
168                                 function(e) {
169                                         return function() { };
170                                 }
171                         ],
172                         'patron_day_phone' : [
173                                 ['render'],
174                                 function(e) {
175                                         return function() { };
176                                 }
177                         ],
178                         'patron_evening_phone' : [
179                                 ['render'],
180                                 function(e) {
181                                         return function() { };
182                                 }
183                         ],
184                         'patron_other_phone' : [
185                                 ['render'],
186                                 function(e) {
187                                         return function() { };
188                                 }
189                         ],
190                         'patron_email' : [
191                                 ['render'],
192                                 function(e) {
193                                         return function() { };
194                                 }
195                         ],
196                         'patron_photo_url' : [
197                                 ['render'],
198                                 function(e) {
199                                         return function() { };
200                                 }
201                         ],
202                         'patron_library' : [
203                                 ['render'],
204                                 function(e) {
205                                         return function() { };
206                                 }
207                         ],
208                         'patron_mailing_address_street1' : [
209                                 ['render'],
210                                 function(e) {
211                                         return function() { };
212                                 }
213                         ],
214                         'patron_mailing_address_street2' : [
215                                 ['render'],
216                                 function(e) {
217                                         return function() { };
218                                 }
219                         ],
220                         'patron_mailing_address_city' : [
221                                 ['render'],
222                                 function(e) {
223                                         return function() { };
224                                 }
225                         ],
226                         'patron_mailing_address_state' : [
227                                 ['render'],
228                                 function(e) {
229                                         return function() { };
230                                 }
231                         ],
232                         'patron_mailing_address_post_code' : [
233                                 ['render'],
234                                 function(e) {
235                                         return function() { };
236                                 }
237                         ],
238                         'patron_physical_address_street1' : [
239                                 ['render'],
240                                 function(e) {
241                                         return function() { };
242                                 }
243                         ],
244                         'patron_physical_address_street2' : [
245                                 ['render'],
246                                 function(e) {
247                                         return function() { };
248                                 }
249                         ],
250                         'patron_physical_address_city' : [
251                                 ['render'],
252                                 function(e) {
253                                         return function() { };
254                                 }
255                         ],
256                         'patron_physical_address_state' : [
257                                 ['render'],
258                                 function(e) {
259                                         return function() { };
260                                 }
261                         ],
262                         'patron_physical_address_post_code' : [
263                                 ['render'],
264                                 function(e) {
265                                         return function() { };
266                                 }
267                         ]
268                 };
269
270                 for (var i in control_map) {
271                         var cmd = this.w.document.getElementById(i);
272                         if (cmd) {
273                                 for (var j in control_map[i][0]) {
274                                         if (control_map[i][1]) {
275                                                 var ev_type = control_map[i][0][j];
276                                                 switch(ev_type) {
277                                                         case 'render':
278                                                                 obj.render_list.push( control_map[i][1](cmd) ); 
279                                                         break;
280                                                         default: cmd.addEventListener(ev_type,control_map[i][1],false);
281                                                 }
282                                         }
283                                 }
284                         }
285                         obj.view[i] = cmd;
286                 }
287
288                 obj.retrieve();
289
290         },
291
292         'retrieve' : function() {
293
294                 var patron;
295                 try {
296
297                         var obj = this;
298
299                         var chain = [];
300
301                         // Retrieve the patron
302                         chain.push(
303                                 function() {
304                                         try {
305                                                 var patron = obj.network.request(
306                                                         'open-ils.actor',
307                                                         'open-ils.actor.user.fleshed.retrieve_by_barcode',
308                                                         [ obj.session, obj.barcode ]
309                                                 );
310                                                 if (patron) {
311
312                                                         if (instanceOf(patron,au)) {
313
314                                                                 obj.patron = patron;
315
316                                                         } else {
317
318                                                                 throw('patron is not an au fm object');
319                                                         }
320                                                 } else {
321
322                                                         throw('patron == false');
323                                                 }
324
325                                         } catch(E) {
326                                                 var error = ('patron.display.retrieve : ' + js2JSON(E));
327                                                 obj.error.sdump('D_ERROR',error);
328                                                 alert(error);
329                                                 //FIXME// abort the chain
330                                         }
331                                 }
332                         );
333
334                         // Retrieve the bills
335                         chain.push(
336                                 function() {
337                                         try {
338                                                 var bills = obj.network.request(
339                                                         'open-ils.actor',
340                                                         'open-ils.actor.user.transactions.have_balance',
341                                                         [ obj.session, obj.patron.id() ]
342                                                 );
343                                                 //FIXME// obj.patron.bills( bills );
344                                                 obj.patron.bills = bills;
345                                         } catch(E) {
346                                                 var error = ('patron.display.retrieve : ' + js2JSON(E));
347                                                 obj.error.sdump('D_ERROR',error);
348                                                 alert(error);
349                                                 //FIXME// abort the chain
350                                         }
351                                 }
352                         );
353
354                         // Retrieve the checkouts
355                         chain.push(
356                                 function() {
357                                         try {
358                                                 var checkouts = obj.network.request(
359                                                         'open-ils.circ',
360                                                         'open-ils.circ.actor.user.checked_out',
361                                                         [ obj.session, obj.patron.id() ]
362                                                 );
363                                                 obj.patron.checkouts( checkouts );
364                                         } catch(E) {
365                                                 var error = ('patron.display.retrieve : ' + js2JSON(E));
366                                                 obj.error.sdump('D_ERROR',error);
367                                                 alert(error);
368                                                 //FIXME// abort the chain
369                                         }
370                                 }
371                         );
372
373                         // Retrieve the holds
374                         chain.push(
375                                 function() {
376                                         try {
377                                                 var holds = obj.network.request(
378                                                         'open-ils.circ',
379                                                         'open-ils.circ.holds.retrieve',
380                                                         [ obj.session, obj.patron.id() ]
381                                                 );
382                                                 obj.patron.hold_requests( holds );
383                                         } catch(E) {
384                                                 var error = ('patron.display.retrieve : ' + js2JSON(E));
385                                                 obj.error.sdump('D_ERROR',error);
386                                                 alert(error);
387                                                 //FIXME// abort the chain
388                                         }
389                                 }
390                         );
391
392                         // Update the screen
393                         chain.push( function() { obj.render(); } );
394
395                         // Do it
396                         JSAN.use('util.exec');
397                         util.exec.chain( chain );
398
399                 } catch(E) {
400                         var error = ('patron.display.retrieve : ' + js2JSON(E));
401                         this.error.sdump('D_ERROR',error);
402                         alert(error);
403                 }
404         },
405
406         'render' : function() {
407
408                 for (var i in this.render_list) {
409                         try {
410                                 this.render_list[i]();
411                         } catch(E) {
412                                 var error = 'Problem in patron.display.render with\n' + this.render_list[i] + '\n\n' + js2JSON(E);
413                                 this.error.sdump('D_ERROR',error);
414                                 alert(error);
415                         }
416                 }
417         }
418
419 }
420
421 dump('exiting patron/display.js\n');