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