]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/patron/display.js
toward patron display
[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                                                 e.setAttribute('value',
56                                                         obj.patron.credit_forward_balance()
57                                                 );
58                                         };
59                                 }
60                         ],
61                         'patron_bill' : [
62                                 ['render'],
63                                 function(e) {
64                                         return function() { 
65                                                 JSAN.use('util.money');
66                                                 var total = 0;
67                                                 for (var i = 0; i < obj.patron.bills.length; i++) {
68                                                         total += util.money.dollars_float_to_cents_integer( 
69                                                                 obj.patron.bills[i].balance_owed() 
70                                                         );
71                                                 }
72                                                 e.setAttribute('value',
73                                                         util.money.cents_as_dollars( total )
74                                                 );
75                                         };
76                                 }
77                         ],
78                         'patron_checkouts' : [
79                                 ['render'],
80                                 function(e) {
81                                         return function() { };
82                                 }
83                         ],
84                         'patron_overdue' : [
85                                 ['render'],
86                                 function(e) {
87                                         return function() { };
88                                 }
89                         ],
90                         'patron_holds' : [
91                                 ['render'],
92                                 function(e) {
93                                         return function() { };
94                                 }
95                         ],
96                         'patron_holds_available' : [
97                                 ['render'],
98                                 function(e) {
99                                         return function() { };
100                                 }
101                         ],
102                         'patron_card' : [
103                                 ['render'],
104                                 function(e) {
105                                         return function() { };
106                                 }
107                         ],
108                         'patron_ident_type_1' : [
109                                 ['render'],
110                                 function(e) {
111                                         return function() { };
112                                 }
113                         ],
114                         'patron_ident_value_1' : [
115                                 ['render'],
116                                 function(e) {
117                                         return function() { };
118                                 }
119                         ],
120                         'patron_ident_type_2' : [
121                                 ['render'],
122                                 function(e) {
123                                         return function() { };
124                                 }
125                         ],
126                         'patron_date_of_birth' : [
127                                 ['render'],
128                                 function(e) {
129                                         return function() { };
130                                 }
131                         ],
132                         'patron_day_phone' : [
133                                 ['render'],
134                                 function(e) {
135                                         return function() { };
136                                 }
137                         ],
138                         'patron_evening_phone' : [
139                                 ['render'],
140                                 function(e) {
141                                         return function() { };
142                                 }
143                         ],
144                         'patron_other_phone' : [
145                                 ['render'],
146                                 function(e) {
147                                         return function() { };
148                                 }
149                         ],
150                         'patron_email' : [
151                                 ['render'],
152                                 function(e) {
153                                         return function() { };
154                                 }
155                         ],
156                         'patron_photo_url' : [
157                                 ['render'],
158                                 function(e) {
159                                         return function() { };
160                                 }
161                         ],
162                         'patron_library' : [
163                                 ['render'],
164                                 function(e) {
165                                         return function() { };
166                                 }
167                         ],
168                         'patron_mailing_address_street1' : [
169                                 ['render'],
170                                 function(e) {
171                                         return function() { };
172                                 }
173                         ],
174                         'patron_mailing_address_street2' : [
175                                 ['render'],
176                                 function(e) {
177                                         return function() { };
178                                 }
179                         ],
180                         'patron_mailing_address_city' : [
181                                 ['render'],
182                                 function(e) {
183                                         return function() { };
184                                 }
185                         ],
186                         'patron_mailing_address_state' : [
187                                 ['render'],
188                                 function(e) {
189                                         return function() { };
190                                 }
191                         ],
192                         'patron_mailing_address_post_code' : [
193                                 ['render'],
194                                 function(e) {
195                                         return function() { };
196                                 }
197                         ],
198                         'patron_physical_address_street1' : [
199                                 ['render'],
200                                 function(e) {
201                                         return function() { };
202                                 }
203                         ],
204                         'patron_physical_address_street2' : [
205                                 ['render'],
206                                 function(e) {
207                                         return function() { };
208                                 }
209                         ],
210                         'patron_physical_address_city' : [
211                                 ['render'],
212                                 function(e) {
213                                         return function() { };
214                                 }
215                         ],
216                         'patron_physical_address_state' : [
217                                 ['render'],
218                                 function(e) {
219                                         return function() { };
220                                 }
221                         ],
222                         'patron_physical_address_post_code' : [
223                                 ['render'],
224                                 function(e) {
225                                         return function() { };
226                                 }
227                         ]
228                 };
229
230                 for (var i in control_map) {
231                         var cmd = this.w.document.getElementById(i);
232                         if (cmd) {
233                                 for (var j in control_map[i][0]) {
234                                         if (control_map[i][1]) {
235                                                 var ev_type = control_map[i][0][j];
236                                                 switch(ev_type) {
237                                                         case 'render':
238                                                                 obj.render_list.push( control_map[i][1](cmd) ); 
239                                                         break;
240                                                         default: cmd.addEventListener(ev_type,control_map[i][1],false);
241                                                 }
242                                         }
243                                 }
244                         }
245                         obj.view[i] = cmd;
246                 }
247
248                 obj.retrieve();
249
250         },
251
252         'retrieve' : function() {
253
254                 var patron;
255                 try {
256
257                         var obj = this;
258
259                         var chain = [];
260
261                         // Retrieve the patron
262                         chain.push(
263                                 function() {
264                                         try {
265                                                 var patron = obj.network.request(
266                                                         'open-ils.actor',
267                                                         'open-ils.actor.user.fleshed.retrieve_by_barcode',
268                                                         [ obj.session, obj.barcode ]
269                                                 );
270                                                 if (patron) {
271
272                                                         if (instanceOf(patron,au)) {
273
274                                                                 obj.patron = patron;
275
276                                                         } else {
277
278                                                                 throw('patron is not an au fm object');
279                                                         }
280                                                 } else {
281
282                                                         throw('patron == false');
283                                                 }
284
285                                         } catch(E) {
286                                                 var error = ('patron.display.retrieve : ' + js2JSON(E));
287                                                 obj.error.sdump('D_ERROR',error);
288                                                 alert(error);
289                                                 //FIXME// abort the chain
290                                         }
291                                 }
292                         );
293
294                         // Retrieve the bills
295                         chain.push(
296                                 function() {
297                                         try {
298                                                 var bills = obj.network.request(
299                                                         'open-ils.actor',
300                                                         'open-ils.actor.user.transactions.have_balance',
301                                                         [ obj.session, obj.patron.id() ]
302                                                 );
303                                                 //FIXME// obj.patron.bills( bills );
304                                                 obj.patron.bills = bills;
305                                         } catch(E) {
306                                                 var error = ('patron.display.retrieve : ' + js2JSON(E));
307                                                 obj.error.sdump('D_ERROR',error);
308                                                 alert(error);
309                                                 //FIXME// abort the chain
310                                         }
311                                 }
312                         );
313
314                         // Retrieve the checkouts
315                         chain.push(
316                                 function() {
317                                         try {
318                                                 var checkouts = obj.network.request(
319                                                         'open-ils.circ',
320                                                         'open-ils.circ.actor.user.checked_out',
321                                                         [ obj.session, obj.patron.id() ]
322                                                 );
323                                                 obj.patron.checkouts( checkouts );
324                                         } catch(E) {
325                                                 var error = ('patron.display.retrieve : ' + js2JSON(E));
326                                                 obj.error.sdump('D_ERROR',error);
327                                                 alert(error);
328                                                 //FIXME// abort the chain
329                                         }
330                                 }
331                         );
332
333                         // Update the screen
334                         chain.push( function() { obj.render(); } );
335
336                         // Do it
337                         JSAN.use('util.exec');
338                         util.exec.chain( chain );
339
340                 } catch(E) {
341                         var error = ('patron.display.retrieve : ' + js2JSON(E));
342                         this.error.sdump('D_ERROR',error);
343                         alert(error);
344                 }
345         },
346
347         'render' : function() {
348
349                 for (var i in this.render_list) {
350                         try {
351                                 this.render_list[i]();
352                         } catch(E) {
353                                 var error = 'Problem in patron.display.render with\n' + this.render_list[i] + '\n\n' + js2JSON(E);
354                                 this.error.sdump('D_ERROR',error);
355                                 alert(error);
356                         }
357                 }
358         }
359
360 }
361
362 dump('exiting patron/display.js\n');