]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/patron/display.js
holds available
[Evergreen.git] / Open-ILS / xul / staff_client / server / patron / display.js
1 dump('entering patron/display.js\n');
2
3 if (typeof patron == 'undefined') patron = {};
4 patron.display = function (params) {
5
6         JSAN.use('util.error'); this.error = new util.error();
7         JSAN.use('main.window'); this.window = new main.window();
8         JSAN.use('main.network'); this.network = new main.network();
9         this.w = window;
10 }
11
12 patron.display.prototype = {
13
14         'init' : function( params ) {
15
16                 this.session = params['session'];
17                 this.barcode = params['barcode'];
18
19                 JSAN.use('OpenILS.data'); this.OpenILS = {}; 
20                 this.OpenILS.data = new OpenILS.data( { 'session' : params.session } ); this.OpenILS.data.init(true);
21
22                 var obj = this;
23                 obj.view = {}; obj.render_list = [];
24
25                 var control_map = {
26                         'cmd_broken' : [
27                                 ['command'],
28                                 function() { alert('Not Yet Implemented'); }
29                         ],
30                         'patron_name' : [
31                                 ['render'],
32                                 function(e) {
33                                         return function() { 
34                                                 e.setAttribute('value',obj.patron.family_name() + ', ' 
35                                                         + obj.patron.first_given_name());
36                                         };
37                                 }
38                         ],
39                         'patron_profile' : [
40                                 ['render'],
41                                 function(e) {
42                                         return function() { 
43                                                 e.setAttribute('value',
44                                                         obj.OpenILS.data.hash.pgt[
45                                                                 obj.patron.profile()
46                                                         ].name()
47                                                 );
48                                         };
49                                 }
50                         ],
51                         'patron_credit' : [
52                                 ['render'],
53                                 function(e) {
54                                         return function() { 
55                                                 JSAN.use('util.money');
56                                                 e.setAttribute('value',
57                                                         util.money.cents_as_dollars(
58                                                                 obj.patron.credit_forward_balance()
59                                                         )
60                                                 );
61                                         };
62                                 }
63                         ],
64                         'patron_bill' : [
65                                 ['render'],
66                                 function(e) {
67                                         return function() { 
68                                                 JSAN.use('util.money');
69                                                 var total = 0;
70                                                 //FIXME//adjust when .bills becomes a virtual field
71                                                 for (var i = 0; i < obj.patron.bills.length; i++) {
72                                                         total += util.money.dollars_float_to_cents_integer( 
73                                                                 obj.patron.bills[i].balance_owed() 
74                                                         );
75                                                 }
76                                                 e.setAttribute('value',
77                                                         util.money.cents_as_dollars( total )
78                                                 );
79                                         };
80                                 }
81                         ],
82                         'patron_checkouts' : [
83                                 ['render'],
84                                 function(e) {
85                                         return function() { 
86                                                 e.setAttribute('value',
87                                                         obj.patron.checkouts.length     
88                                                 );
89                                         };
90                                 }
91                         ],
92                         'patron_overdue' : [
93                                 ['render'],
94                                 function(e) {
95                                         return function() { 
96                                                 //FIXME//Get Bill to do this correctly on server side
97                                                 JSAN.use('util.date');
98                                                 var total = 0;
99                                                 for (var i = 0; i < obj.patron.checkouts().length; i++) {
100                                                         var item = obj.patron.checkouts()[i];
101                                                         var due_date = item.circ.due_date();
102                                                         due_date = due_date.substr(0,4) 
103                                                                 + due_date.substr(5,2) + due_date.substr(8,2);
104                                                         var today = util.date.formatted_date( new Date() , '%Y%m%d' );
105                                                         if (today > due_date) total++;
106                                                 }
107                                                 e.setAttribute('value',
108                                                         total
109                                                 );
110                                         };
111                                 }
112                         ],
113                         'patron_holds' : [
114                                 ['render'],
115                                 function(e) {
116                                         return function() { 
117                                                 e.setAttribute('value',
118                                                         obj.patron.hold_requests.length
119                                                 );
120                                         };
121                                 }
122                         ],
123                         'patron_holds_available' : [
124                                 ['render'],
125                                 function(e) {
126                                         return function() { 
127                                                 var total = 0;
128                                                 for (var i = 0; i < obj.patron.hold_requests().length; i++) {
129                                                         var hold = obj.patron.hold_requests()[i];
130                                                         if (hold.capture_time()) total++;
131                                                 }
132                                                 e.setAttribute('value',
133                                                         total
134                                                 );
135                                         };
136                                 }
137                         ],
138                         'patron_card' : [
139                                 ['render'],
140                                 function(e) {
141                                         return function() { };
142                                 }
143                         ],
144                         'patron_ident_type_1' : [
145                                 ['render'],
146                                 function(e) {
147                                         return function() { };
148                                 }
149                         ],
150                         'patron_ident_value_1' : [
151                                 ['render'],
152                                 function(e) {
153                                         return function() { };
154                                 }
155                         ],
156                         'patron_ident_type_2' : [
157                                 ['render'],
158                                 function(e) {
159                                         return function() { };
160                                 }
161                         ],
162                         'patron_date_of_birth' : [
163                                 ['render'],
164                                 function(e) {
165                                         return function() { };
166                                 }
167                         ],
168                         'patron_day_phone' : [
169                                 ['render'],
170                                 function(e) {
171                                         return function() { };
172                                 }
173                         ],
174                         'patron_evening_phone' : [
175                                 ['render'],
176                                 function(e) {
177                                         return function() { };
178                                 }
179                         ],
180                         'patron_other_phone' : [
181                                 ['render'],
182                                 function(e) {
183                                         return function() { };
184                                 }
185                         ],
186                         'patron_email' : [
187                                 ['render'],
188                                 function(e) {
189                                         return function() { };
190                                 }
191                         ],
192                         'patron_photo_url' : [
193                                 ['render'],
194                                 function(e) {
195                                         return function() { };
196                                 }
197                         ],
198                         'patron_library' : [
199                                 ['render'],
200                                 function(e) {
201                                         return function() { };
202                                 }
203                         ],
204                         'patron_mailing_address_street1' : [
205                                 ['render'],
206                                 function(e) {
207                                         return function() { };
208                                 }
209                         ],
210                         'patron_mailing_address_street2' : [
211                                 ['render'],
212                                 function(e) {
213                                         return function() { };
214                                 }
215                         ],
216                         'patron_mailing_address_city' : [
217                                 ['render'],
218                                 function(e) {
219                                         return function() { };
220                                 }
221                         ],
222                         'patron_mailing_address_state' : [
223                                 ['render'],
224                                 function(e) {
225                                         return function() { };
226                                 }
227                         ],
228                         'patron_mailing_address_post_code' : [
229                                 ['render'],
230                                 function(e) {
231                                         return function() { };
232                                 }
233                         ],
234                         'patron_physical_address_street1' : [
235                                 ['render'],
236                                 function(e) {
237                                         return function() { };
238                                 }
239                         ],
240                         'patron_physical_address_street2' : [
241                                 ['render'],
242                                 function(e) {
243                                         return function() { };
244                                 }
245                         ],
246                         'patron_physical_address_city' : [
247                                 ['render'],
248                                 function(e) {
249                                         return function() { };
250                                 }
251                         ],
252                         'patron_physical_address_state' : [
253                                 ['render'],
254                                 function(e) {
255                                         return function() { };
256                                 }
257                         ],
258                         'patron_physical_address_post_code' : [
259                                 ['render'],
260                                 function(e) {
261                                         return function() { };
262                                 }
263                         ]
264                 };
265
266                 for (var i in control_map) {
267                         var cmd = this.w.document.getElementById(i);
268                         if (cmd) {
269                                 for (var j in control_map[i][0]) {
270                                         if (control_map[i][1]) {
271                                                 var ev_type = control_map[i][0][j];
272                                                 switch(ev_type) {
273                                                         case 'render':
274                                                                 obj.render_list.push( control_map[i][1](cmd) ); 
275                                                         break;
276                                                         default: cmd.addEventListener(ev_type,control_map[i][1],false);
277                                                 }
278                                         }
279                                 }
280                         }
281                         obj.view[i] = cmd;
282                 }
283
284                 obj.retrieve();
285
286         },
287
288         'retrieve' : function() {
289
290                 var patron;
291                 try {
292
293                         var obj = this;
294
295                         var chain = [];
296
297                         // Retrieve the patron
298                         chain.push(
299                                 function() {
300                                         try {
301                                                 var patron = obj.network.request(
302                                                         'open-ils.actor',
303                                                         'open-ils.actor.user.fleshed.retrieve_by_barcode',
304                                                         [ obj.session, obj.barcode ]
305                                                 );
306                                                 if (patron) {
307
308                                                         if (instanceOf(patron,au)) {
309
310                                                                 obj.patron = patron;
311
312                                                         } else {
313
314                                                                 throw('patron is not an au fm object');
315                                                         }
316                                                 } else {
317
318                                                         throw('patron == false');
319                                                 }
320
321                                         } catch(E) {
322                                                 var error = ('patron.display.retrieve : ' + js2JSON(E));
323                                                 obj.error.sdump('D_ERROR',error);
324                                                 alert(error);
325                                                 //FIXME// abort the chain
326                                         }
327                                 }
328                         );
329
330                         // Retrieve the bills
331                         chain.push(
332                                 function() {
333                                         try {
334                                                 var bills = obj.network.request(
335                                                         'open-ils.actor',
336                                                         'open-ils.actor.user.transactions.have_balance',
337                                                         [ obj.session, obj.patron.id() ]
338                                                 );
339                                                 //FIXME// obj.patron.bills( bills );
340                                                 obj.patron.bills = bills;
341                                         } catch(E) {
342                                                 var error = ('patron.display.retrieve : ' + js2JSON(E));
343                                                 obj.error.sdump('D_ERROR',error);
344                                                 alert(error);
345                                                 //FIXME// abort the chain
346                                         }
347                                 }
348                         );
349
350                         // Retrieve the checkouts
351                         chain.push(
352                                 function() {
353                                         try {
354                                                 var checkouts = obj.network.request(
355                                                         'open-ils.circ',
356                                                         'open-ils.circ.actor.user.checked_out',
357                                                         [ obj.session, obj.patron.id() ]
358                                                 );
359                                                 obj.patron.checkouts( checkouts );
360                                         } catch(E) {
361                                                 var error = ('patron.display.retrieve : ' + js2JSON(E));
362                                                 obj.error.sdump('D_ERROR',error);
363                                                 alert(error);
364                                                 //FIXME// abort the chain
365                                         }
366                                 }
367                         );
368
369                         // Retrieve the holds
370                         chain.push(
371                                 function() {
372                                         try {
373                                                 var holds = obj.network.request(
374                                                         'open-ils.circ',
375                                                         'open-ils.circ.holds.retrieve',
376                                                         [ obj.session, obj.patron.id() ]
377                                                 );
378                                                 obj.patron.hold_requests( holds );
379                                         } catch(E) {
380                                                 var error = ('patron.display.retrieve : ' + js2JSON(E));
381                                                 obj.error.sdump('D_ERROR',error);
382                                                 alert(error);
383                                                 //FIXME// abort the chain
384                                         }
385                                 }
386                         );
387
388                         // Update the screen
389                         chain.push( function() { obj.render(); } );
390
391                         // Do it
392                         JSAN.use('util.exec');
393                         util.exec.chain( chain );
394
395                 } catch(E) {
396                         var error = ('patron.display.retrieve : ' + js2JSON(E));
397                         this.error.sdump('D_ERROR',error);
398                         alert(error);
399                 }
400         },
401
402         'render' : function() {
403
404                 for (var i in this.render_list) {
405                         try {
406                                 this.render_list[i]();
407                         } catch(E) {
408                                 var error = 'Problem in patron.display.render with\n' + this.render_list[i] + '\n\n' + js2JSON(E);
409                                 this.error.sdump('D_ERROR',error);
410                                 alert(error);
411                         }
412                 }
413         }
414
415 }
416
417 dump('exiting patron/display.js\n');