]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/cat/util.js
replace barcode entry points
[Evergreen.git] / Open-ILS / xul / staff_client / server / cat / util.js
1 dump('entering cat/util.js\n');
2
3 if (typeof cat == 'undefined') var cat = {};
4 cat.util = {};
5
6 cat.util.EXPORT_OK      = [ 
7         'spawn_copy_editor', 'add_copies_to_bucket', 'show_in_opac', 'spawn_spine_editor', 'transfer_copies', 
8         'mark_item_missing', 'mark_item_damaged', 'replace_barcode',
9 ];
10 cat.util.EXPORT_TAGS    = { ':all' : cat.util.EXPORT_OK };
11
12 cat.util.replace_barcode = function(old_bc) {
13         try {
14                 JSAN.use('util.network');
15                 var network = new util.network();
16
17                 if (!old_bc) old_bc = window.prompt('Enter original barcode for the copy:','','Replace Barcode');
18                 if (!old_bc) return;
19
20                 var copy = network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[ old_bc ]);
21                 if (typeof copy.ilsevent != 'undefined') throw(copy); 
22                 if (!copy) throw(copy);
23
24                 // Why did I want to do this twice?  Because this copy is more fleshed?
25                 copy = network.simple_request('FM_ACP_RETRIEVE',[ copy.id() ]);
26                 if (typeof copy.ilsevent != 'undefined') throw(copy);
27                 if (!copy) throw(copy);
28
29                 var new_bc = window.prompt('Enter the replacement barcode for the copy with barcode ' + old_bc + ':','','Replace Barcode');
30
31                 var test = network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[ ses(), new_bc ]);
32                 if (typeof test.ilsevent == 'undefined') {
33                         alert('Rename aborted.  Another copy has that barcode');
34                         return;
35                 }
36                 copy.barcode(new_bc); copy.ischanged('1');
37                 var r = network.simple_request('FM_ACP_FLESHED_BATCH_UPDATE', [ ses(), [ copy ] ]);
38                 if (typeof r.ilsevent != 'undefined') { if (r.ilsevent != 0) throw(r); }
39         } catch(E) {
40                 JSAN.use('util.error'); var error = new util.error();
41                 error.standard_unexpected_error_alert('Rename did not likely occur.',E);
42         }
43 }
44
45 cat.util.transfer_copies = function(params) {
46         JSAN.use('util.error'); var error = new util.error();
47         JSAN.use('OpenILS.data'); var data = new OpenILS.data();
48         JSAN.use('util.network'); var network = new util.network();
49         try {
50                 data.stash_retrieve();
51                 if (!data.marked_volume) {
52                         alert('Please mark a volume as the destination from within holdings maintenance and then try this again.');
53                         return;
54                 }
55                 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
56                 var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: auto">';
57                 if (!params.message) {
58                         params.message = 'Transfer items from their original volumes to ';
59                         params.message += data.hash.aou[ params.owning_lib ].shortname() + "'s volume labelled ";
60                         params.message += '"' + params.volume_label + '" on the following record (and change their circ libs to match)?';
61                 }
62
63                 xml += '<description>' + params.message + '</description>';
64                 xml += '<hbox><button label="Transfer" name="fancy_submit"/>';
65                 xml += '<button label="Cancel" accesskey="C" name="fancy_cancel"/></hbox>';
66                 xml += '<iframe style="overflow: scroll" flex="1" src="' + urls.XUL_BIB_BRIEF + '?docid=' + params.docid + '"/>';
67                 xml += '</vbox>';
68                 data.temp_transfer = xml; data.stash('temp_transfer');
69                 window.open(
70                         urls.XUL_FANCY_PROMPT
71                         + '?xml_in_stash=temp_transfer'
72                         + '&title=' + window.escape('Item Transfer'),
73                         'fancy_prompt', 'chrome,resizable,modal,width=500,height=300'
74                 );
75                 data.stash_retrieve();
76                 if (data.fancy_prompt_data == '') { alert('Transfer Aborted'); return; }
77
78                 JSAN.use('util.functional');
79
80                 var copies = network.simple_request('FM_ACP_FLESHED_BATCH_RETRIEVE', [ params.copy_ids ]);
81
82                 for (var i = 0; i < copies.length; i++) {
83                         copies[i].call_number( data.marked_volume );
84                         copies[i].circ_lib( params.owning_lib );
85                         copies[i].ischanged( 1 );
86                 }
87
88                 var robj = network.simple_request(
89                         'FM_ACP_FLESHED_BATCH_UPDATE', 
90                         [ ses(), copies, true ], 
91                         null,
92                         {
93                                 'title' : 'Override Transfer Failure?',
94                                 'overridable_events' : [
95                                         1208 /* TITLE_LAST_COPY */,
96                                 ]
97                         }
98                 );
99                 
100                 if (typeof robj.ilsevent != 'undefined') {
101                         throw(robj);
102                 } else {
103                         alert('Items transferred.');
104                 }
105
106         } catch(E) {
107                 error.standard_unexpected_error_alert('All items not likely transferred.',E);
108         }
109 }
110
111 cat.util.spawn_spine_editor = function(selection_list) {
112         JSAN.use('util.error'); var error = new util.error();
113         try {
114                 JSAN.use('util.functional');
115                 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.stash_retrieve();
116                 data.temp_barcodes_for_labels = util.functional.map_list( selection_list, function(o){return o.barcode;}) ; 
117                 data.stash('temp_barcodes_for_labels');
118                 xulG.new_tab(
119                         xulG.url_prefix( urls.XUL_SPINE_LABEL ),
120                         { 'tab_name' : 'Spine Labels' },
121                         {}
122                 );
123         } catch(E) {
124                 error.standard_unexpected_error_alert('Spine Labels',E);
125         }
126 }
127
128 cat.util.show_in_opac = function(selection_list) {
129         JSAN.use('util.error'); var error = new util.error();
130         var doc_id; var seen = {};
131         try {
132                 for (var i = 0; i < selection_list.length; i++) {
133                         doc_id = selection_list[i].doc_id;
134                         if (!doc_id) {
135                                 alert(selection_list[i].barcode + ' is not cataloged');
136                                 continue;
137                         }
138                         if (typeof seen[doc_id] != 'undefined') {
139                                 continue;
140                         }
141                         seen[doc_id] = true;
142                         var opac_url = xulG.url_prefix( urls.opac_rdetail ) + '?r=' + doc_id;
143                         var content_params = { 
144                                 'session' : ses(),
145                                 'authtime' : ses('authtime'),
146                                 'opac_url' : opac_url,
147                         };
148                         xulG.new_tab(
149                                 xulG.url_prefix(urls.XUL_OPAC_WRAPPER), 
150                                 {'tab_name':'Retrieving title...'}, 
151                                 content_params
152                         );
153                 }
154         } catch(E) {
155                 error.standard_unexpected_error_alert('Error opening catalog for document id = ' + doc_id,E);
156         }
157 }
158
159 cat.util.add_copies_to_bucket = function(selection_list) {
160         JSAN.use('util.functional');
161         JSAN.use('util.window'); var win = new util.window();
162         JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
163         data.cb_temp_copy_ids = js2JSON(
164                 util.functional.map_list(
165                         selection_list,
166                         function (o) {
167                                 if (typeof o.copy_id != 'undefined' && o.copy_id != null) {
168                                         return o.copy_id;
169                                 } else {
170                                         return o;
171                                 }
172                         }
173                 )
174         );
175         data.stash('cb_temp_copy_ids');
176         win.open( 
177                 xulG.url_prefix(urls.XUL_COPY_BUCKETS_QUICK),
178                 'sel_bucket_win' + win.window_name_increment(),
179                 'chrome,resizable,center'
180         );
181 }
182
183 cat.util.spawn_copy_editor = function(list,edit) {
184         try {
185         var obj = {};
186         JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
187         JSAN.use('util.network'); obj.network = new util.network();
188         JSAN.use('util.error'); obj.error = new util.error();
189
190         var title = list.length == 1 ? '' : 'Batch '; 
191         title += edit == 1 ? 'Edit' : 'View';
192         title += ' Copy Attributes';
193
194         JSAN.use('util.window'); var win = new util.window();
195         obj.data.temp_copies = undefined; obj.data.stash('temp_copies');
196         obj.data.temp_callnumbers = undefined; obj.data.stash('temp_callnumbers');
197         obj.data.temp_copy_ids = js2JSON(list);
198         obj.data.stash('temp_copy_ids');
199         var w = win.open(
200                 window.xulG.url_prefix(urls.XUL_COPY_EDITOR)
201                         +'?edit='+edit,
202                 title,
203                 'chrome,modal,resizable'
204         );
205         /* FIXME -- need to unique the temp space, and not rely on modalness of window */
206         obj.data.stash_retrieve();
207         if (!obj.data.temp_copies) return;
208         var copies = JSON2js( obj.data.temp_copies );
209         obj.data.temp_copies = undefined; obj.data.stash('temp_copies');
210         obj.data.temp_callnumbers = undefined; obj.data.stash('temp_callnumbers');
211         obj.data.temp_copy_ids = undefined; obj.data.stash('temp_copy_ids');
212         obj.error.sdump('D_CAT','in cat/copy_status, copy editor, copies =\n<<' + copies + '>>');
213         if (edit=='1' && copies!='' && typeof copies != 'undefined') {
214                 try {
215                         var r = obj.network.request(
216                                 api.FM_ACP_FLESHED_BATCH_UPDATE.app,
217                                 api.FM_ACP_FLESHED_BATCH_UPDATE.method,
218                                 [ ses(), copies, true ]
219                         );
220                         /* FIXME -- revisit the return value here */
221                 } catch(E) {
222                         obj.error.standard_unexpected_error_alert('copy update error',E);
223                 }
224         } else {
225                 //alert('not updating');
226         }
227         } catch(E) {
228                 alert(E);
229         }
230 }
231
232 cat.util.mark_item_damaged = function(copy_ids) {
233         var error;
234         try {
235                 JSAN.use('util.error'); error = new util.error();
236                 JSAN.use('util.functional');
237                 JSAN.use('util.network'); var network = new util.network();
238                 var copies = network.simple_request('FM_ACP_FLESHED_BATCH_RETRIEVE', [ copy_ids ]);
239                 if (typeof copies.ilsevent != 'undefined') throw(copies);
240                 var magic_status = false;
241                 for (var i = 0; i < copies.length; i++) {
242                         var status = copies[i].status(); if (typeof status == 'object') status = status.id();
243                         if (typeof my_constants.magical_statuses[ status ] != 'undefined') 
244                                 if (my_constants.magical_statuses[ status ].block_mark_item_action) magic_status = true;
245                 }
246                 if (magic_status) {
247                 
248                         error.yns_alert('Action failed.  One or more of these items is in a special status (Checked Out, In Transit, etc.) and cannot be changed to the Damaged status.','Action failed.','OK',null,null,'Check here to confirm this message');
249
250                 } else {
251
252                         var r = error.yns_alert('Change the status for these items to Damaged?  You will have to manually retrieve the last circulation if you need to bill a patron.  Barcodes: ' + util.functional.map_list( copies, function(o) { return o.barcode(); } ).join(", "), 'Mark Damaged', 'OK', 'Cancel', null, 'Check here to confirm this action');
253
254                         if (r == 0) {
255                                 var count = 0;
256                                 for (var i = 0; i < copies.length; i++) {
257                                         try {
258                                                 var robj = network.simple_request('MARK_ITEM_DAMAGED',[ses(),copies[i].id()]);
259                                                 if (typeof robj.ilsevent != 'undefined') throw(robj);
260                                                 count++;
261                                         } catch(E) {
262                                                 error.standard_unexpected_error_alert('Error marking item ' + copies[i].barcode() + ' damaged.',E);
263                                         }
264                                 }
265                                 alert(count == 1 ? 'Item marked Damaged' : count + ' items marked Damaged.');
266                         }
267                 }
268
269         } catch(E) {
270                 if (error) error.standard_unexpected_error_alert('cat.util.mark_item_damaged',E); else alert('FIXME: ' + E);
271         }
272 }
273
274 cat.util.mark_item_missing = function(copy_ids) {
275         var error;
276         try {
277                 JSAN.use('util.error'); error = new util.error();
278                 JSAN.use('util.functional');
279                 JSAN.use('util.network'); var network = new util.network();
280                 var copies = network.simple_request('FM_ACP_FLESHED_BATCH_RETRIEVE', [ copy_ids ]);
281                 if (typeof copies.ilsevent != 'undefined') throw(copies);
282                 var magic_status = false;
283                 for (var i = 0; i < copies.length; i++) {
284                         var status = copies[i].status(); if (typeof status == 'object') status = status.id();
285                         if (typeof my_constants.magical_statuses[ status ] != 'undefined') 
286                                 if (my_constants.magical_statuses[ status ].block_mark_item_action) magic_status = true;
287                 }
288                 if (magic_status) {
289                 
290                         error.yns_alert('Action failed.  One or more of these items is in a special status (Checked Out, In Transit, etc.) and cannot be changed to the Missing status.','Action failed.','OK',null,null,'Check here to confirm this message');
291
292                 } else {
293
294                         var r = error.yns_alert('Change the status for these items to Missing?  Barcodes: ' + util.functional.map_list( copies, function(o) { return o.barcode(); } ).join(", "), 'Mark Missing', 'OK', 'Cancel', null, 'Check here to confirm this action');
295
296                         if (r == 0) {
297                                 var count = 0;
298                                 for (var i = 0; i < copies.length; i++) {
299                                         try {
300                                                 var robj = network.simple_request('MARK_ITEM_MISSING',[ses(),copies[i].id()]);
301                                                 if (typeof robj.ilsevent != 'undefined') throw(robj);
302                                                 count++;
303                                         } catch(E) {
304                                                 error.standard_unexpected_error_alert('Error marking item ' + copies[i].barcode() + ' missing.',E);
305                                         }
306                                 }
307                                 alert(count == 1 ? 'Item marked Missing' : count + ' items marked Missing.');
308                         }
309                 }
310
311         } catch(E) {
312                 if (error) error.standard_unexpected_error_alert('cat.util.mark_item_missing',E); else alert('FIXME: ' + E);
313         }
314 }
315
316
317 dump('exiting cat/util.js\n');