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