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