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