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