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',
10 cat.util.EXPORT_TAGS = { ':all' : cat.util.EXPORT_OK };
12 cat.util.transfer_copies = function(params) {
13 JSAN.use('util.error'); var error = new util.error();
14 JSAN.use('OpenILS.data'); var data = new OpenILS.data();
15 JSAN.use('util.network'); var network = new util.network();
17 data.stash_retrieve();
18 if (!data.marked_volume) {
19 alert('Please mark a volume as the destination from within holdings maintenance and then try this again.');
22 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
23 var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: auto">';
24 if (!params.message) {
25 params.message = 'Transfer items from their original volumes to ';
26 params.message += data.hash.aou[ params.owning_lib ].shortname() + "'s volume labelled ";
27 params.message += '"' + params.volume_label + '" on the following record (and change their circ libs to match)?';
30 xml += '<description>' + params.message + '</description>';
31 xml += '<hbox><button label="Transfer" name="fancy_submit"/>';
32 xml += '<button label="Cancel" accesskey="C" name="fancy_cancel"/></hbox>';
33 xml += '<iframe style="overflow: scroll" flex="1" src="' + urls.XUL_BIB_BRIEF + '?docid=' + params.docid + '"/>';
35 data.temp_transfer = xml; data.stash('temp_transfer');
38 + '?xml_in_stash=temp_transfer'
39 + '&title=' + window.escape('Item Transfer'),
40 'fancy_prompt', 'chrome,resizable,modal,width=500,height=300'
42 data.stash_retrieve();
43 if (data.fancy_prompt_data == '') { alert('Transfer Aborted'); return; }
45 JSAN.use('util.functional');
47 var copies = network.simple_request('FM_ACP_FLESHED_BATCH_RETRIEVE', [ params.copy_ids ]);
49 for (var i = 0; i < copies.length; i++) {
50 copies[i].call_number( data.marked_volume );
51 copies[i].circ_lib( params.owning_lib );
52 copies[i].ischanged( 1 );
55 var robj = network.simple_request(
56 'FM_ACP_FLESHED_BATCH_UPDATE',
57 [ ses(), copies, true ],
60 'title' : 'Override Transfer Failure?',
61 'overridable_events' : [
62 1208 /* TITLE_LAST_COPY */,
67 if (typeof robj.ilsevent != 'undefined') {
70 alert('Items transferred.');
74 error.standard_unexpected_error_alert('All items not likely transferred.',E);
78 cat.util.spawn_spine_editor = function(selection_list) {
79 JSAN.use('util.error'); var error = new util.error();
81 JSAN.use('util.functional');
83 xulG.url_prefix( urls.XUL_SPINE_LABEL ) + '?barcodes='
84 + js2JSON( util.functional.map_list(selection_list,function(o){return o.barcode;}) ),
85 { 'tab_name' : 'Spine Labels' },
89 error.standard_unexpected_error_alert('Spine Labels',E);
93 cat.util.show_in_opac = function(selection_list) {
94 JSAN.use('util.error'); var error = new util.error();
95 var doc_id; var seen = {};
97 for (var i = 0; i < selection_list.length; i++) {
98 doc_id = selection_list[i].doc_id;
100 alert(selection_list[i].barcode + ' is not cataloged');
103 if (typeof seen[doc_id] != 'undefined') {
107 var opac_url = xulG.url_prefix( urls.opac_rdetail ) + '?r=' + doc_id;
108 var content_params = {
110 'authtime' : ses('authtime'),
111 'opac_url' : opac_url,
114 xulG.url_prefix(urls.XUL_OPAC_WRAPPER),
115 {'tab_name':'Retrieving title...'},
120 error.standard_unexpected_error_alert('Error opening catalog for document id = ' + doc_id,E);
124 cat.util.add_copies_to_bucket = function(selection_list) {
125 JSAN.use('util.functional');
126 JSAN.use('util.window'); var win = new util.window();
127 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
128 data.cb_temp_copy_ids = js2JSON(
129 util.functional.map_list(
132 if (typeof o.copy_id != 'undefined' && o.copy_id != null) {
140 data.stash('cb_temp_copy_ids');
142 xulG.url_prefix(urls.XUL_COPY_BUCKETS_QUICK),
143 'sel_bucket_win' + win.window_name_increment(),
144 'chrome,resizable,modal,center'
148 cat.util.spawn_copy_editor = function(list,edit) {
151 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
152 JSAN.use('util.network'); obj.network = new util.network();
153 JSAN.use('util.error'); obj.error = new util.error();
155 var title = list.length == 1 ? '' : 'Batch ';
156 title += edit == 1 ? 'Edit' : 'View';
157 title += ' Copy Attributes';
159 JSAN.use('util.window'); var win = new util.window();
160 obj.data.temp_copies = undefined; obj.data.stash('temp_copies');
161 obj.data.temp_callnumbers = undefined; obj.data.stash('temp_callnumbers');
162 obj.data.temp_copy_ids = js2JSON(list);
163 obj.data.stash('temp_copy_ids');
165 window.xulG.url_prefix(urls.XUL_COPY_EDITOR)
168 'chrome,modal,resizable'
170 /* FIXME -- need to unique the temp space, and not rely on modalness of window */
171 obj.data.stash_retrieve();
172 if (!obj.data.temp_copies) return;
173 var copies = JSON2js( obj.data.temp_copies );
174 obj.data.temp_copies = undefined; obj.data.stash('temp_copies');
175 obj.data.temp_callnumbers = undefined; obj.data.stash('temp_callnumbers');
176 obj.data.temp_copy_ids = undefined; obj.data.stash('temp_copy_ids');
177 obj.error.sdump('D_CAT','in cat/copy_status, copy editor, copies =\n<<' + copies + '>>');
178 if (edit=='1' && copies!='' && typeof copies != 'undefined') {
180 var r = obj.network.request(
181 api.FM_ACP_FLESHED_BATCH_UPDATE.app,
182 api.FM_ACP_FLESHED_BATCH_UPDATE.method,
183 [ ses(), copies, true ]
185 /* FIXME -- revisit the return value here */
187 obj.error.standard_unexpected_error_alert('copy update error',E);
190 //alert('not updating');
197 cat.util.mark_item_damaged = function(copy_ids) {
200 JSAN.use('util.error'); error = new util.error();
201 JSAN.use('util.functional');
202 JSAN.use('util.network'); var network = new util.network();
203 var copies = network.simple_request('FM_ACP_FLESHED_BATCH_RETRIEVE', [ copy_ids ]);
204 if (typeof copies.ilsevent != 'undefined') throw(copies);
205 var magic_status = false;
206 for (var i = 0; i < copies.length; i++) {
207 var status = copies[i].status(); if (typeof status == 'object') status = status.id();
208 if (typeof my_constants.magical_statuses[ status ] != 'undefined')
209 if (my_constants.magical_statuses[ status ].block_mark_item_action) magic_status = true;
213 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');
217 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. You will also have to manually adjust any pertinent holds. Barcodes: ' + util.functional.map_list( copies, function(o) { return o.barcode(); } ).join(", "), 'Mark Damaged', 'OK', 'Cancel', null, 'Check here to confirm this action');
221 for (var i = 0; i < copies.length; i++) {
223 var robj = network.simple_request('MARK_ITEM_DAMAGED',[ses(),copies[i].id()]);
224 if (typeof robj.ilsevent != 'undefined') throw(robj);
227 error.standard_unexpected_error_alert('Error marking item ' + copies[i].barcode() + ' damaged.',E);
230 alert(count == 1 ? 'Item marked Damaged' : count + ' items marked Damaged.');
235 if (error) error.standard_unexpected_error_alert('cat.util.mark_item_damaged',E); else alert('FIXME: ' + E);
239 cat.util.mark_item_missing = function(copy_ids) {
242 JSAN.use('util.error'); error = new util.error();
243 JSAN.use('util.functional');
244 JSAN.use('util.network'); var network = new util.network();
245 var copies = network.simple_request('FM_ACP_FLESHED_BATCH_RETRIEVE', [ copy_ids ]);
246 if (typeof copies.ilsevent != 'undefined') throw(copies);
247 var magic_status = false;
248 for (var i = 0; i < copies.length; i++) {
249 var status = copies[i].status(); if (typeof status == 'object') status = status.id();
250 if (typeof my_constants.magical_statuses[ status ] != 'undefined')
251 if (my_constants.magical_statuses[ status ].block_mark_item_action) magic_status = true;
255 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');
259 var r = error.yns_alert('Change the status for these items to Missing? You will have to manually adjust any pertinent holds. Barcodes: ' + util.functional.map_list( copies, function(o) { return o.barcode(); } ).join(", "), 'Mark Missing', 'OK', 'Cancel', null, 'Check here to confirm this action');
263 for (var i = 0; i < copies.length; i++) {
265 var robj = network.simple_request('MARK_ITEM_MISSING',[ses(),copies[i].id()]);
266 if (typeof robj.ilsevent != 'undefined') throw(robj);
269 error.standard_unexpected_error_alert('Error marking item ' + copies[i].barcode() + ' missing.',E);
272 alert(count == 1 ? 'Item marked Missing' : count + ' items marked Missing.');
277 if (error) error.standard_unexpected_error_alert('cat.util.mark_item_missing',E); else alert('FIXME: ' + E);
282 dump('exiting cat/util.js\n');