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