]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/copy_status.js
refactor
[working/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                 JSAN.use('circ.util');
20                 var columns = circ.util.columns( 
21                         { 
22                                 'barcode' : { 'hidden' : false },
23                                 'title' : { 'hidden' : false },
24                                 'location' : { 'hidden' : false },
25                                 'call_number' : { 'hidden' : false },
26                                 'status' : { 'hidden' : false },
27                                 'alert_message' : { 'hidden' : false },
28                         } 
29                 );
30
31                 JSAN.use('util.list'); obj.list = new util.list('copy_status_list');
32                 obj.list.init(
33                         {
34                                 'columns' : columns,
35                                 'map_row_to_column' : circ.util.std_map_row_to_column(),
36                                 'on_select' : function(ev) {
37                                         try {
38                                                 JSAN.use('util.functional');
39                                                 var sel = obj.list.retrieve_selection();
40                                                 obj.selection_list = util.functional.map_list(
41                                                         sel,
42                                                         function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
43                                                 );
44                                                 obj.error.sdump('D_TRACE','circ/copy_status: selection list = ' + js2JSON(obj.selection_list) );
45                                                 if (obj.selection_list.length == 0) {
46                                                         obj.controller.view.sel_checkin.setAttribute('disabled','true');
47                                                         obj.controller.view.sel_edit.setAttribute('disabled','true');
48                                                         obj.controller.view.sel_opac.setAttribute('disabled','true');
49                                                         obj.controller.view.sel_patron.setAttribute('disabled','true');
50                                                         obj.controller.view.sel_bucket.setAttribute('disabled','true');
51                                                         obj.controller.view.sel_spine.setAttribute('disabled','true');
52                                                         obj.controller.view.sel_transit_abort.setAttribute('disabled','true');
53                                                 } else {
54                                                         obj.controller.view.sel_checkin.setAttribute('disabled','false');
55                                                         obj.controller.view.sel_edit.setAttribute('disabled','false');
56                                                         obj.controller.view.sel_opac.setAttribute('disabled','false');
57                                                         obj.controller.view.sel_patron.setAttribute('disabled','false');
58                                                         obj.controller.view.sel_bucket.setAttribute('disabled','false');
59                                                         obj.controller.view.sel_spine.setAttribute('disabled','false');
60                                                         obj.controller.view.sel_transit_abort.setAttribute('disabled','false');
61                                                 }
62                                         } catch(E) {
63                                                 alert('FIXME: ' + E);
64                                         }
65                                 },
66                         }
67                 );
68                 
69                 JSAN.use('util.controller'); obj.controller = new util.controller();
70                 obj.controller.init(
71                         {
72                                 'control_map' : {
73                                         'sel_checkin' : [
74                                                 ['command'],
75                                                 function() {
76                                                         try {
77                                                                 JSAN.use('circ.util');
78                                                                 for (var i = 0; i < obj.selection_list.length; i++) {
79                                                                         var barcode = obj.selection_list[i].barcode;
80                                                                         var checkin = circ.util.checkin_via_barcode( ses(), barcode );
81                                                                 }
82                                                         } catch(E) {
83                                                                 obj.error.standard_unexpected_error_alert('Checkin did not likely happen.',E);
84                                                         }
85                                                 }
86                                         ],
87                                         'sel_edit' : [
88                                                 ['command'],
89                                                 function() {
90                                                         try {
91                                                                 obj.spawn_copy_editor();
92                                                         } catch(E) {
93                                                                 alert(E);
94                                                         }
95                                                 }
96                                         ],
97                                         'sel_spine' : [
98                                                 ['command'],
99                                                 function() {
100                                                         try {
101                                                                 JSAN.use('util.functional');
102                                                                 xulG.new_tab(
103                                                                         xulG.url_prefix( urls.XUL_SPINE_LABEL ) + '?barcodes=' 
104                                                                         + js2JSON( util.functional.map_list(obj.selection_list,function(o){return o.barcode;}) ),
105                                                                         { 'tab_name' : 'Spine Labels' },
106                                                                         {}
107                                                                 );
108                                                         } catch(E) {
109                                                                 obj.error.standard_unexpected_error_alert('Spine Labels',E);
110                                                         }
111                                                 }
112                                         ],
113                                         'sel_opac' : [
114                                                 ['command'],
115                                                 function() {
116                                                         try {
117                                                                 for (var i = 0; i < obj.selection_list.length; i++) {
118                                                                         var doc_id = obj.selection_list[i].doc_id;
119                                                                         if (!doc_id) {
120                                                                                 alert(obj.selection_list[i].barcode + ' is not cataloged');
121                                                                                 continue;
122                                                                         }
123                                                                         var opac_url = xulG.url_prefix( urls.opac_rdetail ) + '?r=' + doc_id;
124                                                                         var content_params = { 
125                                                                                 'session' : ses(),
126                                                                                 'authtime' : ses('authtime'),
127                                                                                 'opac_url' : opac_url,
128                                                                         };
129                                                                         xulG.new_tab(
130                                                                                 xulG.url_prefix(urls.XUL_OPAC_WRAPPER), 
131                                                                                 {'tab_name':'Retrieving title...'}, 
132                                                                                 content_params
133                                                                         );
134                                                                 }
135                                                         } catch(E) {
136                                                                 obj.error.standard_unexpected_error_alert('',E);
137                                                         }
138                                                 }
139                                         ],
140                                         'sel_transit_abort' : [
141                                                 ['command'],
142                                                 function() {
143                                                         JSAN.use('util.functional');
144                                                         var msg = 'Are you sure you would like to abort transits for copies:' + util.functional.map_list( obj.selection_list, function(o){return o.copy_id;}).join(', ') + '?';
145                                                         var r = obj.error.yns_alert(msg,'Aborting Transits','Yes','No',null,'Check here to confirm this action');
146                                                         if (r == 0) {
147                                                                 try {
148                                                                         for (var i = 0; i < obj.selection_list.length; i++) {
149                                                                                 var copy_id = obj.selection_list[i].copy_id;
150                                                                                 var robj = obj.network.simple_request('FM_ATC_VOID',[ ses(), { 'copyid' : copy_id } ]);
151                                                                                 if (typeof robj.ilsevent != 'undefined') throw(robj);
152                                                                         }
153                                                                 } catch(E) {
154                                                                         obj.error.standard_unexpected_error_alert('Transit not likely aborted.',E);
155                                                                 }
156                                                         }
157                                                 }
158                                         ],
159                                         'sel_patron' : [
160                                                 ['command'],
161                                                 function() {
162                                                         var count = 5;
163                                                         JSAN.use('circ.util');
164                                                         circ.util.show_last_few_circs(obj.selection_list,count);
165                                                 }
166                                         ],
167                                         'sel_bucket' : [
168                                                 ['command'],
169                                                 function() {
170                                                         JSAN.use('util.functional');
171                                                         JSAN.use('util.window'); var win = new util.window();
172                                                         win.open( 
173                                                                 xulG.url_prefix(urls.XUL_COPY_BUCKETS) 
174                                                                 + '?copy_ids=' + js2JSON(
175                                                                         util.functional.map_list(
176                                                                                 obj.selection_list,
177                                                                                 function (o) {
178                                                                                         return o.copy_id;
179                                                                                 }
180                                                                         )
181                                                                 ),
182                                                                 'sel_bucket_win' + win.window_name_increment(),
183                                                                 'chrome,resizable,modal,center'
184                                                         );
185                                                 }
186                                         ],
187                                         'copy_status_barcode_entry_textbox' : [
188                                                 ['keypress'],
189                                                 function(ev) {
190                                                         if (ev.keyCode && ev.keyCode == 13) {
191                                                                 obj.copy_status();
192                                                         }
193                                                 }
194                                         ],
195                                         'cmd_broken' : [
196                                                 ['command'],
197                                                 function() { alert('Not Yet Implemented'); }
198                                         ],
199                                         'cmd_copy_status_submit_barcode' : [
200                                                 ['command'],
201                                                 function() {
202                                                         obj.copy_status();
203                                                 }
204                                         ],
205                                         'cmd_copy_status_print' : [
206                                                 ['command'],
207                                                 function() {
208                                                         try {
209                                                         dump( js2JSON( obj.list.dump() ) + '\n' );
210                                                         obj.data.stash_retrieve();
211                                                         var lib = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
212                                                         lib.children(null);
213                                                         var p = { 
214                                                                 'lib' : lib,
215                                                                 'staff' : obj.data.list.au[0],
216                                                                 'header' : obj.data.print_list_templates.item_status.header,
217                                                                 'line_item' : obj.data.print_list_templates.item_status.line_item,
218                                                                 'footer' : obj.data.print_list_templates.item_status.footer,
219                                                                 'type' : obj.data.print_list_templates.item_status.type,
220                                                                 'list' : obj.list.dump(),
221                                                         };
222                                                         JSAN.use('util.print'); var print = new util.print();
223                                                         print.tree_list( p );
224                                                         } catch(E) {
225                                                                 alert(E); 
226                                                         }
227                                                 }
228                                         ],
229                                         'cmd_copy_status_reprint' : [
230                                                 ['command'],
231                                                 function() {
232                                                 }
233                                         ],
234                                         'cmd_copy_status_done' : [
235                                                 ['command'],
236                                                 function() {
237                                                 }
238                                         ],
239                                 }
240                         }
241                 );
242                 this.controller.render();
243                 this.controller.view.copy_status_barcode_entry_textbox.focus();
244
245         },
246
247         'copy_status' : function(barcode) {
248                 var obj = this;
249                 try {
250                         if (!barcode) barcode = obj.controller.view.copy_status_barcode_entry_textbox.value;
251                         JSAN.use('circ.util');
252                         var copy = obj.network.simple_request( 'FM_ACP_RETRIEVE_VIA_BARCODE', [ barcode ]);
253                         if (copy == null) {
254                                 throw('Something weird happened.  null result');
255                         } else if (copy.ilsevent) {
256                                 switch(copy.ilsevent) {
257                                         case -1: 
258                                                 obj.error.standard_network_error_alert(); 
259                                                 obj.controller.view.copy_status_barcode_entry_textbox.select();
260                                                 obj.controller.view.copy_status_barcode_entry_textbox.focus();
261                                         break;
262                                         case 1502 /* ASSET_COPY_NOT_FOUND */ :
263                                                 obj.error.yns_alert(barcode + ' was either mis-scanned or is not cataloged.','Not Cataloged','OK',null,null,'Check here to confirm this message');
264                                                 obj.controller.view.copy_status_barcode_entry_textbox.select();
265                                                 obj.controller.view.copy_status_barcode_entry_textbox.focus();
266                                         break;
267                                         default: 
268                                                 throw(copy); 
269                                         break;
270                                 }
271                         } else {
272                                 var my_mvr = obj.network.simple_request('MODS_SLIM_RECORD_RETRIEVE_VIA_COPY', [ copy.id() ]);
273                                 obj.list.append(
274                                         {
275                                                 'retrieve_id' : js2JSON( { 'copy_id' : copy.id(), 'barcode' : barcode, 'doc_id' : (typeof my_mvr.ilsevent == 'undefined' ? my_mvr.doc_id() : null ) } ),
276                                                 'row' : {
277                                                         'my' : {
278                                                                 'mvr' : my_mvr,
279                                                                 'acp' : copy,
280                                                         }
281                                                 }
282                                         }
283                                 );
284                                 obj.controller.view.copy_status_barcode_entry_textbox.value = '';
285                                 obj.controller.view.copy_status_barcode_entry_textbox.focus();
286                         }
287                 } catch(E) {
288                         obj.error.standard_unexpected_error_alert('',E);
289                         obj.controller.view.copy_status_barcode_entry_textbox.select();
290                         obj.controller.view.copy_status_barcode_entry_textbox.focus();
291                 }
292
293         },
294         
295         'spawn_copy_editor' : function() {
296
297                 /* FIXME -  a lot of redundant calls here */
298
299                 var obj = this;
300
301                 JSAN.use('util.widgets'); JSAN.use('util.functional');
302
303                 var list = obj.selection_list;
304
305                 list = util.functional.map_list(
306                         list,
307                         function (o) {
308                                 return o.copy_id;
309                         }
310                 );
311
312                 var copies = util.functional.map_list(
313                         list,
314                         function (acp_id) {
315                                 return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]);
316                         }
317                 );
318
319                 var edit = 0;
320                 try {
321                         edit = obj.network.request(
322                                 api.PERM_MULTI_ORG_CHECK.app,
323                                 api.PERM_MULTI_ORG_CHECK.method,
324                                 [ 
325                                         ses(), 
326                                         obj.data.list.au[0].id(), 
327                                         util.functional.map_list(
328                                                 copies,
329                                                 function (o) {
330                                                         return obj.network.simple_request('FM_ACN_RETRIEVE',[o.call_number()]).owning_lib();
331                                                 }
332                                         ),
333                                         [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
334                                 ]
335                         ).length == 0 ? 1 : 0;
336                 } catch(E) {
337                         obj.error.sdump('D_ERROR','batch permission check: ' + E);
338                 }
339
340                 JSAN.use('cat.util'); cat.util.spawn_copy_editor(list,edit);
341
342         },
343
344 }
345
346 dump('exiting circ.copy_status.js\n');