]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/patron/summary.js
subtotals for checkout counts
[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_standing' : [
76                                                 ['render'],
77                                                 function(e) {
78                                                         return function() {
79                                                         /*
80                                                                 e.setAttribute('value',
81                                                                         obj.OpenILS.data.hash.cst[
82                                                                                 obj.patron.standing()
83                                                                         ].value()
84                                                                 );
85                                                         */
86                                                                 var e2 = document.getElementById('patron_standing_penalties');
87                                                                 JSAN.use('util.widgets');
88                                                                 util.widgets.remove_children(e2);
89                                                                 var penalties = obj.patron.standing_penalties();
90                                                                 for (var i = 0; i < penalties.length; i++) {
91                                                                         var x = document.createElement('label');
92                                                                         x.setAttribute('value',penalties[i].penalty_type());
93                                                                         e2.appendChild(x);
94                                                                 }
95                                                         };
96                                                 }
97                                         ],
98                                         'patron_credit' : [
99                                                 ['render'],
100                                                 function(e) {
101                                                         return function() { 
102                                                                 JSAN.use('util.money');
103                                                                 e.setAttribute('value',
104                                                                         '$' + 
105                                                                         util.money.sanitize(
106                                                                                 obj.patron.credit_forward_balance()
107                                                                         )
108                                                                 );
109                                                         };
110                                                 }
111                                         ],
112                                         'patron_bill' : [
113                                                 ['render'],
114                                                 function(e) {
115                                                         return function() { 
116                                                                 e.setAttribute('value','...');
117                                                                 obj.network.simple_request(
118                                                                         'FM_MOBTS_TOTAL_HAVING_BALANCE',
119                                                                         [ ses(), obj.patron.id() ],
120                                                                         function(req) {
121                                                                                 JSAN.use('util.money');
122                                                                                 e.setAttribute('value',
123                                                                                         '$' + 
124                                                                                         util.money.sanitize( 
125                                                                                                 req.getResultObject() 
126                                                                                         )
127                                                                                 );
128                                                                         }
129                                                                 );
130                                                         };
131                                                 }
132                                         ],
133                                         'patron_checkouts' : [
134                                                 ['render'],
135                                                 function(e) {
136                                                         return function() { 
137                                                                 e.setAttribute('value','...');
138                                                                 var e2 = document.getElementById( 'patron_overdue' ); if (e2) e2.setAttribute('value','...');
139                                                                 var e3 = document.getElementById( 'patron_claimed_returned' ); if (e3) e3.setAttribute('value','...');
140                                                                 var e4 = document.getElementById( 'patron_long_overdue' ); if (e4) e4.setAttribute('value','...');
141                                                                 var e5 = document.getElementById( 'patron_lost' ); if (e5) e5.setAttribute('value','...');
142                                                                 obj.network.simple_request(
143                                                                         'FM_CIRC_COUNT_RETRIEVE_VIA_USER',
144                                                                         [ ses(), obj.patron.id() ],
145                                                                         function(req) {
146                                                                                 var robj = req.getResultObject();
147                                                                                 e.setAttribute('value', robj.out + robj.overdue + robj.claims_returned + robj.long_overdue );
148                                                                                 if (e2) e2.setAttribute('value', robj.overdue   );
149                                                                                 if (e3) e3.setAttribute('value', robj.claims_returned   );
150                                                                                 if (e4) e4.setAttribute('value', robj.long_overdue      );
151                                                                                 if (e5) e5.setAttribute('value', robj.lost      );
152                                                                         }
153                                                                 );
154                                                         };
155                                                 }
156                                         ],
157                                         'patron_overdue' : [
158                                                 ['render'],
159                                                 function(e) {
160                                                         return function() { 
161                                                                 /* handled by 'patron_checkouts' */
162                                                         };
163                                                 }
164                                         ],
165                                         'patron_holds' : [
166                                                 ['render'],
167                                                 function(e) {
168                                                         return function() { 
169                                                                 e.setAttribute('value','...');
170                                                                 var e2 = document.getElementById('patron_holds_available');
171                                                                 if (e2) e2.setAttribute('value','...');
172                                                                 obj.network.simple_request(
173                                                                         'FM_AHR_COUNT_RETRIEVE',
174                                                                         [ ses(), obj.patron.id() ],
175                                                                         function(req) {
176                                                                                 e.setAttribute('value',
177                                                                                         req.getResultObject().total
178                                                                                 );
179                                                                                 if (e2) e2.setAttribute('value',
180                                                                                         req.getResultObject().ready
181                                                                                 );
182                                                                         }
183                                                                 );
184                                                         };
185                                                 }
186                                         ],
187                                         'patron_holds_available' : [
188                                                 ['render'],
189                                                 function(e) {
190                                                         return function() { 
191                                                                 /* handled by 'patron_holds' */
192                                                         };
193                                                 }
194                                         ],
195                                         'patron_card' : [
196                                                 ['render'],
197                                                 function(e) {
198                                                         return function() { 
199                                                                 e.setAttribute('value',
200                                                                         obj.patron.card().barcode()
201                                                                 );
202                                                         };
203                                                 }
204                                         ],
205                                         'patron_ident_type_1' : [
206                                                 ['render'],
207                                                 function(e) {
208                                                         return function() { 
209                                                                 var ident_string = '';
210                                                                 var ident = obj.OpenILS.data.hash.cit[
211                                                                         obj.patron.ident_type()
212                                                                 ];
213                                                                 if (ident) ident_string = ident.name()
214                                                                 e.setAttribute('value',
215                                                                         ident_string
216                                                                 );
217                                                         };
218                                                 }
219                                         ],
220                                         'patron_ident_value_1' : [
221                                                 ['render'],
222                                                 function(e) {
223                                                         return function() { 
224                                                                 e.setAttribute('value',
225                                                                         obj.patron.ident_value()
226                                                                 );
227                                                         };
228                                                 }
229                                         ],
230                                         'patron_ident_type_2' : [
231                                                 ['render'],
232                                                 function(e) {
233                                                         return function() { 
234                                                                 var ident_string = '';
235                                                                 var ident = obj.OpenILS.data.hash.cit[
236                                                                         obj.patron.ident_type2()
237                                                                 ];
238                                                                 if (ident) ident_string = ident.name()
239                                                                 e.setAttribute('value',
240                                                                         ident_string
241                                                                 );
242                                                         };
243                                                 }
244                                         ],
245                                         'patron_ident_value_2' : [
246                                                 ['render'],
247                                                 function(e) {
248                                                         return function() { 
249                                                                 e.setAttribute('value',
250                                                                         obj.patron.ident_value2()
251                                                                 );
252                                                         };
253                                                 }
254                                         ],
255                                         'patron_date_of_birth' : [
256                                                 ['render'],
257                                                 function(e) {
258                                                         return function() { 
259                                                                 e.setAttribute('value',
260                                                                         obj.patron.dob().substr(0,10)
261                                                                 );
262                                                         };
263                                                 }
264                                         ],
265                                         'patron_day_phone' : [
266                                                 ['render'],
267                                                 function(e) {
268                                                         return function() { 
269                                                                 e.setAttribute('value',
270                                                                         obj.patron.day_phone()
271                                                                 );
272                                                         };
273                                                 }
274                                         ],
275                                         'patron_evening_phone' : [
276                                                 ['render'],
277                                                 function(e) {
278                                                         return function() { 
279                                                                 e.setAttribute('value',
280                                                                         obj.patron.evening_phone()
281                                                                 );
282                                                         };
283                                                 }
284                                         ],
285                                         'patron_other_phone' : [
286                                                 ['render'],
287                                                 function(e) {
288                                                         return function() { 
289                                                                 e.setAttribute('value',
290                                                                         obj.patron.other_phone()
291                                                                 );
292                                                         };
293                                                 }
294                                         ],
295                                         'patron_email' : [
296                                                 ['render'],
297                                                 function(e) {
298                                                         return function() { 
299                                                                 e.setAttribute('value',
300                                                                         obj.patron.email()
301                                                                 );
302                                                         };
303                                                 }
304                                         ],
305                                         'patron_photo_url' : [
306                                                 ['render'],
307                                                 function(e) {
308                                                         return function() { 
309                                                                 e.setAttribute('src',
310                                                                         obj.patron.photo_url()
311                                                                 );
312                                                         };
313                                                 }
314                                         ],
315                                         'patron_library' : [
316                                                 ['render'],
317                                                 function(e) {
318                                                         return function() { 
319                                                                 e.setAttribute('value',
320                                                                         obj.OpenILS.data.hash.aou[
321                                                                                 obj.patron.home_ou()
322                                                                         ].shortname()
323                                                                 );
324                                                                 e.setAttribute('tooltiptext',
325                                                                         obj.OpenILS.data.hash.aou[
326                                                                                 obj.patron.home_ou()
327                                                                         ].name()
328                                                                 );
329                                                         };
330                                                 }
331                                         ],
332                                         'patron_last_library' : [
333                                                 ['render'],
334                                                 function(e) {
335                                                         return function() { 
336                                                                 e.setAttribute('value',
337                                                                         obj.OpenILS.data.hash.aou[
338                                                                                 obj.patron.home_ou()
339                                                                         ].shortname()
340                                                                 );
341                                                                 e.setAttribute('tooltiptext',
342                                                                         obj.OpenILS.data.hash.aou[
343                                                                                 obj.patron.home_ou()
344                                                                         ].name()
345                                                                 );
346                                                         };
347                                                 }
348                                         ],
349                                         'patron_mailing_address_street1' : [
350                                                 ['render'],
351                                                 function(e) {
352                                                         return function() { 
353                                                                 e.setAttribute('value',
354                                                                         obj.patron.mailing_address().street1()
355                                                                 );
356                                                         };
357                                                 }
358                                         ],
359                                         'patron_mailing_address_street2' : [
360                                                 ['render'],
361                                                 function(e) {
362                                                         return function() { 
363                                                                 e.setAttribute('value',
364                                                                         obj.patron.mailing_address().street2()
365                                                                 );
366                                                         };
367                                                 }
368                                         ],
369                                         'patron_mailing_address_city' : [
370                                                 ['render'],
371                                                 function(e) {
372                                                         return function() { 
373                                                                 e.setAttribute('value',
374                                                                         obj.patron.mailing_address().city()
375                                                                 );
376                                                         };
377                                                 }
378                                         ],
379                                         'patron_mailing_address_state' : [
380                                                 ['render'],
381                                                 function(e) {
382                                                         return function() { 
383                                                                 e.setAttribute('value',
384                                                                         obj.patron.mailing_address().state()
385                                                                 );
386                                                         };
387                                                 }
388                                         ],
389                                         'patron_mailing_address_post_code' : [
390                                                 ['render'],
391                                                 function(e) {
392                                                         return function() { 
393                                                                 e.setAttribute('value',
394                                                                         obj.patron.mailing_address().post_code()
395                                                                 );
396                                                         };
397                                                 }
398                                         ],
399                                         'patron_physical_address_street1' : [
400                                                 ['render'],
401                                                 function(e) {
402                                                         return function() { 
403                                                                 e.setAttribute('value',
404                                                                         obj.patron.billing_address().street1()
405                                                                 );
406                                                         };
407                                                 }
408                                         ],
409                                         'patron_physical_address_street2' : [
410                                                 ['render'],
411                                                 function(e) {
412                                                         return function() { 
413                                                                 e.setAttribute('value',
414                                                                         obj.patron.billing_address().street2()
415                                                                 );
416                                                         };
417                                                 }
418                                         ],
419                                         'patron_physical_address_city' : [
420                                                 ['render'],
421                                                 function(e) {
422                                                         return function() { 
423                                                                 e.setAttribute('value',
424                                                                         obj.patron.billing_address().city()
425                                                                 );
426                                                         };
427                                                 }
428                                         ],
429                                         'patron_physical_address_state' : [
430                                                 ['render'],
431                                                 function(e) {
432                                                         return function() { 
433                                                                 e.setAttribute('value',
434                                                                         obj.patron.billing_address().state()
435                                                                 );
436                                                         };
437                                                 }
438                                         ],
439                                         'patron_physical_address_post_code' : [
440                                                 ['render'],
441                                                 function(e) {
442                                                         return function() { 
443                                                                 e.setAttribute('value',
444                                                                         obj.patron.billing_address().post_code()
445                                                                 );
446                                                         };
447                                                 }
448                                         ]
449                                 }
450                         }
451                 );
452
453                 obj.retrieve();
454
455         },
456
457         'retrieve' : function() {
458
459                 try {
460
461                         var obj = this;
462
463                         var chain = [];
464
465                         // Retrieve the patron
466                                 function blah_retrieve() {
467                                         try {
468                                                 var robj;
469                                                 if (obj.barcode && obj.barcode != 'null') {
470                                                         robj = obj.network.request(
471                                                                 api.FM_AU_RETRIEVE_VIA_BARCODE.app,
472                                                                 api.FM_AU_RETRIEVE_VIA_BARCODE.method,
473                                                                 [ ses(), obj.barcode ]
474                                                         );
475                                                 } else if (obj.id && obj.id != 'null') {
476                                                         robj = obj.network.simple_request(
477                                                                 'FM_AU_FLESHED_RETRIEVE_VIA_ID',
478                                                                 [ ses(), obj.id ]
479                                                         );
480                                                 } else {
481                                                         throw('summary: No barcode or id');
482                                                 }
483                                                 if (robj) {
484
485                                                         if (instanceOf(robj,au)) {
486
487                                                                 obj.patron = robj;
488                                                                 JSAN.use('patron.util');
489                                                                 document.getElementById('patron_name').setAttribute('value',
490                                                                         obj.patron.family_name() + ', ' + obj.patron.first_given_name() + ' ' +
491                                                                         ( obj.patron.second_given_name() ? obj.patron.second_given_name() : '' )
492                                                                 );
493                                                                 patron.util.set_penalty_css(obj.patron);
494
495                                                         } else {
496
497                                                                 throw(robj);
498
499                                                         }
500                                                 } else {
501
502                                                         throw(robj);
503
504                                                 }
505
506                                         } catch(E) {
507                                                 throw(E);
508                                         }
509                                 };
510                                 blah_retrieve();
511
512                         /*
513                         // Retrieve the survey responses for required surveys
514                         chain.push(
515                                 function() {
516                                         try {
517                                                 var surveys = obj.OpenILS.data.list.my_asv;
518                                                 var survey_responses = {};
519                                                 for (var i = 0; i < surveys.length; i++) {
520                                                         var s = obj.network.request(
521                                                                 api.FM_ASVR_RETRIEVE.app,
522                                                                 api.FM_ASVR_RETRIEVE.method,
523                                                                 [ ses(), surveys[i].id(), obj.patron.id() ]
524                                                         );
525                                                         survey_responses[ surveys[i].id() ] = s;
526                                                 }
527                                                 obj.patron.survey_responses( survey_responses );
528                                         } catch(E) {
529                                                 var error = ('patron.summary.retrieve : ' + js2JSON(E));
530                                                 obj.error.sdump('D_ERROR',error);
531                                                 throw(error);
532                                         }
533                                 }
534                         );
535                         */
536
537                         // Update the screen
538                         chain.push( function() { obj.controller.render(); } );
539
540                         // On Complete
541
542                         chain.push( function() {
543
544                                 if (typeof window.xulG == 'object' && typeof window.xulG.on_finished == 'function') {
545                                         obj.error.sdump('D_PATRON_SUMMARY',
546                                                 'patron.summary: Calling external .on_finished()\n');
547                                         window.xulG.on_finished(obj.patron);
548                                 } else {
549                                         obj.error.sdump('D_PATRON_SUMMARY','patron.summary: No external .on_finished()\n');
550                                 }
551
552                         } );
553
554                         // Do it
555                         JSAN.use('util.exec'); obj.exec = new util.exec();
556                         obj.exec.on_error = function(E) {
557
558                                 if (typeof window.xulG == 'object' && typeof window.xulG.on_error == 'function') {
559                                         window.xulG.on_error(E);
560                                 } else {
561                                         alert(js2JSON(E));
562                                 }
563
564                         }
565                         this.exec.chain( chain );
566
567                 } catch(E) {
568                         if (typeof window.xulG == 'object' && typeof window.xulG.on_error == 'function') {
569                                 window.xulG.on_error(E);
570                         } else {
571                                 alert(js2JSON(E));
572                         }
573                 }
574         }
575 }
576
577 dump('exiting patron.summary.js\n');