1 dump('entering cat/util.js\n');
3 if (typeof cat == 'undefined') var cat = {};
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',
10 cat.util.EXPORT_TAGS = { ':all' : cat.util.EXPORT_OK };
12 cat.util.replace_barcode = function(old_bc) {
14 JSAN.use('util.network');
15 var network = new util.network();
17 if (!old_bc) old_bc = window.prompt('Enter original barcode for the copy:','','Replace Barcode');
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);
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);
29 var new_bc = window.prompt('Enter the replacement barcode for the copy with barcode ' + old_bc + ':','','Replace Barcode');
31 alert('Rename aborted. Blank for barcode not allowed.');
35 var test = network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[ ses(), new_bc ]);
36 if (typeof test.ilsevent == 'undefined') {
37 alert('Rename aborted. Another copy has that barcode');
40 copy.barcode(new_bc); copy.ischanged('1');
41 var r = network.simple_request('FM_ACP_FLESHED_BATCH_UPDATE', [ ses(), [ copy ] ]);
42 if (typeof r.ilsevent != 'undefined') { if (r.ilsevent != 0) throw(r); }
45 JSAN.use('util.error'); var error = new util.error();
46 error.standard_unexpected_error_alert('Rename did not likely occur.',E);
50 cat.util.transfer_copies = function(params) {
51 JSAN.use('util.error'); var error = new util.error();
52 JSAN.use('OpenILS.data'); var data = new OpenILS.data();
53 JSAN.use('util.network'); var network = new util.network();
55 data.stash_retrieve();
56 if (!data.marked_volume) {
57 alert('Please mark a volume as the destination from within holdings maintenance and then try this again.');
60 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
61 var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: auto">';
62 if (!params.message) {
63 params.message = 'Transfer items from their original volumes to ';
64 params.message += data.hash.aou[ params.owning_lib ].shortname() + "'s volume labelled ";
65 params.message += '"' + params.volume_label + '" on the following record (and change their circ libs to match)?';
68 xml += '<description>' + params.message.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>') + '</description>';
69 xml += '<hbox><button label="Transfer" name="fancy_submit"/>';
70 xml += '<button label="Cancel" accesskey="C" name="fancy_cancel"/></hbox>';
71 xml += '<iframe style="overflow: scroll" flex="1" src="' + urls.XUL_BIB_BRIEF + '?docid=' + params.docid + '"/>';
73 data.temp_transfer = xml; data.stash('temp_transfer');
76 + '?xml_in_stash=temp_transfer'
77 + '&title=' + window.escape('Item Transfer'),
78 'fancy_prompt', 'chrome,resizable,modal,width=500,height=300'
80 data.stash_retrieve();
81 if (data.fancy_prompt_data == '') { alert('Transfer Aborted'); return; }
83 JSAN.use('util.functional');
85 var copies = network.simple_request('FM_ACP_FLESHED_BATCH_RETRIEVE', [ params.copy_ids ]);
87 for (var i = 0; i < copies.length; i++) {
88 copies[i].call_number( data.marked_volume );
89 copies[i].circ_lib( params.owning_lib );
90 copies[i].ischanged( 1 );
93 var robj = network.simple_request(
94 'FM_ACP_FLESHED_BATCH_UPDATE',
95 [ ses(), copies, true ],
98 'title' : 'Override Transfer Failure?',
99 'overridable_events' : [
100 1208 /* TITLE_LAST_COPY */,
101 1227 /* COPY_DELETE_WARNING */,
106 if (typeof robj.ilsevent != 'undefined') {
109 alert('Items transferred.');
113 error.standard_unexpected_error_alert('All items not likely transferred.',E);
117 cat.util.spawn_spine_editor = function(selection_list) {
118 JSAN.use('util.error'); var error = new util.error();
120 JSAN.use('util.functional');
121 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.stash_retrieve();
122 data.temp_barcodes_for_labels = util.functional.map_list( selection_list, function(o){return o.barcode;}) ;
123 data.stash('temp_barcodes_for_labels');
125 xulG.url_prefix( urls.XUL_SPINE_LABEL ),
126 { 'tab_name' : 'Spine Labels' },
130 error.standard_unexpected_error_alert('Spine Labels',E);
134 cat.util.show_in_opac = function(selection_list) {
135 JSAN.use('util.error'); var error = new util.error();
136 var doc_id; var seen = {};
138 for (var i = 0; i < selection_list.length; i++) {
139 doc_id = selection_list[i].doc_id;
141 alert(selection_list[i].barcode + ' is not cataloged');
144 if (typeof seen[doc_id] != 'undefined') {
148 var opac_url = xulG.url_prefix( urls.opac_rdetail ) + '?r=' + doc_id;
149 var content_params = {
151 'authtime' : ses('authtime'),
152 'opac_url' : opac_url,
155 xulG.url_prefix(urls.XUL_OPAC_WRAPPER),
156 {'tab_name':'Retrieving title...'},
161 error.standard_unexpected_error_alert('Error opening catalog for document id = ' + doc_id,E);
165 cat.util.add_copies_to_bucket = function(selection_list) {
166 JSAN.use('util.functional');
167 JSAN.use('util.window'); var win = new util.window();
168 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
169 data.cb_temp_copy_ids = js2JSON(
170 util.functional.map_list(
173 if (typeof o.copy_id != 'undefined' && o.copy_id != null) {
181 data.stash('cb_temp_copy_ids');
183 xulG.url_prefix(urls.XUL_COPY_BUCKETS_QUICK),
184 'sel_bucket_win' + win.window_name_increment(),
185 'chrome,resizable,center'
189 cat.util.spawn_copy_editor = function(list,edit) {
192 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
193 JSAN.use('util.network'); obj.network = new util.network();
194 JSAN.use('util.error'); obj.error = new util.error();
196 var title = list.length == 1 ? '' : 'Batch ';
197 title += edit == 1 ? 'Edit' : 'View';
198 title += ' Copy Attributes';
200 JSAN.use('util.window'); var win = new util.window();
201 obj.data.temp_copies = undefined; obj.data.stash('temp_copies');
202 obj.data.temp_callnumbers = undefined; obj.data.stash('temp_callnumbers');
203 obj.data.temp_copy_ids = js2JSON(list);
204 obj.data.stash('temp_copy_ids');
206 window.xulG.url_prefix(urls.XUL_COPY_EDITOR)
209 'chrome,modal,resizable'
211 /* FIXME -- need to unique the temp space, and not rely on modalness of window */
212 obj.data.stash_retrieve();
213 if (!obj.data.temp_copies) return;
214 var copies = JSON2js( obj.data.temp_copies );
215 obj.data.temp_copies = undefined; obj.data.stash('temp_copies');
216 obj.data.temp_callnumbers = undefined; obj.data.stash('temp_callnumbers');
217 obj.data.temp_copy_ids = undefined; obj.data.stash('temp_copy_ids');
218 obj.error.sdump('D_CAT','in cat/copy_status, copy editor, copies =\n<<' + copies + '>>');
219 if (edit=='1' && copies!='' && typeof copies != 'undefined') {
221 var r = obj.network.request(
222 api.FM_ACP_FLESHED_BATCH_UPDATE.app,
223 api.FM_ACP_FLESHED_BATCH_UPDATE.method,
224 [ ses(), copies, true ]
226 if (typeof r.ilsevent != 'undefined') {
227 if (r.ilsevent != 0) throw(r);
229 alert('Copies modified.');
231 obj.error.standard_unexpected_error_alert('copy update error',E);
234 if (edit=='1') alert('Copies not modified.');
241 cat.util.mark_item_damaged = function(copy_ids) {
244 JSAN.use('util.error'); error = new util.error();
245 JSAN.use('util.functional');
246 JSAN.use('util.network'); var network = new util.network();
247 var copies = network.simple_request('FM_ACP_FLESHED_BATCH_RETRIEVE', [ copy_ids ]);
248 if (typeof copies.ilsevent != 'undefined') throw(copies);
249 var magic_status = false;
250 for (var i = 0; i < copies.length; i++) {
251 var status = copies[i].status(); if (typeof status == 'object') status = status.id();
252 if (typeof my_constants.magical_statuses[ status ] != 'undefined')
253 if (my_constants.magical_statuses[ status ].block_mark_item_action) magic_status = true;
257 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');
261 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');
265 for (var i = 0; i < copies.length; i++) {
267 var robj = network.simple_request('MARK_ITEM_DAMAGED',[ses(),copies[i].id()]);
268 if (typeof robj.ilsevent != 'undefined') throw(robj);
271 error.standard_unexpected_error_alert('Error marking item ' + copies[i].barcode() + ' damaged.',E);
274 alert(count == 1 ? 'Item marked Damaged' : count + ' items marked Damaged.');
279 if (error) error.standard_unexpected_error_alert('cat.util.mark_item_damaged',E); else alert('FIXME: ' + E);
283 cat.util.mark_item_missing = function(copy_ids) {
286 JSAN.use('util.error'); error = new util.error();
287 JSAN.use('util.functional');
288 JSAN.use('util.network'); var network = new util.network();
289 var copies = network.simple_request('FM_ACP_FLESHED_BATCH_RETRIEVE', [ copy_ids ]);
290 if (typeof copies.ilsevent != 'undefined') throw(copies);
291 var magic_status = false;
292 for (var i = 0; i < copies.length; i++) {
293 var status = copies[i].status(); if (typeof status == 'object') status = status.id();
294 if (typeof my_constants.magical_statuses[ status ] != 'undefined')
295 if (my_constants.magical_statuses[ status ].block_mark_item_action) magic_status = true;
299 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');
303 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');
307 for (var i = 0; i < copies.length; i++) {
309 var robj = network.simple_request('MARK_ITEM_MISSING',[ses(),copies[i].id()]);
310 if (typeof robj.ilsevent != 'undefined') throw(robj);
313 error.standard_unexpected_error_alert('Error marking item ' + copies[i].barcode() + ' missing.',E);
316 alert(count == 1 ? 'Item marked Missing' : count + ' items marked Missing.');
321 if (error) error.standard_unexpected_error_alert('cat.util.mark_item_missing',E); else alert('FIXME: ' + E);
326 dump('exiting cat/util.js\n');