]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/copy_status.js
printing on an all_fleshed callback..need to do this for other print actions
[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                                                         JSAN.use('cat.util');
101                                                         cat.util.spawn_spine_editor(obj.selection_list);
102                                                 }
103                                         ],
104                                         'sel_opac' : [
105                                                 ['command'],
106                                                 function() {
107                                                         JSAN.use('cat.util');
108                                                         cat.util.show_in_opac(obj.selection_list);
109                                                 }
110                                         ],
111                                         'sel_transit_abort' : [
112                                                 ['command'],
113                                                 function() {
114                                                         JSAN.use('circ.util');
115                                                         circ.util.abort_transits(obj.selection_list);
116                                                 }
117                                         ],
118                                         'sel_patron' : [
119                                                 ['command'],
120                                                 function() {
121                                                         JSAN.use('circ.util');
122                                                         circ.util.show_last_few_circs(obj.selection_list);
123                                                 }
124                                         ],
125                                         'sel_bucket' : [
126                                                 ['command'],
127                                                 function() {
128                                                         JSAN.use('cat.util');
129                                                         cat.util.add_copies_to_bucket(obj.selection_list);
130                                                 }
131                                         ],
132                                         'copy_status_barcode_entry_textbox' : [
133                                                 ['keypress'],
134                                                 function(ev) {
135                                                         if (ev.keyCode && ev.keyCode == 13) {
136                                                                 obj.copy_status();
137                                                         }
138                                                 }
139                                         ],
140                                         'cmd_broken' : [
141                                                 ['command'],
142                                                 function() { alert('Not Yet Implemented'); }
143                                         ],
144                                         'cmd_copy_status_submit_barcode' : [
145                                                 ['command'],
146                                                 function() {
147                                                         obj.copy_status();
148                                                 }
149                                         ],
150                                         'cmd_copy_status_print' : [
151                                                 ['command'],
152                                                 function() {
153                                                         try {
154                                                                 obj.list.on_all_fleshed =
155                                                                         function() {
156                                                                                 try {
157                                                                                         dump( js2JSON( obj.list.dump() ) + '\n' );
158                                                                                         obj.data.stash_retrieve();
159                                                                                         var lib = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
160                                                                                         lib.children(null);
161                                                                                         var p = { 
162                                                                                                 'lib' : lib,
163                                                                                                 'staff' : obj.data.list.au[0],
164                                                                                                 'header' : obj.data.print_list_templates.item_status.header,
165                                                                                                 'line_item' : obj.data.print_list_templates.item_status.line_item,
166                                                                                                 'footer' : obj.data.print_list_templates.item_status.footer,
167                                                                                                 'type' : obj.data.print_list_templates.item_status.type,
168                                                                                                 'list' : obj.list.dump(),
169                                                                                         };
170                                                                                         JSAN.use('util.print'); var print = new util.print();
171                                                                                         print.tree_list( p );
172                                                                                         setTimeout(function(){ obj.list.on_all_fleshed = null; },0);
173                                                                                 } catch(E) {
174                                                                                         obj.error.standard_unexpected_error_alert('print',E); 
175                                                                                 }
176                                                                         }
177                                                                 obj.list.full_retrieve();
178                                                         } catch(E) {
179                                                                 obj.error.standard_unexpected_error_alert('print',E); 
180                                                         }
181                                                 }
182                                         ],
183                                         'cmd_copy_status_reprint' : [
184                                                 ['command'],
185                                                 function() {
186                                                 }
187                                         ],
188                                         'cmd_copy_status_done' : [
189                                                 ['command'],
190                                                 function() {
191                                                 }
192                                         ],
193                                 }
194                         }
195                 );
196                 this.controller.render();
197                 this.controller.view.copy_status_barcode_entry_textbox.focus();
198
199         },
200
201         'copy_status' : function(barcode) {
202                 var obj = this;
203                 try {
204                         if (!barcode) barcode = obj.controller.view.copy_status_barcode_entry_textbox.value;
205                         JSAN.use('circ.util');
206                         var copy = obj.network.simple_request( 'FM_ACP_RETRIEVE_VIA_BARCODE', [ barcode ]);
207                         if (copy == null) {
208                                 throw('Something weird happened.  null result');
209                         } else if (copy.ilsevent) {
210                                 switch(copy.ilsevent) {
211                                         case -1: 
212                                                 obj.error.standard_network_error_alert(); 
213                                                 obj.controller.view.copy_status_barcode_entry_textbox.select();
214                                                 obj.controller.view.copy_status_barcode_entry_textbox.focus();
215                                         break;
216                                         case 1502 /* ASSET_COPY_NOT_FOUND */ :
217                                                 obj.error.yns_alert(barcode + ' was either mis-scanned or is not cataloged.','Not Cataloged','OK',null,null,'Check here to confirm this message');
218                                                 obj.controller.view.copy_status_barcode_entry_textbox.select();
219                                                 obj.controller.view.copy_status_barcode_entry_textbox.focus();
220                                         break;
221                                         default: 
222                                                 throw(copy); 
223                                         break;
224                                 }
225                         } else {
226                                 var my_mvr = obj.network.simple_request('MODS_SLIM_RECORD_RETRIEVE_VIA_COPY', [ copy.id() ]);
227                                 obj.list.append(
228                                         {
229                                                 'retrieve_id' : js2JSON( { 'copy_id' : copy.id(), 'barcode' : barcode, 'doc_id' : (typeof my_mvr.ilsevent == 'undefined' ? my_mvr.doc_id() : null ) } ),
230                                                 'row' : {
231                                                         'my' : {
232                                                                 'mvr' : my_mvr,
233                                                                 'acp' : copy,
234                                                         }
235                                                 }
236                                         }
237                                 );
238                                 obj.controller.view.copy_status_barcode_entry_textbox.value = '';
239                                 obj.controller.view.copy_status_barcode_entry_textbox.focus();
240                         }
241                 } catch(E) {
242                         obj.error.standard_unexpected_error_alert('',E);
243                         obj.controller.view.copy_status_barcode_entry_textbox.select();
244                         obj.controller.view.copy_status_barcode_entry_textbox.focus();
245                 }
246
247         },
248         
249         'spawn_copy_editor' : function() {
250
251                 /* FIXME -  a lot of redundant calls here */
252
253                 var obj = this;
254
255                 JSAN.use('util.widgets'); JSAN.use('util.functional');
256
257                 var list = obj.selection_list;
258
259                 list = util.functional.map_list(
260                         list,
261                         function (o) {
262                                 return o.copy_id;
263                         }
264                 );
265
266                 var copies = util.functional.map_list(
267                         list,
268                         function (acp_id) {
269                                 return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]);
270                         }
271                 );
272
273                 var edit = 0;
274                 try {
275                         edit = obj.network.request(
276                                 api.PERM_MULTI_ORG_CHECK.app,
277                                 api.PERM_MULTI_ORG_CHECK.method,
278                                 [ 
279                                         ses(), 
280                                         obj.data.list.au[0].id(), 
281                                         util.functional.map_list(
282                                                 copies,
283                                                 function (o) {
284                                                         return obj.network.simple_request('FM_ACN_RETRIEVE',[o.call_number()]).owning_lib();
285                                                 }
286                                         ),
287                                         [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
288                                 ]
289                         ).length == 0 ? 1 : 0;
290                 } catch(E) {
291                         obj.error.sdump('D_ERROR','batch permission check: ' + E);
292                 }
293
294                 JSAN.use('cat.util'); cat.util.spawn_copy_editor(list,edit);
295
296         },
297
298 }
299
300 dump('exiting circ.copy_status.js\n');