]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/patron/summary.js
e532cd8d40316df38f5a71c0f203a19e5bc7678c
[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_MOBTS_TOTAL_HAVING_BALANCE',
132                                                                         [ ses(), obj.patron.id() ],
133                                                                         function(req) {
134                                                                                 JSAN.use('util.money');
135                                                                                 e.setAttribute('value',
136                                                                                         '$' + 
137                                                                                         util.money.sanitize( 
138                                                                                                 req.getResultObject() 
139                                                                                         )
140                                                                                 );
141                                                                         }
142                                                                 );
143                                                         };
144                                                 }
145                                         ],
146                                         'patron_checkouts' : [
147                                                 ['render'],
148                                                 function(e) {
149                                                         return function() { 
150                                                                 e.setAttribute('value','...');
151                                                                 var e2 = document.getElementById( 'patron_overdue' ); if (e2) e2.setAttribute('value','...');
152                                                                 var e3 = document.getElementById( 'patron_claimed_returned' ); if (e3) e3.setAttribute('value','...');
153                                                                 var e4 = document.getElementById( 'patron_long_overdue' ); if (e4) e4.setAttribute('value','...');
154                                                                 var e5 = document.getElementById( 'patron_lost' ); if (e5) e5.setAttribute('value','...');
155                                                                 var e6 = document.getElementById( 'patron_noncat' ); if (e6) e6.setAttribute('value','...');
156                                                                 obj.network.simple_request(
157                                                                         'FM_CIRC_COUNT_RETRIEVE_VIA_USER',
158                                                                         [ ses(), obj.patron.id() ],
159                                                                         function(req) {
160                                                                                 var robj = req.getResultObject();
161                                                                                 e.setAttribute('value', robj.out + robj.overdue + robj.claims_returned + robj.long_overdue );
162                                                                                 if (e2) e2.setAttribute('value', robj.overdue   );
163                                                                                 if (e3) e3.setAttribute('value', robj.claims_returned   );
164                                                                                 if (e4) e4.setAttribute('value', robj.long_overdue      );
165                                                                                 if (e5) e5.setAttribute('value', robj.lost      );
166                                                                         }
167                                                                 );
168                                                                 obj.network.simple_request(
169                                                                         'FM_ANCC_RETRIEVE_VIA_USER',
170                                                                         [ ses(), obj.patron.id() ],
171                                                                         function(req) {
172                                                                                 var robj = req.getResultObject();
173                                                                                 if (e6) e6.setAttribute('value',robj.length);
174                                                                         }
175                                                                 );
176                                                         };
177                                                 }
178                                         ],
179                                         'patron_overdue' : [
180                                                 ['render'],
181                                                 function(e) {
182                                                         return function() { 
183                                                                 /* handled by 'patron_checkouts' */
184                                                         };
185                                                 }
186                                         ],
187                                         'patron_holds' : [
188                                                 ['render'],
189                                                 function(e) {
190                                                         return function() { 
191                                                                 e.setAttribute('value','...');
192                                                                 var e2 = document.getElementById('patron_holds_available');
193                                                                 if (e2) e2.setAttribute('value','...');
194                                                                 obj.network.simple_request(
195                                                                         'FM_AHR_COUNT_RETRIEVE',
196                                                                         [ ses(), obj.patron.id() ],
197                                                                         function(req) {
198                                                                                 e.setAttribute('value',
199                                                                                         req.getResultObject().total
200                                                                                 );
201                                                                                 if (e2) e2.setAttribute('value',
202                                                                                         req.getResultObject().ready
203                                                                                 );
204                                                                         }
205                                                                 );
206                                                         };
207                                                 }
208                                         ],
209                                         'patron_holds_available' : [
210                                                 ['render'],
211                                                 function(e) {
212                                                         return function() { 
213                                                                 /* handled by 'patron_holds' */
214                                                         };
215                                                 }
216                                         ],
217                                         'patron_card' : [
218                                                 ['render'],
219                                                 function(e) {
220                                                         return function() { 
221                                                                 e.setAttribute('value',
222                                                                         obj.patron.card().barcode()
223                                                                 );
224                                                         };
225                                                 }
226                                         ],
227                                         'patron_ident_type_1' : [
228                                                 ['render'],
229                                                 function(e) {
230                                                         return function() { 
231                                                                 var ident_string = '';
232                                                                 var ident = obj.OpenILS.data.hash.cit[
233                                                                         obj.patron.ident_type()
234                                                                 ];
235                                                                 if (ident) ident_string = ident.name()
236                                                                 e.setAttribute('value',
237                                                                         ident_string
238                                                                 );
239                                                         };
240                                                 }
241                                         ],
242                                         'patron_ident_value_1' : [
243                                                 ['render'],
244                                                 function(e) {
245                                                         return function() { 
246                                                                 e.setAttribute('value',
247                                                                         obj.patron.ident_value()
248                                                                 );
249                                                         };
250                                                 }
251                                         ],
252                                         'patron_ident_type_2' : [
253                                                 ['render'],
254                                                 function(e) {
255                                                         return function() { 
256                                                                 var ident_string = '';
257                                                                 var ident = obj.OpenILS.data.hash.cit[
258                                                                         obj.patron.ident_type2()
259                                                                 ];
260                                                                 if (ident) ident_string = ident.name()
261                                                                 e.setAttribute('value',
262                                                                         ident_string
263                                                                 );
264                                                         };
265                                                 }
266                                         ],
267                                         'patron_ident_value_2' : [
268                                                 ['render'],
269                                                 function(e) {
270                                                         return function() { 
271                                                                 e.setAttribute('value',
272                                                                         obj.patron.ident_value2()
273                                                                 );
274                                                         };
275                                                 }
276                                         ],
277                                         'patron_date_of_birth' : [
278                                                 ['render'],
279                                                 function(e) {
280                                                         return function() { 
281                                                                 e.setAttribute('value',
282                                                                         obj.patron.dob() ?
283                                                                         obj.patron.dob().substr(0,10) :
284                                                                         '<Unset>'
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                                                                 if (!get_bool(obj.patron.mailing_address().valid())){e.setAttribute('style','color: red');}
381                                                         };
382                                                 }
383                                         ],
384                                         'patron_mailing_address_street2' : [
385                                                 ['render'],
386                                                 function(e) {
387                                                         return function() { 
388                                                                 e.setAttribute('value',
389                                                                         obj.patron.mailing_address().street2()
390                                                                 );
391                                                                 if (!get_bool(obj.patron.mailing_address().valid())){e.setAttribute('style','color: red');}
392                                                         };
393                                                 }
394                                         ],
395                                         'patron_mailing_address_city' : [
396                                                 ['render'],
397                                                 function(e) {
398                                                         return function() { 
399                                                                 e.setAttribute('value',
400                                                                         obj.patron.mailing_address().city()
401                                                                 );
402                                                                 if (!get_bool(obj.patron.mailing_address().valid())){e.setAttribute('style','color: red');}
403                                                         };
404                                                 }
405                                         ],
406                                         'patron_mailing_address_state' : [
407                                                 ['render'],
408                                                 function(e) {
409                                                         return function() { 
410                                                                 e.setAttribute('value',
411                                                                         obj.patron.mailing_address().state()
412                                                                 );
413                                                                 if (!get_bool(obj.patron.mailing_address().valid())){e.setAttribute('style','color: red');}
414                                                         };
415                                                 }
416                                         ],
417                                         'patron_mailing_address_post_code' : [
418                                                 ['render'],
419                                                 function(e) {
420                                                         return function() { 
421                                                                 e.setAttribute('value',
422                                                                         obj.patron.mailing_address().post_code()
423                                                                 );
424                                                                 if (!get_bool(obj.patron.mailing_address().valid())){e.setAttribute('style','color: red');}
425                                                         };
426                                                 }
427                                         ],
428                                         'patron_physical_address_street1' : [
429                                                 ['render'],
430                                                 function(e) {
431                                                         return function() { 
432                                                                 e.setAttribute('value',
433                                                                         obj.patron.billing_address().street1()
434                                                                 );
435                                                                 if (!get_bool(obj.patron.billing_address().valid())){e.setAttribute('style','color: red');}
436                                                         };
437                                                 }
438                                         ],
439                                         'patron_physical_address_street2' : [
440                                                 ['render'],
441                                                 function(e) {
442                                                         return function() { 
443                                                                 e.setAttribute('value',
444                                                                         obj.patron.billing_address().street2()
445                                                                 );
446                                                                 if (!get_bool(obj.patron.billing_address().valid())){e.setAttribute('style','color: red');}
447                                                         };
448                                                 }
449                                         ],
450                                         'patron_physical_address_city' : [
451                                                 ['render'],
452                                                 function(e) {
453                                                         return function() { 
454                                                                 e.setAttribute('value',
455                                                                         obj.patron.billing_address().city()
456                                                                 );
457                                                                 if (!get_bool(obj.patron.billing_address().valid())){e.setAttribute('style','color: red');}
458                                                         };
459                                                 }
460                                         ],
461                                         'patron_physical_address_state' : [
462                                                 ['render'],
463                                                 function(e) {
464                                                         return function() { 
465                                                                 e.setAttribute('value',
466                                                                         obj.patron.billing_address().state()
467                                                                 );
468                                                                 if (!get_bool(obj.patron.billing_address().valid())){e.setAttribute('style','color: red');}
469                                                         };
470                                                 }
471                                         ],
472                                         'patron_physical_address_post_code' : [
473                                                 ['render'],
474                                                 function(e) {
475                                                         return function() { 
476                                                                 e.setAttribute('value',
477                                                                         obj.patron.billing_address().post_code()
478                                                                 );
479                                                                 if (!get_bool(obj.patron.billing_address().valid())){e.setAttribute('style','color: red');}
480                                                         };
481                                                 }
482                                         ]
483                                 }
484                         }
485                 );
486
487                 obj.retrieve();
488
489                 try {
490                         var caption = document.getElementById("PatronSummaryContact_caption");
491                         var arrow = document.getAnonymousNodes(caption)[0];
492                         var gb_content = document.getAnonymousNodes(caption.parentNode)[1];
493                         arrow.addEventListener(
494                                 'click',
495                                 function() {
496                                         setTimeout(
497                                                 function() {
498                                                         //alert('setting shrink_state to ' + gb_content.hidden);
499                                                         //caption.setAttribute('shrink_state',gb_content.hidden);
500                                                         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
501                                                         JSAN.use('util.file'); var file = new util.file('patron_id_shrink');
502                                                         file.set_object(String(gb_content.hidden)); file.close();
503                                                 }, 0
504                                         );
505                                 }, false
506                         );
507                         //var shrink_state = caption.getAttribute('shrink_state');
508                         var shrink_state = false;
509                         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
510                         JSAN.use('util.file'); var file = new util.file('patron_id_shrink');
511                         if (file._file.exists()) {
512                                 shrink_state = file.get_object(); file.close();
513                         }
514                         //alert('shrink_state retrieved as ' + shrink_state);
515                         if (shrink_state != 'false' && shrink_state) {
516                                 JSAN.use('util.widgets');
517                                 //alert('clicking the widget');
518                                 util.widgets.click( arrow );
519                         }
520                 } catch(E) {
521                         obj.error.sdump('D_ERROR','with shrink_state in summary.js: ' + E);
522                 }
523         },
524
525         'retrieve' : function() {
526
527                 try {
528
529                         var obj = this;
530
531                         var chain = [];
532
533                         // Retrieve the patron
534                                 function blah_retrieve() {
535                                         try {
536                                                 var robj;
537                                                 if (obj.barcode && obj.barcode != 'null') {
538                                                         robj = obj.network.request(
539                                                                 api.FM_AU_RETRIEVE_VIA_BARCODE.app,
540                                                                 api.FM_AU_RETRIEVE_VIA_BARCODE.method,
541                                                                 [ ses(), obj.barcode ]
542                                                         );
543                                                 } else if (obj.id && obj.id != 'null') {
544                                                         robj = obj.network.simple_request(
545                                                                 'FM_AU_FLESHED_RETRIEVE_VIA_ID',
546                                                                 [ ses(), obj.id ]
547                                                         );
548                                                 } else {
549                                                         throw('summary: No barcode or id');
550                                                 }
551                                                 if (robj) {
552
553                                                         if (instanceOf(robj,au)) {
554
555                                                                 obj.patron = robj;
556                                                                 JSAN.use('patron.util');
557                                                                 document.getElementById('patron_name').setAttribute('value',
558                                                                         obj.patron.family_name() + ', ' + obj.patron.first_given_name() + ' ' +
559                                                                         ( obj.patron.second_given_name() ? obj.patron.second_given_name() : '' )
560                                                                 );
561                                                                 patron.util.set_penalty_css(obj.patron);
562                                                                 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
563                                                                 data.last_patron = obj.patron.id(); data.stash('last_patron');
564
565                                                         } else {
566
567                                                                 throw(robj);
568
569                                                         }
570                                                 } else {
571
572                                                         throw(robj);
573
574                                                 }
575
576                                         } catch(E) {
577                                                 throw(E);
578                                         }
579                                 };
580                                 blah_retrieve();
581
582                         /*
583                         // Retrieve the survey responses for required surveys
584                         chain.push(
585                                 function() {
586                                         try {
587                                                 var surveys = obj.OpenILS.data.list.my_asv;
588                                                 var survey_responses = {};
589                                                 for (var i = 0; i < surveys.length; i++) {
590                                                         var s = obj.network.request(
591                                                                 api.FM_ASVR_RETRIEVE.app,
592                                                                 api.FM_ASVR_RETRIEVE.method,
593                                                                 [ ses(), surveys[i].id(), obj.patron.id() ]
594                                                         );
595                                                         survey_responses[ surveys[i].id() ] = s;
596                                                 }
597                                                 obj.patron.survey_responses( survey_responses );
598                                         } catch(E) {
599                                                 var error = ('patron.summary.retrieve : ' + js2JSON(E));
600                                                 obj.error.sdump('D_ERROR',error);
601                                                 throw(error);
602                                         }
603                                 }
604                         );
605                         */
606
607                         // Update the screen
608                         chain.push( function() { obj.controller.render(); } );
609
610                         // On Complete
611
612                         chain.push( function() {
613
614                                 if (typeof window.xulG == 'object' && typeof window.xulG.on_finished == 'function') {
615                                         obj.error.sdump('D_PATRON_SUMMARY',
616                                                 'patron.summary: Calling external .on_finished()\n');
617                                         window.xulG.on_finished(obj.patron);
618                                 } else {
619                                         obj.error.sdump('D_PATRON_SUMMARY','patron.summary: No external .on_finished()\n');
620                                 }
621
622                         } );
623
624                         // Do it
625                         JSAN.use('util.exec'); obj.exec = new util.exec();
626                         obj.exec.on_error = function(E) {
627
628                                 if (typeof window.xulG == 'object' && typeof window.xulG.on_error == 'function') {
629                                         window.xulG.on_error(E);
630                                 } else {
631                                         alert(js2JSON(E));
632                                 }
633
634                         }
635                         this.exec.chain( chain );
636
637                 } catch(E) {
638                         if (typeof window.xulG == 'object' && typeof window.xulG.on_error == 'function') {
639                                 window.xulG.on_error(E);
640                         } else {
641                                 alert(js2JSON(E));
642                         }
643                 }
644         }
645 }
646
647 dump('exiting patron.summary.js\n');