]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/patron/summary.js
non cat count in summary
[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                                                         };
381                                                 }
382                                         ],
383                                         'patron_mailing_address_street2' : [
384                                                 ['render'],
385                                                 function(e) {
386                                                         return function() { 
387                                                                 e.setAttribute('value',
388                                                                         obj.patron.mailing_address().street2()
389                                                                 );
390                                                         };
391                                                 }
392                                         ],
393                                         'patron_mailing_address_city' : [
394                                                 ['render'],
395                                                 function(e) {
396                                                         return function() { 
397                                                                 e.setAttribute('value',
398                                                                         obj.patron.mailing_address().city()
399                                                                 );
400                                                         };
401                                                 }
402                                         ],
403                                         'patron_mailing_address_state' : [
404                                                 ['render'],
405                                                 function(e) {
406                                                         return function() { 
407                                                                 e.setAttribute('value',
408                                                                         obj.patron.mailing_address().state()
409                                                                 );
410                                                         };
411                                                 }
412                                         ],
413                                         'patron_mailing_address_post_code' : [
414                                                 ['render'],
415                                                 function(e) {
416                                                         return function() { 
417                                                                 e.setAttribute('value',
418                                                                         obj.patron.mailing_address().post_code()
419                                                                 );
420                                                         };
421                                                 }
422                                         ],
423                                         'patron_physical_address_street1' : [
424                                                 ['render'],
425                                                 function(e) {
426                                                         return function() { 
427                                                                 e.setAttribute('value',
428                                                                         obj.patron.billing_address().street1()
429                                                                 );
430                                                         };
431                                                 }
432                                         ],
433                                         'patron_physical_address_street2' : [
434                                                 ['render'],
435                                                 function(e) {
436                                                         return function() { 
437                                                                 e.setAttribute('value',
438                                                                         obj.patron.billing_address().street2()
439                                                                 );
440                                                         };
441                                                 }
442                                         ],
443                                         'patron_physical_address_city' : [
444                                                 ['render'],
445                                                 function(e) {
446                                                         return function() { 
447                                                                 e.setAttribute('value',
448                                                                         obj.patron.billing_address().city()
449                                                                 );
450                                                         };
451                                                 }
452                                         ],
453                                         'patron_physical_address_state' : [
454                                                 ['render'],
455                                                 function(e) {
456                                                         return function() { 
457                                                                 e.setAttribute('value',
458                                                                         obj.patron.billing_address().state()
459                                                                 );
460                                                         };
461                                                 }
462                                         ],
463                                         'patron_physical_address_post_code' : [
464                                                 ['render'],
465                                                 function(e) {
466                                                         return function() { 
467                                                                 e.setAttribute('value',
468                                                                         obj.patron.billing_address().post_code()
469                                                                 );
470                                                         };
471                                                 }
472                                         ]
473                                 }
474                         }
475                 );
476
477                 obj.retrieve();
478
479         },
480
481         'retrieve' : function() {
482
483                 try {
484
485                         var obj = this;
486
487                         var chain = [];
488
489                         // Retrieve the patron
490                                 function blah_retrieve() {
491                                         try {
492                                                 var robj;
493                                                 if (obj.barcode && obj.barcode != 'null') {
494                                                         robj = obj.network.request(
495                                                                 api.FM_AU_RETRIEVE_VIA_BARCODE.app,
496                                                                 api.FM_AU_RETRIEVE_VIA_BARCODE.method,
497                                                                 [ ses(), obj.barcode ]
498                                                         );
499                                                 } else if (obj.id && obj.id != 'null') {
500                                                         robj = obj.network.simple_request(
501                                                                 'FM_AU_FLESHED_RETRIEVE_VIA_ID',
502                                                                 [ ses(), obj.id ]
503                                                         );
504                                                 } else {
505                                                         throw('summary: No barcode or id');
506                                                 }
507                                                 if (robj) {
508
509                                                         if (instanceOf(robj,au)) {
510
511                                                                 obj.patron = robj;
512                                                                 JSAN.use('patron.util');
513                                                                 document.getElementById('patron_name').setAttribute('value',
514                                                                         obj.patron.family_name() + ', ' + obj.patron.first_given_name() + ' ' +
515                                                                         ( obj.patron.second_given_name() ? obj.patron.second_given_name() : '' )
516                                                                 );
517                                                                 patron.util.set_penalty_css(obj.patron);
518
519                                                         } else {
520
521                                                                 throw(robj);
522
523                                                         }
524                                                 } else {
525
526                                                         throw(robj);
527
528                                                 }
529
530                                         } catch(E) {
531                                                 throw(E);
532                                         }
533                                 };
534                                 blah_retrieve();
535
536                         /*
537                         // Retrieve the survey responses for required surveys
538                         chain.push(
539                                 function() {
540                                         try {
541                                                 var surveys = obj.OpenILS.data.list.my_asv;
542                                                 var survey_responses = {};
543                                                 for (var i = 0; i < surveys.length; i++) {
544                                                         var s = obj.network.request(
545                                                                 api.FM_ASVR_RETRIEVE.app,
546                                                                 api.FM_ASVR_RETRIEVE.method,
547                                                                 [ ses(), surveys[i].id(), obj.patron.id() ]
548                                                         );
549                                                         survey_responses[ surveys[i].id() ] = s;
550                                                 }
551                                                 obj.patron.survey_responses( survey_responses );
552                                         } catch(E) {
553                                                 var error = ('patron.summary.retrieve : ' + js2JSON(E));
554                                                 obj.error.sdump('D_ERROR',error);
555                                                 throw(error);
556                                         }
557                                 }
558                         );
559                         */
560
561                         // Update the screen
562                         chain.push( function() { obj.controller.render(); } );
563
564                         // On Complete
565
566                         chain.push( function() {
567
568                                 if (typeof window.xulG == 'object' && typeof window.xulG.on_finished == 'function') {
569                                         obj.error.sdump('D_PATRON_SUMMARY',
570                                                 'patron.summary: Calling external .on_finished()\n');
571                                         window.xulG.on_finished(obj.patron);
572                                 } else {
573                                         obj.error.sdump('D_PATRON_SUMMARY','patron.summary: No external .on_finished()\n');
574                                 }
575
576                         } );
577
578                         // Do it
579                         JSAN.use('util.exec'); obj.exec = new util.exec();
580                         obj.exec.on_error = function(E) {
581
582                                 if (typeof window.xulG == 'object' && typeof window.xulG.on_error == 'function') {
583                                         window.xulG.on_error(E);
584                                 } else {
585                                         alert(js2JSON(E));
586                                 }
587
588                         }
589                         this.exec.chain( chain );
590
591                 } catch(E) {
592                         if (typeof window.xulG == 'object' && typeof window.xulG.on_error == 'function') {
593                                 window.xulG.on_error(E);
594                         } else {
595                                 alert(js2JSON(E));
596                         }
597                 }
598         }
599 }
600
601 dump('exiting patron.summary.js\n');