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