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