]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/patron/display.js
de9d12c17c3160581aa14c0ad8508d1713ed6181
[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('util.window'); this.window = new util.window();
8         JSAN.use('util.network'); this.network = new util.network();
9         this.w = window;
10 }
11
12 patron.display.prototype = {
13
14         'init' : function( params ) {
15
16                 var obj = this;
17
18                 obj.session = params['session'];
19                 obj.barcode = params['barcode'];
20
21                 JSAN.use('OpenILS.data'); this.OpenILS = {}; 
22                 obj.OpenILS.data = new OpenILS.data(); obj.OpenILS.data.init({'via':'stash'});
23
24                 JSAN.use('util.deck'); 
25                 obj.right_deck = new util.deck('patron_right_deck');
26                 obj.left_deck = new util.deck('patron_left_deck');
27
28                 function spawn_checkout_interface() {
29                         obj.right_deck.set_iframe(
30                                 urls.remote_checkout
31                                 + '?session=' + window.escape( obj.session )
32                                 + '&patron_id=' + window.escape( obj.patron.id() ),
33                                 {},
34                                 { 
35                                         'on_checkout' : function(checkout) {
36                                                 var c = obj.summary_window.g.summary.patron.checkouts();
37                                                 c.push( checkout );
38                                                 obj.summary_window.g.summary.patron.checkouts( c );
39                                                 obj.summary_window.g.summary.controller.render('patron_checkouts');
40                                         }
41                                 }
42                         );
43                         dump('obj.right_deck.node.childNodes.length = ' + obj.right_deck.node.childNodes.length + '\n');
44                 }
45
46                 JSAN.use('util.controller'); obj.controller = new util.controller();
47                 obj.controller.init(
48                         {
49                                 control_map : {
50                                         'cmd_broken' : [
51                                                 ['command'],
52                                                 function() { alert('Not Yet Implemented'); }
53                                         ],
54                                         'cmd_patron_retrieve' : [
55                                                 ['command'],
56                                                 function(ev) {
57                                                 }
58                                         ],
59                                         'cmd_patron_refresh' : [
60                                                 ['command'],
61                                                 function(ev) {
62                                                         obj.controller.view.patron_name.setAttribute(
63                                                                 'value','Retrieving...'
64                                                         );
65                                                         try { obj.summary_window.refresh(); } catch(E) { dump(E + '\n'); }
66                                                         try { obj.refresh_deck(); } catch(E) { dump(E + '\n'); }
67                                                 }
68                                         ],
69                                         'cmd_patron_checkout' : [
70                                                 ['command'],
71                                                 spawn_checkout_interface
72                                         ],
73                                         'cmd_patron_items' : [
74                                                 ['command'],
75                                                 function(ev) {
76                                                         obj.right_deck.set_iframe(
77                                                                 urls.remote_patron_items
78                                                                 + '?session=' + window.escape( obj.session )
79                                                                 + '&patron_id=' + window.escape( obj.patron.id() ),
80                                                                 {},
81                                                                 {
82                                                                         'checkouts' : obj.patron.checkouts()
83                                                                 }
84                                                         );
85                                                         dump('obj.right_deck.node.childNodes.length = ' + obj.right_deck.node.childNodes.length + '\n');
86                                                 }
87                                         ],
88                                         'cmd_patron_holds' : [
89                                                 ['command'],
90                                                 function(ev) {
91                                                         obj.right_deck.set_iframe(
92                                                                 urls.remote_patron_holds        
93                                                                 + '?session=' + window.escape( obj.session )
94                                                                 + '&patron_id=' + window.escape( obj.patron.id() ),
95                                                                 {},
96                                                                 {
97                                                                         //FIXME//'holds' : obj.patron.holds()
98                                                                 }
99                                                         );
100                                                         dump('obj.right_deck.node.childNodes.length = ' + obj.right_deck.node.childNodes.length + '\n');
101                                                 }
102                                         ],
103                                         'cmd_patron_bills' : [
104                                                 ['command'],
105                                                 function(ev) {
106                                                         obj.right_deck.set_iframe(
107                                                                 urls.remote_patron_bills
108                                                                 + '?session=' + window.escape( obj.session )
109                                                                 + '&patron_id=' + window.escape( obj.patron.id() ),
110                                                                 {},
111                                                                 {
112                                                                         //FIXME//'bills' : obj.patron.bills()
113                                                                 }
114                                                         );
115                                                         dump('obj.right_deck.node.childNodes.length = ' + obj.right_deck.node.childNodes.length + '\n');
116                                                 }
117                                         ],
118                                         'cmd_patron_edit' : [
119                                                 ['command'],
120                                                 function(ev) {
121                                                         obj.right_deck.set_iframe(
122                                                                 urls.remote_patron_edit
123                                                                 + '?ses=' + window.escape( obj.session )
124                                                                 + '&usr=' + window.escape( obj.patron.id() ),
125                                                                 {}, {}
126                                                         );
127                                                         dump('obj.right_deck.node.childNodes.length = ' + obj.right_deck.node.childNodes.length + '\n');
128                                                 }
129                                         ],
130                                         'cmd_patron_info' : [
131                                                 ['command'],
132                                                 function(ev) {
133                                                         obj.right_deck.set_iframe(urls.remote_patron_info);
134                                                         dump('obj.right_deck.node.childNodes.length = ' + obj.right_deck.node.childNodes.length + '\n');
135                                                 }
136                                         ],
137                                         'patron_name' : [
138                                                 ['render'],
139                                                 function(e) {
140                                                         return function() { 
141                                                                 e.setAttribute('value',
142                                                                         obj.patron.family_name() + ', ' + obj.patron.first_given_name()
143                                                                 );
144                                                                 e.setAttribute('style','background-color: lime');
145                                                                 if (obj.summary_window) {
146                                                                         //FIXME//bills should become a virtual field
147                                                                         if (obj.summary_window.g.summary.patron.bills.length > 0)
148                                                                                 e.setAttribute('style','background-color: yellow');
149                                                                         if (obj.summary_window.g.summary.patron.standing() == 2)
150                                                                                 e.setAttribute('style','background-color: lightred');
151                                                                 }
152
153                                                         };
154                                                 }
155                                         ],
156                                         'PatronNavBar' : [
157                                                 ['render'],
158                                                 function(e) {
159                                                         return function() {}
160                                                 }
161                                         ],
162                                 }
163                         }
164                 );
165
166                 if (obj.barcode) {
167                         obj.controller.view.PatronNavBar.selectedIndex = 1;
168                         obj.controller.view.cmd_patron_refresh.setAttribute('disabled','true');
169                         obj.controller.view.cmd_patron_checkout.setAttribute('disabled','true');
170                         obj.controller.view.cmd_patron_items.setAttribute('disabled','true');
171                         obj.controller.view.cmd_patron_holds.setAttribute('disabled','true');
172                         obj.controller.view.cmd_patron_bills.setAttribute('disabled','true');
173                         obj.controller.view.cmd_patron_edit.setAttribute('disabled','true');
174                         obj.controller.view.cmd_patron_info.setAttribute('disabled','true');
175                         obj.controller.view.patron_name.setAttribute('value','Retrieving...');
176                         var frame = obj.left_deck.set_iframe(
177                                 urls.remote_patron_summary
178                                 +'?session=' + window.escape(obj.session)
179                                 +'&barcode=' + window.escape(obj.barcode), 
180                                 {},
181                                 {
182                                         'on_finished' : function(patron) {
183                                                 obj.patron = patron; obj.controller.render();
184                                                 obj.controller.view.cmd_patron_refresh.setAttribute('disabled','false');
185                                                 obj.controller.view.cmd_patron_checkout.setAttribute('disabled','false');
186                                                 obj.controller.view.cmd_patron_items.setAttribute('disabled','false');
187                                                 obj.controller.view.cmd_patron_holds.setAttribute('disabled','false');
188                                                 obj.controller.view.cmd_patron_bills.setAttribute('disabled','false');
189                                                 obj.controller.view.cmd_patron_edit.setAttribute('disabled','false');
190                                                 obj.controller.view.cmd_patron_info.setAttribute('disabled','false');
191                                                 if (!obj._checkout_spawned) {
192                                                         spawn_checkout_interface();
193                                                         obj._checkout_spawned = true;
194                                                 }
195                                         }
196                                 }
197                         );
198                         obj.summary_window = frame.contentWindow;
199                 } else {
200                         obj.controller.view.PatronNavBar.selectedIndex = 0;
201                         obj.controller.view.cmd_patron_retrieve.setAttribute('disabled','true');
202                         var form_frame = obj.left_deck.set_iframe(
203                                 urls.remote_patron_search_form
204                                 +'?session=' + window.escape(obj.session),
205                                 {},
206                                 {
207                                         'on_submit' : function(query) {
208                                                 var list_frame = obj.right_deck.reset_iframe(
209                                                         urls.remote_patron_search_result
210                                                         +'?session=' + window.escape(obj.session) + '&' + query,
211                                                         {},
212                                                         {
213                                                         }
214                                                 );
215                                                 obj.search_result = list_frame.contentWindow;
216                                         }
217                                 }
218                         );
219                         obj.search_window = form_frame.contentWindow;
220                         obj._checkout_spawned = true;
221                 }
222         },
223
224         '_checkout_spawned' : false,
225
226         'refresh_deck' : function() {
227                 var obj = this;
228                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
229                 for (var i = 0; i < obj.right_deck.node.childNodes.length; i++) {
230                         try {
231
232                                 var f = obj.right_deck.node.childNodes[i];
233                                 var w = f.contentWindow;
234                                 if (typeof w.refresh == 'function') {
235                                         w.refresh();
236                                 }
237
238                         } catch(E) {
239                                 dump('refresh_deck: ' + E + '\n');
240                         }
241                 }
242         },
243 }
244
245 dump('exiting patron/display.js\n');