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