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