]> 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_caption' : [
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                                 }
56                         ],
57                         'patron_bill' : [
58                                 ['render'],
59                                 function(e) {
60                                         return function() { };
61                                 }
62                         ],
63                         'patron_checkouts' : [
64                                 ['render'],
65                                 function(e) {
66                                         return function() { };
67                                 }
68                         ],
69                         'patron_overdue' : [
70                                 ['render'],
71                                 function(e) {
72                                         return function() { };
73                                 }
74                         ],
75                         'patron_holds' : [
76                                 ['render'],
77                                 function(e) {
78                                         return function() { };
79                                 }
80                         ],
81                         'patron_holds_available' : [
82                                 ['render'],
83                                 function(e) {
84                                         return function() { };
85                                 }
86                         ],
87                         'patron_card' : [
88                                 ['render'],
89                                 function(e) {
90                                         return function() { };
91                                 }
92                         ],
93                         'patron_ident_type_1' : [
94                                 ['render'],
95                                 function(e) {
96                                         return function() { };
97                                 }
98                         ],
99                         'patron_ident_value_1' : [
100                                 ['render'],
101                                 function(e) {
102                                         return function() { };
103                                 }
104                         ],
105                         'patron_ident_type_2' : [
106                                 ['render'],
107                                 function(e) {
108                                         return function() { };
109                                 }
110                         ],
111                         'patron_date_of_birth' : [
112                                 ['render'],
113                                 function(e) {
114                                         return function() { };
115                                 }
116                         ],
117                         'patron_day_phone' : [
118                                 ['render'],
119                                 function(e) {
120                                         return function() { };
121                                 }
122                         ],
123                         'patron_evening_phone' : [
124                                 ['render'],
125                                 function(e) {
126                                         return function() { };
127                                 }
128                         ],
129                         'patron_other_phone' : [
130                                 ['render'],
131                                 function(e) {
132                                         return function() { };
133                                 }
134                         ],
135                         'patron_email' : [
136                                 ['render'],
137                                 function(e) {
138                                         return function() { };
139                                 }
140                         ],
141                         'patron_library' : [
142                                 ['render'],
143                                 function(e) {
144                                         return function() { };
145                                 }
146                         ],
147                         'patron_mailing_address_street1' : [
148                                 ['render'],
149                                 function(e) {
150                                         return function() { };
151                                 }
152                         ],
153                         'patron_mailing_address_street2' : [
154                                 ['render'],
155                                 function(e) {
156                                         return function() { };
157                                 }
158                         ],
159                         'patron_mailing_address_city' : [
160                                 ['render'],
161                                 function(e) {
162                                         return function() { };
163                                 }
164                         ],
165                         'patron_mailing_address_state' : [
166                                 ['render'],
167                                 function(e) {
168                                         return function() { };
169                                 }
170                         ],
171                         'patron_mailing_address_post_code' : [
172                                 ['render'],
173                                 function(e) {
174                                         return function() { };
175                                 }
176                         ],
177                         'patron_physical_address_street1' : [
178                                 ['render'],
179                                 function(e) {
180                                         return function() { };
181                                 }
182                         ],
183                         'patron_physical_address_street2' : [
184                                 ['render'],
185                                 function(e) {
186                                         return function() { };
187                                 }
188                         ],
189                         'patron_physical_address_city' : [
190                                 ['render'],
191                                 function(e) {
192                                         return function() { };
193                                 }
194                         ],
195                         'patron_physical_address_state' : [
196                                 ['render'],
197                                 function(e) {
198                                         return function() { };
199                                 }
200                         ],
201                         'patron_physical_address_post_code' : [
202                                 ['render'],
203                                 function(e) {
204                                         return function() { };
205                                 }
206                         ]
207                 };
208
209                 for (var i in control_map) {
210                         var cmd = this.w.document.getElementById(i);
211                         if (cmd) {
212                                 for (var j in control_map[i][0]) {
213                                         if (control_map[i][1]) {
214                                                 var ev_type = control_map[i][0][j];
215                                                 switch(ev_type) {
216                                                         case 'render':
217                                                                 obj.render_list.push( control_map[i][1](cmd) ); 
218                                                         break;
219                                                         default: cmd.addEventListener(ev_type,control_map[i][1],false);
220                                                 }
221                                         }
222                                 }
223                         }
224                         obj.view[i] = cmd;
225                 }
226
227                 obj.retrieve();
228
229         },
230
231         'retrieve' : function() {
232
233                 var patron;
234                 try {
235                         patron = this.network.request(
236                                 'open-ils.actor',
237                                 'open-ils.actor.user.fleshed.retrieve_by_barcode',
238                                 [ this.session, this.barcode ]
239                         );
240
241                         if (patron) {
242
243                                 if (instanceOf(patron,au)) {
244
245                                         this.patron = patron;
246                                         this.render();
247
248                                 } else {
249
250                                         throw('patron is not an au fm object');
251                                 }
252                         } else {
253
254                                 throw('patron == false');
255                         }
256
257                 } catch(E) {
258                         var error = ('patron.display.retrieve : ' + js2JSON(E));
259                         this.error.sdump('D_ERROR',error);
260                         alert(error);
261                 }
262         },
263
264         'render' : function() {
265
266                 for (var i in this.render_list) {
267                         try {
268                                 this.render_list[i]();
269                         } catch(E) {
270                                 var error = 'Problem in patron.display.render with\n' + this.render_list[i] + '\n\n' + js2JSON(E);
271                                 this.error.sdump('D_ERROR',error);
272                         }
273                 }
274         }
275
276 }
277
278 dump('exiting patron/display.js\n');