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