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');
22 copy = network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[ old_bc ]);
23 if (typeof copy.ilsevent != 'undefined') throw(copy);
24 if (!copy) throw(copy);
26 alert('We were unable to retrieve an item with barcode "' + old_bc + '".\n');
30 // Why did I want to do this twice? Because this copy is more fleshed?
32 copy = network.simple_request('FM_ACP_RETRIEVE',[ copy.id() ]);
33 if (typeof copy.ilsevent != 'undefined') throw(copy);
34 if (!copy) throw(copy);
36 try { alert('We were unable to retrieve an item with barcode "' + old_bc + '".\n' + (typeof E.ilsevent == 'undefined' ? '' : E.textcode + ' : ' + E.desc)); } catch(F) { alert(E + '\n' + F); }
40 var new_bc = window.prompt('Enter the replacement barcode for the copy:','','Replace Barcode');
41 new_bc = String( new_bc ).replace(/\s/g,'');
43 alert('Rename aborted. Blank for barcode not allowed.');
47 var test = network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[ new_bc ]);
48 if (typeof test.ilsevent == 'undefined') {
49 alert('Rename aborted. Another copy has barcode "' + new_bc + '".');
52 if (test.ilsevent != 1502 /* ASSET_COPY_NOT_FOUND */) {
53 obj.error.standard_unexpected_error_alert('Error testing replacement barcode "' + new_bc + '".',test);
58 copy.barcode(new_bc); copy.ischanged('1');
59 var r = network.simple_request('FM_ACP_FLESHED_BATCH_UPDATE', [ ses(), [ copy ] ]);
60 if (typeof r.ilsevent != 'undefined') {
61 if (r.ilsevent != 0) {
62 if (r.ilsevent == 5000 /* PERM_FAILURE */) {
63 alert('Renamed aborted. Insufficient permission.');
66 obj.error.standard_unexpected_error_alert('Error renaming item.',r);
74 JSAN.use('util.error'); var error = new util.error();
75 error.standard_unexpected_error_alert('Rename did not likely occur.',E);
80 cat.util.transfer_copies = function(params) {
81 JSAN.use('util.error'); var error = new util.error();
82 JSAN.use('OpenILS.data'); var data = new OpenILS.data();
83 JSAN.use('util.network'); var network = new util.network();
85 data.stash_retrieve();
86 if (!data.marked_volume) {
87 alert('Please mark a volume as the destination from within holdings maintenance and then try this again.');
90 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
91 var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: auto">';
92 if (!params.message) {
93 params.message = 'Transfer items from their original volumes to ';
94 params.message += data.hash.aou[ params.owning_lib ].shortname() + "'s volume labelled ";
95 params.message += '"' + params.volume_label + '" on the following record (and change their circ libs to match)?';
98 xml += '<description>' + params.message.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>') + '</description>';
99 xml += '<hbox><button label="Transfer" name="fancy_submit"/>';
100 xml += '<button label="Cancel" accesskey="C" name="fancy_cancel"/></hbox>';
101 xml += '<iframe style="overflow: scroll" flex="1" src="' + urls.XUL_BIB_BRIEF + '?docid=' + params.docid + '"/>';
103 //data.temp_transfer = xml; data.stash('temp_transfer');
104 JSAN.use('util.window'); var win = new util.window();
105 var fancy_prompt_data = win.open(
106 urls.XUL_FANCY_PROMPT,
107 //+ '?xml_in_stash=temp_transfer'
108 //+ '&title=' + window.escape('Item Transfer'),
109 'fancy_prompt', 'chrome,resizable,modal,width=500,height=300',
110 { 'xml' : xml, 'title' : 'Item Transfer' }
112 if (fancy_prompt_data.fancy_status == 'incomplete') { alert('Transfer Aborted'); return; }
114 JSAN.use('util.functional');
116 var copies = network.simple_request('FM_ACP_FLESHED_BATCH_RETRIEVE.authoritative', [ params.copy_ids ]);
118 for (var i = 0; i < copies.length; i++) {
119 copies[i].call_number( data.marked_volume );
120 copies[i].circ_lib( params.owning_lib );
121 copies[i].ischanged( 1 );
124 var robj = network.simple_request(
125 'FM_ACP_FLESHED_BATCH_UPDATE',
126 [ ses(), copies, true ],
129 'title' : 'Override Transfer Failure?',
130 'overridable_events' : [
131 1208 /* TITLE_LAST_COPY */,
132 1227 /* COPY_DELETE_WARNING */,
137 if (typeof robj.ilsevent != 'undefined') {
140 alert('Items transferred.');
144 error.standard_unexpected_error_alert('All items not likely transferred.',E);
148 cat.util.spawn_spine_editor = function(selection_list) {
149 JSAN.use('util.error'); var error = new util.error();
151 JSAN.use('util.functional');
152 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.stash_retrieve();
153 data.temp_barcodes_for_labels = util.functional.map_list( selection_list, function(o){return o.barcode;}) ;
154 data.stash('temp_barcodes_for_labels');
156 xulG.url_prefix( urls.XUL_SPINE_LABEL ),
157 { 'tab_name' : 'Spine Labels' },
161 error.standard_unexpected_error_alert('Spine Labels',E);
165 cat.util.show_in_opac = function(selection_list) {
166 JSAN.use('util.error'); var error = new util.error();
167 var doc_id; var seen = {};
169 for (var i = 0; i < selection_list.length; i++) {
170 doc_id = selection_list[i].doc_id;
172 alert(selection_list[i].barcode + ' is not cataloged');
175 if (typeof seen[doc_id] != 'undefined') {
179 var opac_url = xulG.url_prefix( urls.opac_rdetail ) + '?r=' + doc_id;
180 var content_params = {
182 'authtime' : ses('authtime'),
183 'opac_url' : opac_url,
186 xulG.url_prefix(urls.XUL_OPAC_WRAPPER),
187 {'tab_name':'Retrieving title...'},
192 error.standard_unexpected_error_alert('Error opening catalog for document id = ' + doc_id,E);
196 cat.util.add_copies_to_bucket = function(selection_list) {
197 JSAN.use('util.functional');
198 JSAN.use('util.window'); var win = new util.window();
199 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
200 data.cb_temp_copy_ids = js2JSON(
201 util.functional.map_list(
204 if (typeof o.copy_id != 'undefined' && o.copy_id != null) {
212 data.stash('cb_temp_copy_ids');
214 xulG.url_prefix(urls.XUL_COPY_BUCKETS_QUICK),
215 'sel_bucket_win' + win.window_name_increment(),
216 'chrome,resizable,center'
220 cat.util.spawn_copy_editor = function(params) {
222 if (!params.copy_ids && !params.copies) return;
223 if (params.copy_ids && params.copy_ids.length == 0) return;
224 if (params.copies && params.copies.length == 0) return;
225 if (params.copy_ids) params.copy_ids = js2JSON(params.copy_ids); // legacy
226 if (!params.caller_handles_update) params.handle_update = 1; // legacy
229 JSAN.use('util.network'); obj.network = new util.network();
230 JSAN.use('util.error'); obj.error = new util.error();
233 if ((params.copy_ids && params.copy_ids.length > 1) || (params.copies && params.copies.length > 1 )) title += 'Batch ';
234 title += params.edit == 1 ? 'Edit' : 'View';
235 title += ' Copy Attributes';
237 JSAN.use('util.window'); var win = new util.window();
238 var my_xulG = win.open(
239 (urls.XUL_COPY_EDITOR),
241 'chrome,modal,resizable',
244 if (!my_xulG.copies && params.edit) {
245 alert(typeof params.no_copies_modified_msg != 'undefined' ? params.no_copies_modified_msg : 'Copies not modified.');
247 return my_xulG.copies;
251 JSAN.use('util.error'); var error = new util.error();
252 error.standard_unexpected_error_alert('error in cat.util.spawn_copy_editor',E);
256 cat.util.mark_item_damaged = function(copy_ids) {
259 JSAN.use('util.error'); error = new util.error();
260 JSAN.use('util.functional');
261 JSAN.use('util.network'); var network = new util.network();
262 var copies = network.simple_request('FM_ACP_FLESHED_BATCH_RETRIEVE.authoritative', [ copy_ids ]);
263 if (typeof copies.ilsevent != 'undefined') throw(copies);
264 var magic_status = false;
265 for (var i = 0; i < copies.length; i++) {
266 var status = copies[i].status(); if (typeof status == 'object') status = status.id();
267 if (typeof my_constants.magical_statuses[ status ] != 'undefined')
268 if (my_constants.magical_statuses[ status ].block_mark_item_action) magic_status = true;
272 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');
276 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');
280 for (var i = 0; i < copies.length; i++) {
282 var robj = network.simple_request('MARK_ITEM_DAMAGED',[ses(),copies[i].id()]);
283 if (typeof robj.ilsevent != 'undefined') throw(robj);
286 error.standard_unexpected_error_alert('Error marking item ' + copies[i].barcode() + ' damaged.',E);
289 alert(count == 1 ? 'Item marked Damaged' : count + ' items marked Damaged.');
294 if (error) error.standard_unexpected_error_alert('cat.util.mark_item_damaged',E); else alert('FIXME: ' + E);
298 cat.util.mark_item_missing = function(copy_ids) {
301 JSAN.use('util.error'); error = new util.error();
302 JSAN.use('util.functional');
303 JSAN.use('util.network'); var network = new util.network();
304 var copies = network.simple_request('FM_ACP_FLESHED_BATCH_RETRIEVE.authoritative', [ copy_ids ]);
305 if (typeof copies.ilsevent != 'undefined') throw(copies);
306 var magic_status = false;
307 for (var i = 0; i < copies.length; i++) {
308 var status = copies[i].status(); if (typeof status == 'object') status = status.id();
309 if (typeof my_constants.magical_statuses[ status ] != 'undefined')
310 if (my_constants.magical_statuses[ status ].block_mark_item_action) magic_status = true;
314 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');
318 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');
322 for (var i = 0; i < copies.length; i++) {
324 var robj = network.simple_request('MARK_ITEM_MISSING',[ses(),copies[i].id()]);
325 if (typeof robj.ilsevent != 'undefined') throw(robj);
328 error.standard_unexpected_error_alert('Error marking item ' + copies[i].barcode() + ' missing.',E);
331 alert(count == 1 ? 'Item marked Missing' : count + ' items marked Missing.');
336 if (error) error.standard_unexpected_error_alert('cat.util.mark_item_missing',E); else alert('FIXME: ' + E);
341 dump('exiting cat/util.js\n');