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