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');
82 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.stash_retrieve();
83 data.temp_barcodes_for_labels = util.functional.map_list( selection_list, function(o){return o.barcode;}) ;
84 data.stash('temp_barcodes_for_labels');
86 xulG.url_prefix( urls.XUL_SPINE_LABEL ),
87 { 'tab_name' : 'Spine Labels' },
91 error.standard_unexpected_error_alert('Spine Labels',E);
95 cat.util.show_in_opac = function(selection_list) {
96 JSAN.use('util.error'); var error = new util.error();
97 var doc_id; var seen = {};
99 for (var i = 0; i < selection_list.length; i++) {
100 doc_id = selection_list[i].doc_id;
102 alert(selection_list[i].barcode + ' is not cataloged');
105 if (typeof seen[doc_id] != 'undefined') {
109 var opac_url = xulG.url_prefix( urls.opac_rdetail ) + '?r=' + doc_id;
110 var content_params = {
112 'authtime' : ses('authtime'),
113 'opac_url' : opac_url,
116 xulG.url_prefix(urls.XUL_OPAC_WRAPPER),
117 {'tab_name':'Retrieving title...'},
122 error.standard_unexpected_error_alert('Error opening catalog for document id = ' + doc_id,E);
126 cat.util.add_copies_to_bucket = function(selection_list) {
127 JSAN.use('util.functional');
128 JSAN.use('util.window'); var win = new util.window();
129 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
130 data.cb_temp_copy_ids = js2JSON(
131 util.functional.map_list(
134 if (typeof o.copy_id != 'undefined' && o.copy_id != null) {
142 data.stash('cb_temp_copy_ids');
144 xulG.url_prefix(urls.XUL_COPY_BUCKETS_QUICK),
145 'sel_bucket_win' + win.window_name_increment(),
146 'chrome,resizable,center'
150 cat.util.spawn_copy_editor = function(list,edit) {
153 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
154 JSAN.use('util.network'); obj.network = new util.network();
155 JSAN.use('util.error'); obj.error = new util.error();
157 var title = list.length == 1 ? '' : 'Batch ';
158 title += edit == 1 ? 'Edit' : 'View';
159 title += ' Copy Attributes';
161 JSAN.use('util.window'); var win = new util.window();
162 obj.data.temp_copies = undefined; obj.data.stash('temp_copies');
163 obj.data.temp_callnumbers = undefined; obj.data.stash('temp_callnumbers');
164 obj.data.temp_copy_ids = js2JSON(list);
165 obj.data.stash('temp_copy_ids');
167 window.xulG.url_prefix(urls.XUL_COPY_EDITOR)
170 'chrome,modal,resizable'
172 /* FIXME -- need to unique the temp space, and not rely on modalness of window */
173 obj.data.stash_retrieve();
174 if (!obj.data.temp_copies) return;
175 var copies = JSON2js( obj.data.temp_copies );
176 obj.data.temp_copies = undefined; obj.data.stash('temp_copies');
177 obj.data.temp_callnumbers = undefined; obj.data.stash('temp_callnumbers');
178 obj.data.temp_copy_ids = undefined; obj.data.stash('temp_copy_ids');
179 obj.error.sdump('D_CAT','in cat/copy_status, copy editor, copies =\n<<' + copies + '>>');
180 if (edit=='1' && copies!='' && typeof copies != 'undefined') {
182 var r = obj.network.request(
183 api.FM_ACP_FLESHED_BATCH_UPDATE.app,
184 api.FM_ACP_FLESHED_BATCH_UPDATE.method,
185 [ ses(), copies, true ]
187 /* FIXME -- revisit the return value here */
189 obj.error.standard_unexpected_error_alert('copy update error',E);
192 //alert('not updating');
199 cat.util.mark_item_damaged = function(copy_ids) {
202 JSAN.use('util.error'); error = new util.error();
203 JSAN.use('util.functional');
204 JSAN.use('util.network'); var network = new util.network();
205 var copies = network.simple_request('FM_ACP_FLESHED_BATCH_RETRIEVE', [ copy_ids ]);
206 if (typeof copies.ilsevent != 'undefined') throw(copies);
207 var magic_status = false;
208 for (var i = 0; i < copies.length; i++) {
209 var status = copies[i].status(); if (typeof status == 'object') status = status.id();
210 if (typeof my_constants.magical_statuses[ status ] != 'undefined')
211 if (my_constants.magical_statuses[ status ].block_mark_item_action) magic_status = true;
215 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');
219 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');
223 for (var i = 0; i < copies.length; i++) {
225 var robj = network.simple_request('MARK_ITEM_DAMAGED',[ses(),copies[i].id()]);
226 if (typeof robj.ilsevent != 'undefined') throw(robj);
229 error.standard_unexpected_error_alert('Error marking item ' + copies[i].barcode() + ' damaged.',E);
232 alert(count == 1 ? 'Item marked Damaged' : count + ' items marked Damaged.');
237 if (error) error.standard_unexpected_error_alert('cat.util.mark_item_damaged',E); else alert('FIXME: ' + E);
241 cat.util.mark_item_missing = 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 Missing 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 Missing? Barcodes: ' + util.functional.map_list( copies, function(o) { return o.barcode(); } ).join(", "), 'Mark Missing', '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_MISSING',[ses(),copies[i].id()]);
268 if (typeof robj.ilsevent != 'undefined') throw(robj);
271 error.standard_unexpected_error_alert('Error marking item ' + copies[i].barcode() + ' missing.',E);
274 alert(count == 1 ? 'Item marked Missing' : count + ' items marked Missing.');
279 if (error) error.standard_unexpected_error_alert('cat.util.mark_item_missing',E); else alert('FIXME: ' + E);
284 dump('exiting cat/util.js\n');