]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/patron/summary.js
02010192ab82b5ad4ce346b0b61486891bb07cda
[Evergreen.git] / Open-ILS / xul / staff_client / server / patron / summary.js
1 dump('entering patron.summary.js\n');
2
3 if (typeof patron == 'undefined') patron = {};
4 patron.summary = function (params) {
5
6         JSAN.use('util.error'); this.error = new util.error();
7         JSAN.use('util.window'); this.window = new util.window();
8         JSAN.use('util.network'); this.network = new util.network();
9         this.w = window;
10 }
11
12 patron.summary.prototype = {
13
14         'init' : function( params ) {
15
16                 var obj = this;
17
18                 obj.barcode = params['barcode'];
19                 obj.id = params['id'];
20                 if (params['show_name']) {
21                         document.getElementById('patron_name').hidden = false;
22                         document.getElementById('patron_name').setAttribute('hidden','false');
23                 }
24
25                 JSAN.use('OpenILS.data'); this.OpenILS = {}; 
26                 obj.OpenILS.data = new OpenILS.data(); obj.OpenILS.data.init({'via':'stash'});
27
28                 JSAN.use('util.controller'); obj.controller = new util.controller();
29                 obj.controller.init(
30                         {
31                                 control_map : {
32                                         'cmd_broken' : [
33                                                 ['command'],
34                                                 function() { alert('Not Yet Implemented'); }
35                                         ],
36                                         'patron_alert' : [
37                                                 ['render'],
38                                                 function(e) {
39                                                         return function() {
40                                                                 JSAN.use('util.widgets');
41                                                                 util.widgets.remove_children( e );
42                                                                 if (obj.patron.alert_message()) {
43                                                                         e.appendChild(
44                                                                                 document.createTextNode(
45                                                                                         obj.patron.alert_message()
46                                                                                 )
47                                                                         );
48                                                                         e.parentNode.hidden = false;
49                                                                 } else {
50                                                                         e.parentNode.hidden = true;
51                                                                 }
52                                                         };
53                                                 }
54                                         ],
55                                         'patron_usrname' : [
56                                                 ['render'],
57                                                 function(e) {
58                                                         return function() {
59                                                                 e.setAttribute('value',obj.patron.usrname());
60                                                         };
61                                                 }
62                                         ],
63                                         'patron_profile' : [
64                                                 ['render'],
65                                                 function(e) {
66                                                         return function() { 
67                                                                 e.setAttribute('value',
68                                                                         obj.OpenILS.data.hash.pgt[
69                                                                                 obj.patron.profile()
70                                                                         ].name()
71                                                                 );
72                                                         };
73                                                 }
74                                         ],
75                                         'patron_net_access' : [
76                                                 ['render'],
77                                                 function(e) {
78                                                         return function() { 
79                                                                 e.setAttribute('value',
80                                                                         'Internet: ' + 
81                                                                         obj.OpenILS.data.hash.cnal[
82                                                                                 obj.patron.net_access_level()
83                                                                         ].name()
84                                                                 );
85                                                         };
86                                                 }
87                                         ],
88                                         'patron_standing' : [
89                                                 ['render'],
90                                                 function(e) {
91                                                         return function() {
92                                                         /*
93                                                                 e.setAttribute('value',
94                                                                         obj.OpenILS.data.hash.cst[
95                                                                                 obj.patron.standing()
96                                                                         ].value()
97                                                                 );
98                                                         */
99                                                                 var e2 = document.getElementById('patron_standing_penalties');
100                                                                 JSAN.use('util.widgets');
101                                                                 util.widgets.remove_children(e2);
102                                                                 var penalties = obj.patron.standing_penalties();
103                                                                 for (var i = 0; i < penalties.length; i++) {
104                                                                         var x = document.createElement('label');
105                                                                         x.setAttribute('value',penalties[i].penalty_type());
106                                                                         e2.appendChild(x);
107                                                                 }
108                                                         };
109                                                 }
110                                         ],
111                                         'patron_credit' : [
112                                                 ['render'],
113                                                 function(e) {
114                                                         return function() { 
115                                                                 JSAN.use('util.money');
116                                                                 e.setAttribute('value',
117                                                                         '$' + 
118                                                                         util.money.sanitize(
119                                                                                 obj.patron.credit_forward_balance()
120                                                                         )
121                                                                 );
122                                                         };
123                                                 }
124                                         ],
125                                         'patron_bill' : [
126                                                 ['render'],
127                                                 function(e) {
128                                                         return function() { 
129                                                                 e.setAttribute('value','...');
130                                                                 obj.network.simple_request(
131                                                                         'FM_MBTS_IDS_RETRIEVE_ALL_HAVING_BALANCE',
132                                                                         [ ses(), obj.patron.id() ],
133                                                                         function(req) {
134                                                                                 var list = req.getResultObject();
135                                                                                 if (typeof list.ilsevent != 'undefined') {
136                                                                                         e.setAttribute('value', '??? See Bills');
137                                                                                         return;
138                                                                                 }
139                                                                                 var sum = 0;
140                                                                                 for (var i = 0; i < list.length; i++) {
141                                                                                         var robj = obj.network.simple_request('FM_MBTS_RETRIEVE',[ses(),list[i]]);
142                                                                                         sum += robj.balance_owed();
143                                                                                 }
144                                                                                 JSAN.use('util.money');
145                                                                                 e.setAttribute('value', '$' + util.money.sanitize( sum ));
146                                                                         }
147                                                                 );
148                                                         };
149                                                 }
150                                         ],
151                                         'patron_checkouts' : [
152                                                 ['render'],
153                                                 function(e) {
154                                                         return function() { 
155                                                                 e.setAttribute('value','...');
156                                                                 var e2 = document.getElementById( 'patron_overdue' ); if (e2) e2.setAttribute('value','...');
157                                                                 var e3 = document.getElementById( 'patron_claimed_returned' ); if (e3) e3.setAttribute('value','...');
158                                                                 var e4 = document.getElementById( 'patron_long_overdue' ); if (e4) e4.setAttribute('value','...');
159                                                                 var e5 = document.getElementById( 'patron_lost' ); if (e5) e5.setAttribute('value','...');
160                                                                 var e6 = document.getElementById( 'patron_noncat' ); if (e6) e6.setAttribute('value','...');
161                                                                 obj.network.simple_request(
162                                                                         'FM_CIRC_COUNT_RETRIEVE_VIA_USER',
163                                                                         [ ses(), obj.patron.id() ],
164                                                                         function(req) {
165                                                                                 var robj = req.getResultObject();
166                                                                                 e.setAttribute('value', robj.out + robj.overdue + robj.claims_returned + robj.long_overdue );
167                                                                                 if (e2) e2.setAttribute('value', robj.overdue   );
168                                                                                 if (e3) e3.setAttribute('value', robj.claims_returned   );
169                                                                                 if (e4) e4.setAttribute('value', robj.long_overdue      );
170                                                                                 if (e5) e5.setAttribute('value', robj.lost      );
171                                                                         }
172                                                                 );
173                                                                 obj.network.simple_request(
174                                                                         'FM_ANCC_RETRIEVE_VIA_USER',
175                                                                         [ ses(), obj.patron.id() ],
176                                                                         function(req) {
177                                                                                 var robj = req.getResultObject();
178                                                                                 if (e6) e6.setAttribute('value',robj.length);
179                                                                         }
180                                                                 );
181                                                         };
182                                                 }
183                                         ],
184                                         'patron_overdue' : [
185                                                 ['render'],
186                                                 function(e) {
187                                                         return function() { 
188                                                                 /* handled by 'patron_checkouts' */
189                                                         };
190                                                 }
191                                         ],
192                                         'patron_holds' : [
193                                                 ['render'],
194                                                 function(e) {
195                                                         return function() { 
196                                                                 e.setAttribute('value','...');
197                                                                 var e2 = document.getElementById('patron_holds_available');
198                                                                 if (e2) e2.setAttribute('value','...');
199                                                                 obj.network.simple_request(
200                                                                         'FM_AHR_COUNT_RETRIEVE',
201                                                                         [ ses(), obj.patron.id() ],
202                                                                         function(req) {
203                                                                                 e.setAttribute('value',
204                                                                                         req.getResultObject().total
205                                                                                 );
206                                                                                 if (e2) e2.setAttribute('value',
207                                                                                         req.getResultObject().ready
208                                                                                 );
209                                                                         }
210                                                                 );
211                                                         };
212                                                 }
213                                         ],
214                                         'patron_holds_available' : [
215                                                 ['render'],
216                                                 function(e) {
217                                                         return function() { 
218                                                                 /* handled by 'patron_holds' */
219                                                         };
220                                                 }
221                                         ],
222                                         'patron_card' : [
223                                                 ['render'],
224                                                 function(e) {
225                                                         return function() { 
226                                                                 e.setAttribute('value',
227                                                                         obj.patron.card().barcode()
228                                                                 );
229                                                         };
230                                                 }
231                                         ],
232                                         'patron_ident_type_1' : [
233                                                 ['render'],
234                                                 function(e) {
235                                                         return function() { 
236                                                                 var ident_string = '';
237                                                                 var ident = obj.OpenILS.data.hash.cit[
238                                                                         obj.patron.ident_type()
239                                                                 ];
240                                                                 if (ident) ident_string = ident.name()
241                                                                 e.setAttribute('value',
242                                                                         ident_string
243                                                                 );
244                                                         };
245                                                 }
246                                         ],
247                                         'patron_ident_value_1' : [
248                                                 ['render'],
249                                                 function(e) {
250                                                         return function() { 
251                                                                 e.setAttribute('value',
252                                                                         obj.patron.ident_value()
253                                                                 );
254                                                         };
255                                                 }
256                                         ],
257                                         'patron_ident_type_2' : [
258                                                 ['render'],
259                                                 function(e) {
260                                                         return function() { 
261                                                                 var ident_string = '';
262                                                                 var ident = obj.OpenILS.data.hash.cit[
263                                                                         obj.patron.ident_type2()
264                                                                 ];
265                                                                 if (ident) ident_string = ident.name()
266                                                                 e.setAttribute('value',
267                                                                         ident_string
268                                                                 );
269                                                         };
270                                                 }
271                                         ],
272                                         'patron_ident_value_2' : [
273                                                 ['render'],
274                                                 function(e) {
275                                                         return function() { 
276                                                                 e.setAttribute('value',
277                                                                         obj.patron.ident_value2()
278                                                                 );
279                                                         };
280                                                 }
281                                         ],
282                                         'patron_date_of_birth' : [
283                                                 ['render'],
284                                                 function(e) {
285                                                         return function() { 
286                                                                 e.setAttribute('value',
287                                                                         obj.patron.dob() ?
288                                                                         obj.patron.dob().substr(0,10) :
289                                                                         '<Unset>'
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                                                                 if (!get_bool(obj.patron.mailing_address().valid())){e.setAttribute('style','color: red');}
386                                                         };
387                                                 }
388                                         ],
389                                         'patron_mailing_address_street2' : [
390                                                 ['render'],
391                                                 function(e) {
392                                                         return function() { 
393                                                                 e.setAttribute('value',
394                                                                         obj.patron.mailing_address().street2()
395                                                                 );
396                                                                 if (!get_bool(obj.patron.mailing_address().valid())){e.setAttribute('style','color: red');}
397                                                         };
398                                                 }
399                                         ],
400                                         'patron_mailing_address_city' : [
401                                                 ['render'],
402                                                 function(e) {
403                                                         return function() { 
404                                                                 e.setAttribute('value',
405                                                                         obj.patron.mailing_address().city()
406                                                                 );
407                                                                 if (!get_bool(obj.patron.mailing_address().valid())){e.setAttribute('style','color: red');}
408                                                         };
409                                                 }
410                                         ],
411                                         'patron_mailing_address_state' : [
412                                                 ['render'],
413                                                 function(e) {
414                                                         return function() { 
415                                                                 e.setAttribute('value',
416                                                                         obj.patron.mailing_address().state()
417                                                                 );
418                                                                 if (!get_bool(obj.patron.mailing_address().valid())){e.setAttribute('style','color: red');}
419                                                         };
420                                                 }
421                                         ],
422                                         'patron_mailing_address_post_code' : [
423                                                 ['render'],
424                                                 function(e) {
425                                                         return function() { 
426                                                                 e.setAttribute('value',
427                                                                         obj.patron.mailing_address().post_code()
428                                                                 );
429                                                                 if (!get_bool(obj.patron.mailing_address().valid())){e.setAttribute('style','color: red');}
430                                                         };
431                                                 }
432                                         ],
433                                         'patron_physical_address_street1' : [
434                                                 ['render'],
435                                                 function(e) {
436                                                         return function() { 
437                                                                 e.setAttribute('value',
438                                                                         obj.patron.billing_address().street1()
439                                                                 );
440                                                                 if (!get_bool(obj.patron.billing_address().valid())){e.setAttribute('style','color: red');}
441                                                         };
442                                                 }
443                                         ],
444                                         'patron_physical_address_street2' : [
445                                                 ['render'],
446                                                 function(e) {
447                                                         return function() { 
448                                                                 e.setAttribute('value',
449                                                                         obj.patron.billing_address().street2()
450                                                                 );
451                                                                 if (!get_bool(obj.patron.billing_address().valid())){e.setAttribute('style','color: red');}
452                                                         };
453                                                 }
454                                         ],
455                                         'patron_physical_address_city' : [
456                                                 ['render'],
457                                                 function(e) {
458                                                         return function() { 
459                                                                 e.setAttribute('value',
460                                                                         obj.patron.billing_address().city()
461                                                                 );
462                                                                 if (!get_bool(obj.patron.billing_address().valid())){e.setAttribute('style','color: red');}
463                                                         };
464                                                 }
465                                         ],
466                                         'patron_physical_address_state' : [
467                                                 ['render'],
468                                                 function(e) {
469                                                         return function() { 
470                                                                 e.setAttribute('value',
471                                                                         obj.patron.billing_address().state()
472                                                                 );
473                                                                 if (!get_bool(obj.patron.billing_address().valid())){e.setAttribute('style','color: red');}
474                                                         };
475                                                 }
476                                         ],
477                                         'patron_physical_address_post_code' : [
478                                                 ['render'],
479                                                 function(e) {
480                                                         return function() { 
481                                                                 e.setAttribute('value',
482                                                                         obj.patron.billing_address().post_code()
483                                                                 );
484                                                                 if (!get_bool(obj.patron.billing_address().valid())){e.setAttribute('style','color: red');}
485                                                         };
486                                                 }
487                                         ]
488                                 }
489                         }
490                 );
491
492                 obj.retrieve();
493
494                 try {
495                         var caption = document.getElementById("PatronSummaryContact_caption");
496                         var arrow = document.getAnonymousNodes(caption)[0];
497                         var gb_content = document.getAnonymousNodes(caption.parentNode)[1];
498                         arrow.addEventListener(
499                                 'click',
500                                 function() {
501                                         setTimeout(
502                                                 function() {
503                                                         //alert('setting shrink_state to ' + gb_content.hidden);
504                                                         //caption.setAttribute('shrink_state',gb_content.hidden);
505                                                         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
506                                                         JSAN.use('util.file'); var file = new util.file('patron_id_shrink');
507                                                         file.set_object(String(gb_content.hidden)); file.close();
508                                                 }, 0
509                                         );
510                                 }, false
511                         );
512                         //var shrink_state = caption.getAttribute('shrink_state');
513                         var shrink_state = false;
514                         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
515                         JSAN.use('util.file'); var file = new util.file('patron_id_shrink');
516                         if (file._file.exists()) {
517                                 shrink_state = file.get_object(); file.close();
518                         }
519                         //alert('shrink_state retrieved as ' + shrink_state);
520                         if (shrink_state != 'false' && shrink_state) {
521                                 JSAN.use('util.widgets');
522                                 //alert('clicking the widget');
523                                 util.widgets.click( arrow );
524                         }
525                 } catch(E) {
526                         obj.error.sdump('D_ERROR','with shrink_state in summary.js: ' + E);
527                 }
528         },
529
530         'retrieve' : function() {
531
532                 try {
533
534                         var obj = this;
535
536                         var chain = [];
537
538                         // Retrieve the patron
539                                 function blah_retrieve() {
540                                         try {
541                                                 var robj;
542                                                 if (obj.barcode && obj.barcode != 'null') {
543                                                         robj = obj.network.request(
544                                                                 api.FM_AU_RETRIEVE_VIA_BARCODE.app,
545                                                                 api.FM_AU_RETRIEVE_VIA_BARCODE.method,
546                                                                 [ ses(), obj.barcode ]
547                                                         );
548                                                 } else if (obj.id && obj.id != 'null') {
549                                                         robj = obj.network.simple_request(
550                                                                 'FM_AU_FLESHED_RETRIEVE_VIA_ID',
551                                                                 [ ses(), obj.id ]
552                                                         );
553                                                 } else {
554                                                         throw('summary: No barcode or id');
555                                                 }
556                                                 if (robj) {
557
558                                                         if (instanceOf(robj,au)) {
559
560                                                                 obj.patron = robj;
561                                                                 JSAN.use('patron.util');
562                                                                 document.getElementById('patron_name').setAttribute('value',
563                                                                         obj.patron.family_name() + ', ' + obj.patron.first_given_name() + ' ' +
564                                                                         ( obj.patron.second_given_name() ? obj.patron.second_given_name() : '' )
565                                                                 );
566                                                                 patron.util.set_penalty_css(obj.patron);
567                                                                 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
568                                                                 data.last_patron = obj.patron.id(); data.stash('last_patron');
569
570                                                         } else {
571
572                                                                 throw(robj);
573
574                                                         }
575                                                 } else {
576
577                                                         throw(robj);
578
579                                                 }
580
581                                         } catch(E) {
582                                                 throw(E);
583                                         }
584                                 };
585                                 blah_retrieve();
586
587                         /*
588                         // Retrieve the survey responses for required surveys
589                         chain.push(
590                                 function() {
591                                         try {
592                                                 var surveys = obj.OpenILS.data.list.my_asv;
593                                                 var survey_responses = {};
594                                                 for (var i = 0; i < surveys.length; i++) {
595                                                         var s = obj.network.request(
596                                                                 api.FM_ASVR_RETRIEVE.app,
597                                                                 api.FM_ASVR_RETRIEVE.method,
598                                                                 [ ses(), surveys[i].id(), obj.patron.id() ]
599                                                         );
600                                                         survey_responses[ surveys[i].id() ] = s;
601                                                 }
602                                                 obj.patron.survey_responses( survey_responses );
603                                         } catch(E) {
604                                                 var error = ('patron.summary.retrieve : ' + js2JSON(E));
605                                                 obj.error.sdump('D_ERROR',error);
606                                                 throw(error);
607                                         }
608                                 }
609                         );
610                         */
611
612                         // Update the screen
613                         chain.push( function() { obj.controller.render(); } );
614
615                         // On Complete
616
617                         chain.push( function() {
618
619                                 if (typeof window.xulG == 'object' && typeof window.xulG.on_finished == 'function') {
620                                         obj.error.sdump('D_PATRON_SUMMARY',
621                                                 'patron.summary: Calling external .on_finished()\n');
622                                         window.xulG.on_finished(obj.patron);
623                                 } else {
624                                         obj.error.sdump('D_PATRON_SUMMARY','patron.summary: No external .on_finished()\n');
625                                 }
626
627                         } );
628
629                         // Do it
630                         JSAN.use('util.exec'); obj.exec = new util.exec();
631                         obj.exec.on_error = function(E) {
632
633                                 if (typeof window.xulG == 'object' && typeof window.xulG.on_error == 'function') {
634                                         window.xulG.on_error(E);
635                                 } else {
636                                         alert(js2JSON(E));
637                                 }
638
639                         }
640                         this.exec.chain( chain );
641
642                 } catch(E) {
643                         if (typeof window.xulG == 'object' && typeof window.xulG.on_error == 'function') {
644                                 window.xulG.on_error(E);
645                         } else {
646                                 alert(js2JSON(E));
647                         }
648                 }
649         }
650 }
651
652 dump('exiting patron.summary.js\n');