spawn buckets interface from copy status interface
[Evergreen.git] / Open-ILS / xul / staff_client / server / circ / copy_status.js
1 dump('entering circ.copy_status.js\n');
2
3 if (typeof circ == 'undefined') circ = {};
4 circ.copy_status = function (params) {
5
6         JSAN.use('util.error'); this.error = new util.error();
7         JSAN.use('util.network'); this.network = new util.network();
8         JSAN.use('util.date');
9         JSAN.use('OpenILS.data'); this.data = new OpenILS.data(); this.data.init({'via':'stash'});
10 }
11
12 circ.copy_status.prototype = {
13         'selection_list' : [],
14
15         'init' : function( params ) {
16
17                 var obj = this;
18
19                 obj.session = params['session'];
20
21                 JSAN.use('circ.util');
22                 var columns = circ.util.columns( 
23                         { 
24                                 'barcode' : { 'hidden' : false },
25                                 'title' : { 'hidden' : false },
26                                 'location' : { 'hidden' : false },
27                                 'call_number' : { 'hidden' : false },
28                                 'status' : { 'hidden' : false },
29                         } 
30                 );
31
32                 JSAN.use('util.list'); obj.list = new util.list('copy_status_list');
33                 obj.list.init(
34                         {
35                                 'columns' : columns,
36                                 'map_row_to_column' : circ.util.std_map_row_to_column(),
37                                 'on_select' : function(ev) {
38                                         try {
39                                                 JSAN.use('util.functional');
40                                                 var sel = obj.list.retrieve_selection();
41                                                 obj.selection_list = util.functional.map_list(
42                                                         sel,
43                                                         function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
44                                                 );
45                                                 obj.error.sdump('D_TRACE','circ/copy_status: selection list = ' + js2JSON(obj.selection_list) );
46                                                 if (obj.selection_list.length == 0) {
47                                                         obj.controller.view.sel_checkin.disabled = true;
48                                                         obj.controller.view.sel_edit.disabled = true;
49                                                         obj.controller.view.sel_opac.disabled = true;
50                                                         obj.controller.view.sel_patron.disabled = true;
51                                                         obj.controller.view.sel_bucket.disabled = true;
52                                                 } else {
53                                                         obj.controller.view.sel_checkin.disabled = false;
54                                                         obj.controller.view.sel_edit.disabled = false;
55                                                         obj.controller.view.sel_opac.disabled = false;
56                                                         obj.controller.view.sel_patron.disabled = false;
57                                                         obj.controller.view.sel_bucket.disabled = false;
58                                                 }
59                                         } catch(E) {
60                                                 alert('FIXME: ' + E);
61                                         }
62                                 },
63                         }
64                 );
65                 
66                 JSAN.use('util.controller'); obj.controller = new util.controller();
67                 obj.controller.init(
68                         {
69                                 'control_map' : {
70                                         'sel_checkin' : [
71                                                 ['command'],
72                                                 function() {
73                                                         JSAN.use('circ.util');
74                                                         for (var i = 0; i < obj.selection_list.length; i++) {
75                                                                 var barcode = obj.selection_list[i][1];
76                                                                 var checkin = circ.util.checkin_via_barcode(
77                                                                         obj.session, barcode
78                                                                 );
79                                                         }
80                                                 }
81                                         ],
82                                         'sel_edit' : [
83                                                 ['command'],
84                                                 function() {
85                                                         try {
86                                                                 obj.spawn_copy_editor();
87                                                         } catch(E) {
88                                                                 alert(E);
89                                                         }
90                                                 }
91                                         ],
92                                         'sel_opac' : [
93                                                 ['command'],
94                                                 function() {
95                                                         alert('Not Yet Implemented');
96                                                 }
97                                         ],
98                                         'sel_patron' : [
99                                                 ['command'],
100                                                 function() {
101                                                         alert('Not Yet Implemented');
102                                                 }
103                                         ],
104                                         'sel_bucket' : [
105                                                 ['command'],
106                                                 function() {
107                                                         JSAN.use('util.functional');
108                                                         JSAN.use('util.window'); var win = new util.window();
109                                                         win.open( 
110                                                                 xulG.url_prefix(urls.XUL_COPY_BUCKETS) 
111                                                                 + '?session=' + window.escape(obj.session)
112                                                                 + '&copy_ids=' + js2JSON(
113                                                                         util.functional.map_list(
114                                                                                 obj.selection_list,
115                                                                                 function (o) {
116                                                                                         return o[0];
117                                                                                 }
118                                                                         )
119                                                                 ),
120                                                                 'sel_bucket_win' + win.window_name_increment(),
121                                                                 'chrome,resizable,modal,center'
122                                                         );
123                                                 }
124                                         ],
125                                         'copy_status_barcode_entry_textbox' : [
126                                                 ['keypress'],
127                                                 function(ev) {
128                                                         if (ev.keyCode && ev.keyCode == 13) {
129                                                                 obj.copy_status();
130                                                         }
131                                                 }
132                                         ],
133                                         'cmd_broken' : [
134                                                 ['command'],
135                                                 function() { alert('Not Yet Implemented'); }
136                                         ],
137                                         'cmd_copy_status_submit_barcode' : [
138                                                 ['command'],
139                                                 function() {
140                                                         obj.copy_status();
141                                                 }
142                                         ],
143                                         'cmd_copy_status_print' : [
144                                                 ['command'],
145                                                 function() {
146                                                         dump( js2JSON( obj.list.dump() ) );
147                                                         alert( js2JSON( obj.list.dump() ) );
148                                                 }
149                                         ],
150                                         'cmd_copy_status_reprint' : [
151                                                 ['command'],
152                                                 function() {
153                                                 }
154                                         ],
155                                         'cmd_copy_status_done' : [
156                                                 ['command'],
157                                                 function() {
158                                                 }
159                                         ],
160                                 }
161                         }
162                 );
163                 this.controller.render();
164                 this.controller.view.copy_status_barcode_entry_textbox.focus();
165
166         },
167
168         'copy_status' : function() {
169                 var obj = this;
170                 try {
171                         var barcode = obj.controller.view.copy_status_barcode_entry_textbox.value;
172                         JSAN.use('circ.util');
173                         var copy = obj.network.simple_request( 'FM_ACP_RETRIEVE_VIA_BARCODE', [ barcode ]);
174                         if (copy == null) {
175                                 throw('COPY NOT FOUND');
176                         } else {
177                                 obj.list.append(
178                                         {
179                                                 'retrieve_id' : js2JSON( [ copy.id(), barcode ] ),
180                                                 'row' : {
181                                                         'my' : {
182                                                                 'mvr' : obj.network.simple_request('MODS_SLIM_RECORD_RETRIEVE_VIA_COPY', [ copy.id() ]),
183                                                                 'acp' : copy,
184                                                         }
185                                                 }
186                                         }
187                                 );
188                         }
189                         obj.controller.view.copy_status_barcode_entry_textbox.value = '';
190                         obj.controller.view.copy_status_barcode_entry_textbox.focus();
191                 } catch(E) {
192                         alert('FIXME: need special alert and error handling\n'
193                                 + js2JSON(E));
194                         obj.controller.view.copy_status_barcode_entry_textbox.select();
195                         obj.controller.view.copy_status_barcode_entry_textbox.focus();
196                 }
197
198         },
199         
200         'spawn_copy_editor' : function() {
201
202                 /* FIXME -  a lot of redundant calls here */
203
204                 var obj = this;
205
206                 JSAN.use('util.widgets'); JSAN.use('util.functional');
207
208                 var list = obj.selection_list;
209
210                 list = util.functional.map_list(
211                         list,
212                         function (o) {
213                                 return o[0];
214                         }
215                 );
216
217                 var copies = util.functional.map_list(
218                         list,
219                         function (acp_id) {
220                                 return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]);
221                         }
222                 );
223
224                 var edit = 0;
225                 try {
226                         edit = obj.network.request(
227                                 api.PERM_MULTI_ORG_CHECK.app,
228                                 api.PERM_MULTI_ORG_CHECK.method,
229                                 [ 
230                                         obj.session, 
231                                         obj.data.list.au[0].id(), 
232                                         util.functional.map_list(
233                                                 copies,
234                                                 function (o) {
235                                                         return obj.network.simple_request('FM_ACN_RETRIEVE',[o.call_number()]).owning_lib();
236                                                 }
237                                         ),
238                                         [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
239                                 ]
240                         ).length == 0 ? 1 : 0;
241                 } catch(E) {
242                         obj.error.sdump('D_ERROR','batch permission check: ' + E);
243                 }
244
245                 var title = list.length == 1 ? 'Copy' : 'Copies';
246
247                 JSAN.use('util.window'); var win = new util.window();
248                 obj.data.temp = '';
249                 obj.data.stash('temp');
250                 var w = win.open(
251                         window.xulG.url_prefix(urls.XUL_COPY_EDITOR)
252                                 +'?session='+window.escape(obj.session)
253                                 +'&copy_ids='+window.escape(js2JSON(list))
254                                 +'&edit='+edit,
255                         title,
256                         'chrome,modal,resizable'
257                 );
258                 /* FIXME -- need to unique the temp space, and not rely on modalness of window */
259                 obj.data.stash_retrieve();
260                 copies = JSON2js( obj.data.temp );
261                 obj.error.sdump('D_CAT','in circ/copy_status, copy editor, copies =\n<<' + copies + '>>');
262                 if (edit=='1' && copies!='' && typeof copies != 'undefined') {
263                         try {
264                                 var r = obj.network.request(
265                                         api.FM_ACP_FLESHED_BATCH_UPDATE.app,
266                                         api.FM_ACP_FLESHED_BATCH_UPDATE.method,
267                                         [ obj.session, copies ]
268                                 );
269                                 /* FIXME -- revisit the return value here */
270                         } catch(E) {
271                                 alert('copy update error: ' + js2JSON(E));
272                         }
273                 }
274         },
275
276 }
277
278 dump('exiting circ.copy_status.js\n');