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