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