]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/patron/display.js
cb05d909a3e685119bd4340116ade139f457001f
[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                 var obj = this;
17
18                 obj.session = params['session'];
19                 obj.barcode = params['barcode'];
20
21                 JSAN.use('OpenILS.data'); this.OpenILS = {}; 
22                 obj.OpenILS.data = new OpenILS.data(); obj.OpenILS.data.init({'via':'stash'});
23
24                 JSAN.use('util.deck');  obj.deck = new util.deck('patron_deck');
25
26                 JSAN.use('main.controller'); obj.controller = new main.controller();
27                 obj.controller.init(
28                         {
29                                 control_map : {
30                                         'cmd_broken' : [
31                                                 ['command'],
32                                                 function() { alert('Not Yet Implemented'); }
33                                         ],
34                                         'cmd_patron_refresh' : [
35                                                 ['command'],
36                                                 function(ev) {
37                                                         obj.controller.view.patron_name.setAttribute(
38                                                                 'value','Retrieving...'
39                                                         );
40                                                         obj.retrieve();
41                                                 }
42                                         ],
43                                         'cmd_patron_checkout' : [
44                                                 ['command'],
45                                                 function(ev) {
46                                                         obj.deck.set_iframe(
47                                                                 urls.remote_checkout
48                                                                 + '?session=' + window.escape( obj.session )
49                                                                 + '&patron_id=' + window.escape( obj.patron.id() ),
50                                                                 {},
51                                                                 { 
52                                                                         'on_checkout' : function() {
53                                                                                 alert('got here');
54                                                                                 obj.controller.render('patron_checkouts');
55                                                                         }
56                                                                 }
57                                                         );
58                                                         dump('obj.deck.node.childNodes.length = ' + obj.deck.node.childNodes.length + '\n');
59                                                 }
60                                         ],
61                                         'cmd_patron_items' : [
62                                                 ['command'],
63                                                 function(ev) {
64                                                         obj.deck.set_iframe('data:text/html,<h1>Items Here</h1>');
65                                                         dump('obj.deck.node.childNodes.length = ' + obj.deck.node.childNodes.length + '\n');
66                                                 }
67                                         ],
68                                         'cmd_patron_holds' : [
69                                                 ['command'],
70                                                 function(ev) {
71                                                         obj.deck.set_iframe('data:text/html,<h1>Holds Here</h1>');
72                                                         dump('obj.deck.node.childNodes.length = ' + obj.deck.node.childNodes.length + '\n');
73                                                 }
74                                         ],
75                                         'cmd_patron_bills' : [
76                                                 ['command'],
77                                                 function(ev) {
78                                                         obj.deck.set_iframe('data:text/html,<h1>Bills Here</h1>');
79                                                         dump('obj.deck.node.childNodes.length = ' + obj.deck.node.childNodes.length + '\n');
80                                                 }
81                                         ],
82                                         'cmd_patron_edit' : [
83                                                 ['command'],
84                                                 function(ev) {
85                                                         obj.deck.set_iframe('data:text/html,<h1>Edit Here</h1>');
86                                                         dump('obj.deck.node.childNodes.length = ' + obj.deck.node.childNodes.length + '\n');
87                                                 }
88                                         ],
89                                         'cmd_patron_info' : [
90                                                 ['command'],
91                                                 function(ev) {
92                                                         obj.deck.set_iframe('data:text/html,<h1>Info Here</h1>');
93                                                         dump('obj.deck.node.childNodes.length = ' + obj.deck.node.childNodes.length + '\n');
94                                                 }
95                                         ],
96                                         'patron_name' : [
97                                                 ['render'],
98                                                 function(e) {
99                                                         return function() { 
100                                                                 e.setAttribute('value',
101                                                                         obj.patron.family_name() + ', ' + obj.patron.first_given_name()
102                                                                 );
103                                                                 e.setAttribute('style','background-color: lime');
104                                                                 //FIXME//bills should become a virtual field
105                                                                 if (obj.patron.bills.length > 0)
106                                                                         e.setAttribute('style','background-color: yellow');
107                                                                 if (obj.patron.standing() == 2)
108                                                                         e.setAttribute('style','background-color: lightred');
109
110                                                         };
111                                                 }
112                                         ],
113                                         'patron_profile' : [
114                                                 ['render'],
115                                                 function(e) {
116                                                         return function() { 
117                                                                 e.setAttribute('value',
118                                                                         obj.OpenILS.data.hash.pgt[
119                                                                                 obj.patron.profile()
120                                                                         ].name()
121                                                                 );
122                                                         };
123                                                 }
124                                         ],
125                                         'patron_standing' : [
126                                                 ['render'],
127                                                 function(e) {
128                                                         return function() {
129                                                                 e.setAttribute('value',
130                                                                         obj.OpenILS.data.hash.cst[
131                                                                                 obj.patron.standing()
132                                                                         ].value()
133                                                                 );
134                                                         };
135                                                 }
136                                         ],
137                                         'patron_credit' : [
138                                                 ['render'],
139                                                 function(e) {
140                                                         return function() { 
141                                                                 JSAN.use('util.money');
142                                                                 e.setAttribute('value',
143                                                                         util.money.cents_as_dollars(
144                                                                                 obj.patron.credit_forward_balance()
145                                                                         )
146                                                                 );
147                                                         };
148                                                 }
149                                         ],
150                                         'patron_bill' : [
151                                                 ['render'],
152                                                 function(e) {
153                                                         return function() { 
154                                                                 JSAN.use('util.money');
155                                                                 var total = 0;
156                                                                 //FIXME//adjust when .bills becomes a virtual field
157                                                                 for (var i = 0; i < obj.patron.bills.length; i++) {
158                                                                         total += util.money.dollars_float_to_cents_integer( 
159                                                                                 obj.patron.bills[i].balance_owed() 
160                                                                         );
161                                                                 }
162                                                                 e.setAttribute('value',
163                                                                         util.money.cents_as_dollars( total )
164                                                                 );
165                                                         };
166                                                 }
167                                         ],
168                                         'patron_checkouts' : [
169                                                 ['render'],
170                                                 function(e) {
171                                                         return function() { 
172                                                                 e.setAttribute('value',
173                                                                         obj.patron.checkouts().length   
174                                                                 );
175                                                         };
176                                                 }
177                                         ],
178                                         'patron_overdue' : [
179                                                 ['render'],
180                                                 function(e) {
181                                                         return function() { 
182                                                                 //FIXME//Get Bill to do this correctly on server side
183                                                                 JSAN.use('util.date');
184                                                                 var total = 0;
185                                                                 for (var i = 0; i < obj.patron.checkouts().length; i++) {
186                                                                         var item = obj.patron.checkouts()[i];
187                                                                         var due_date = item.circ.due_date();
188                                                                         due_date = due_date.substr(0,4) 
189                                                                                 + due_date.substr(5,2) + due_date.substr(8,2);
190                                                                         var today = util.date.formatted_date( new Date() , '%Y%m%d' );
191                                                                         if (today > due_date) total++;
192                                                                 }
193                                                                 e.setAttribute('value',
194                                                                         total
195                                                                 );
196                                                         };
197                                                 }
198                                         ],
199                                         'patron_holds' : [
200                                                 ['render'],
201                                                 function(e) {
202                                                         return function() { 
203                                                                 e.setAttribute('value',
204                                                                         obj.patron.hold_requests.length
205                                                                 );
206                                                         };
207                                                 }
208                                         ],
209                                         'patron_holds_available' : [
210                                                 ['render'],
211                                                 function(e) {
212                                                         return function() { 
213                                                                 var total = 0;
214                                                                 for (var i = 0; i < obj.patron.hold_requests().length; i++) {
215                                                                         var hold = obj.patron.hold_requests()[i];
216                                                                         if (hold.capture_time()) total++;
217                                                                 }
218                                                                 e.setAttribute('value',
219                                                                         total
220                                                                 );
221                                                         };
222                                                 }
223                                         ],
224                                         'patron_card' : [
225                                                 ['render'],
226                                                 function(e) {
227                                                         return function() { 
228                                                                 e.setAttribute('value',
229                                                                         obj.patron.card().barcode()
230                                                                 );
231                                                         };
232                                                 }
233                                         ],
234                                         'patron_ident_type_1' : [
235                                                 ['render'],
236                                                 function(e) {
237                                                         return function() { 
238                                                                 var ident_string = '';
239                                                                 var ident = obj.OpenILS.data.hash.cit[
240                                                                         obj.patron.ident_type()
241                                                                 ];
242                                                                 if (ident) ident_string = ident.name()
243                                                                 e.setAttribute('value',
244                                                                         ident_string
245                                                                 );
246                                                         };
247                                                 }
248                                         ],
249                                         'patron_ident_value_1' : [
250                                                 ['render'],
251                                                 function(e) {
252                                                         return function() { 
253                                                                 e.setAttribute('value',
254                                                                         obj.patron.ident_value()
255                                                                 );
256                                                         };
257                                                 }
258                                         ],
259                                         'patron_ident_type_2' : [
260                                                 ['render'],
261                                                 function(e) {
262                                                         return function() { 
263                                                                 var ident_string = '';
264                                                                 var ident = obj.OpenILS.data.hash.cit[
265                                                                         obj.patron.ident_type2()
266                                                                 ];
267                                                                 if (ident) ident_string = ident.name()
268                                                                 e.setAttribute('value',
269                                                                         ident_string
270                                                                 );
271                                                         };
272                                                 }
273                                         ],
274                                         'patron_ident_value_2' : [
275                                                 ['render'],
276                                                 function(e) {
277                                                         return function() { 
278                                                                 e.setAttribute('value',
279                                                                         obj.patron.ident_value2()
280                                                                 );
281                                                         };
282                                                 }
283                                         ],
284                                         'patron_date_of_birth' : [
285                                                 ['render'],
286                                                 function(e) {
287                                                         return function() { 
288                                                                 e.setAttribute('value',
289                                                                         obj.patron.dob()
290                                                                 );
291                                                         };
292                                                 }
293                                         ],
294                                         'patron_day_phone' : [
295                                                 ['render'],
296                                                 function(e) {
297                                                         return function() { 
298                                                                 e.setAttribute('value',
299                                                                         obj.patron.day_phone()
300                                                                 );
301                                                         };
302                                                 }
303                                         ],
304                                         'patron_evening_phone' : [
305                                                 ['render'],
306                                                 function(e) {
307                                                         return function() { 
308                                                                 e.setAttribute('value',
309                                                                         obj.patron.evening_phone()
310                                                                 );
311                                                         };
312                                                 }
313                                         ],
314                                         'patron_other_phone' : [
315                                                 ['render'],
316                                                 function(e) {
317                                                         return function() { 
318                                                                 e.setAttribute('value',
319                                                                         obj.patron.other_phone()
320                                                                 );
321                                                         };
322                                                 }
323                                         ],
324                                         'patron_email' : [
325                                                 ['render'],
326                                                 function(e) {
327                                                         return function() { 
328                                                                 e.setAttribute('value',
329                                                                         obj.patron.email()
330                                                                 );
331                                                         };
332                                                 }
333                                         ],
334                                         'patron_photo_url' : [
335                                                 ['render'],
336                                                 function(e) {
337                                                         return function() { 
338                                                                 e.setAttribute('src',
339                                                                         obj.patron.photo_url()
340                                                                 );
341                                                         };
342                                                 }
343                                         ],
344                                         'patron_library' : [
345                                                 ['render'],
346                                                 function(e) {
347                                                         return function() { 
348                                                                 e.setAttribute('value',
349                                                                         obj.OpenILS.data.hash.aou[
350                                                                                 obj.patron.home_ou()
351                                                                         ].shortname()
352                                                                 );
353                                                                 e.setAttribute('tooltiptext',
354                                                                         obj.OpenILS.data.hash.aou[
355                                                                                 obj.patron.home_ou()
356                                                                         ].name()
357                                                                 );
358                                                         };
359                                                 }
360                                         ],
361                                         'patron_last_library' : [
362                                                 ['render'],
363                                                 function(e) {
364                                                         return function() { 
365                                                                 e.setAttribute('value',
366                                                                         obj.OpenILS.data.hash.aou[
367                                                                                 obj.patron.home_ou()
368                                                                         ].shortname()
369                                                                 );
370                                                                 e.setAttribute('tooltiptext',
371                                                                         obj.OpenILS.data.hash.aou[
372                                                                                 obj.patron.home_ou()
373                                                                         ].name()
374                                                                 );
375                                                         };
376                                                 }
377                                         ],
378                                         'patron_mailing_address_street1' : [
379                                                 ['render'],
380                                                 function(e) {
381                                                         return function() { 
382                                                                 e.setAttribute('value',
383                                                                         obj.patron.mailing_address().street1()
384                                                                 );
385                                                         };
386                                                 }
387                                         ],
388                                         'patron_mailing_address_street2' : [
389                                                 ['render'],
390                                                 function(e) {
391                                                         return function() { 
392                                                                 e.setAttribute('value',
393                                                                         obj.patron.mailing_address().street2()
394                                                                 );
395                                                         };
396                                                 }
397                                         ],
398                                         'patron_mailing_address_city' : [
399                                                 ['render'],
400                                                 function(e) {
401                                                         return function() { 
402                                                                 e.setAttribute('value',
403                                                                         obj.patron.mailing_address().city()
404                                                                 );
405                                                         };
406                                                 }
407                                         ],
408                                         'patron_mailing_address_state' : [
409                                                 ['render'],
410                                                 function(e) {
411                                                         return function() { 
412                                                                 e.setAttribute('value',
413                                                                         obj.patron.mailing_address().state()
414                                                                 );
415                                                         };
416                                                 }
417                                         ],
418                                         'patron_mailing_address_post_code' : [
419                                                 ['render'],
420                                                 function(e) {
421                                                         return function() { 
422                                                                 e.setAttribute('value',
423                                                                         obj.patron.mailing_address().post_code()
424                                                                 );
425                                                         };
426                                                 }
427                                         ],
428                                         'patron_physical_address_street1' : [
429                                                 ['render'],
430                                                 function(e) {
431                                                         return function() { 
432                                                                 e.setAttribute('value',
433                                                                         obj.patron.billing_address().street1()
434                                                                 );
435                                                         };
436                                                 }
437                                         ],
438                                         'patron_physical_address_street2' : [
439                                                 ['render'],
440                                                 function(e) {
441                                                         return function() { 
442                                                                 e.setAttribute('value',
443                                                                         obj.patron.billing_address().street2()
444                                                                 );
445                                                         };
446                                                 }
447                                         ],
448                                         'patron_physical_address_city' : [
449                                                 ['render'],
450                                                 function(e) {
451                                                         return function() { 
452                                                                 e.setAttribute('value',
453                                                                         obj.patron.billing_address().city()
454                                                                 );
455                                                         };
456                                                 }
457                                         ],
458                                         'patron_physical_address_state' : [
459                                                 ['render'],
460                                                 function(e) {
461                                                         return function() { 
462                                                                 e.setAttribute('value',
463                                                                         obj.patron.billing_address().state()
464                                                                 );
465                                                         };
466                                                 }
467                                         ],
468                                         'patron_physical_address_post_code' : [
469                                                 ['render'],
470                                                 function(e) {
471                                                         return function() { 
472                                                                 e.setAttribute('value',
473                                                                         obj.patron.billing_address().post_code()
474                                                                 );
475                                                         };
476                                                 }
477                                         ]
478                                 }
479                         }
480                 );
481
482                 obj.retrieve();
483
484         },
485
486         'retrieve' : function() {
487
488                 var patron;
489                 try {
490
491                         var obj = this;
492
493                         var chain = [];
494
495                         // Retrieve the patron
496                         chain.push(
497                                 function() {
498                                         try {
499                                                 var patron = obj.network.request(
500                                                         api.fm_au_retrieve_via_barcode.app,
501                                                         api.fm_au_retrieve_via_barcode.method,
502                                                         [ obj.session, obj.barcode ]
503                                                 );
504                                                 if (patron) {
505
506                                                         if (instanceOf(patron,au)) {
507
508                                                                 obj.patron = patron;
509
510                                                         } else {
511
512                                                                 throw('patron is not an au fm object');
513                                                         }
514                                                 } else {
515
516                                                         throw('patron == false');
517                                                 }
518
519                                         } catch(E) {
520                                                 var error = ('patron.display.retrieve : ' + js2JSON(E));
521                                                 obj.error.sdump('D_ERROR',error);
522                                                 throw(error);
523                                         }
524                                 }
525                         );
526
527                         // Retrieve the bills
528                         chain.push(
529                                 function() {
530                                         try {
531                                                 var bills = obj.network.request(
532                                                         api.fm_mobts_having_balance.app,
533                                                         api.fm_mobts_having_balance.method,
534                                                         [ obj.session, obj.patron.id() ]
535                                                 );
536                                                 //FIXME// obj.patron.bills( bills );
537                                                 obj.patron.bills = bills;
538                                         } catch(E) {
539                                                 var error = ('patron.display.retrieve : ' + js2JSON(E));
540                                                 obj.error.sdump('D_ERROR',error);
541                                                 throw(error);
542                                         }
543                                 }
544                         );
545
546                         // Retrieve the checkouts
547                         chain.push(
548                                 function() {
549                                         try {
550                                                 var checkouts = obj.network.request(
551                                                         api.blob_checkouts_retrieve.app,
552                                                         api.blob_checkouts_retrieve.method,
553                                                         [ obj.session, obj.patron.id() ]
554                                                 );
555                                                 obj.patron.checkouts( checkouts );
556                                         } catch(E) {
557                                                 var error = ('patron.display.retrieve : ' + js2JSON(E));
558                                                 obj.error.sdump('D_ERROR',error);
559                                                 throw(error);
560                                         }
561                                 }
562                         );
563
564                         // Retrieve the holds
565                         chain.push(
566                                 function() {
567                                         try {
568                                                 var holds = obj.network.request(
569                                                         api.fm_ahr_retrieve.app,
570                                                         api.fm_ahr_retrieve.method,
571                                                         [ obj.session, obj.patron.id() ]
572                                                 );
573                                                 obj.patron.hold_requests( holds );
574                                         } catch(E) {
575                                                 var error = ('patron.display.retrieve : ' + js2JSON(E));
576                                                 obj.error.sdump('D_ERROR',error);
577                                                 throw(error);
578                                         }
579                                 }
580                         );
581
582                         // Update the screen
583                         chain.push( function() { obj.controller.render(); } );
584
585                         // Do it
586                         JSAN.use('util.exec'); obj.exec = new util.exec();
587                         obj.exec.on_error = function(E) {
588                                 location.href = urls.remote_patron_barcode_entry + '?session=' + window.escape(obj.session);
589                                 alert('FIXME: Need better alert and error handling.\nProblem with barcode.\n' + E);
590                         }
591                         this.exec.chain( chain );
592
593                 } catch(E) {
594                         var error = ('patron.display.retrieve : ' + js2JSON(E));
595                         this.error.sdump('D_ERROR',error);
596                         alert(error);
597                 }
598         }
599 }
600
601 dump('exiting patron/display.js\n');