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