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