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