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