]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/cat/util.js
814d724fff26c1f9411435a7c6ea17563b2fffa3
[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',
9 ];
10 cat.util.EXPORT_TAGS    = { ':all' : cat.util.EXPORT_OK };
11
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();
16         try {
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.');
20                         return;
21                 }
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)?';
28                 }
29
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 + '"/>';
34                 xml += '</vbox>';
35                 data.temp_transfer = xml; data.stash('temp_transfer');
36                 window.open(
37                         urls.XUL_FANCY_PROMPT
38                         + '?xml_in_stash=temp_transfer'
39                         + '&title=' + window.escape('Item Transfer'),
40                         'fancy_prompt', 'chrome,resizable,modal,width=500,height=300'
41                 );
42                 data.stash_retrieve();
43                 if (data.fancy_prompt_data == '') { alert('Transfer Aborted'); return; }
44
45                 JSAN.use('util.functional');
46
47                 var copies = network.simple_request('FM_ACP_FLESHED_BATCH_RETRIEVE', [ params.copy_ids ]);
48
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 );
53                 }
54
55                 var robj = network.simple_request(
56                         'FM_ACP_FLESHED_BATCH_UPDATE', 
57                         [ ses(), copies, true ], 
58                         null,
59                         {
60                                 'title' : 'Override Transfer Failure?',
61                                 'overridable_events' : [
62                                         1208 /* TITLE_LAST_COPY */,
63                                 ]
64                         }
65                 );
66                 
67                 if (typeof robj.ilsevent != 'undefined') {
68                         throw(robj);
69                 } else {
70                         alert('Items transferred.');
71                 }
72
73         } catch(E) {
74                 error.standard_unexpected_error_alert('All items not likely transferred.',E);
75         }
76 }
77
78 cat.util.spawn_spine_editor = function(selection_list) {
79         JSAN.use('util.error'); var error = new util.error();
80         try {
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');
85                 xulG.new_tab(
86                         xulG.url_prefix( urls.XUL_SPINE_LABEL ),
87                         { 'tab_name' : 'Spine Labels' },
88                         {}
89                 );
90         } catch(E) {
91                 error.standard_unexpected_error_alert('Spine Labels',E);
92         }
93 }
94
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 = {};
98         try {
99                 for (var i = 0; i < selection_list.length; i++) {
100                         doc_id = selection_list[i].doc_id;
101                         if (!doc_id) {
102                                 alert(selection_list[i].barcode + ' is not cataloged');
103                                 continue;
104                         }
105                         if (typeof seen[doc_id] != 'undefined') {
106                                 continue;
107                         }
108                         seen[doc_id] = true;
109                         var opac_url = xulG.url_prefix( urls.opac_rdetail ) + '?r=' + doc_id;
110                         var content_params = { 
111                                 'session' : ses(),
112                                 'authtime' : ses('authtime'),
113                                 'opac_url' : opac_url,
114                         };
115                         xulG.new_tab(
116                                 xulG.url_prefix(urls.XUL_OPAC_WRAPPER), 
117                                 {'tab_name':'Retrieving title...'}, 
118                                 content_params
119                         );
120                 }
121         } catch(E) {
122                 error.standard_unexpected_error_alert('Error opening catalog for document id = ' + doc_id,E);
123         }
124 }
125
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(
132                         selection_list,
133                         function (o) {
134                                 if (typeof o.copy_id != 'undefined' && o.copy_id != null) {
135                                         return o.copy_id;
136                                 } else {
137                                         return o;
138                                 }
139                         }
140                 )
141         );
142         data.stash('cb_temp_copy_ids');
143         win.open( 
144                 xulG.url_prefix(urls.XUL_COPY_BUCKETS_QUICK),
145                 'sel_bucket_win' + win.window_name_increment(),
146                 'chrome,resizable,center'
147         );
148 }
149
150 cat.util.spawn_copy_editor = function(list,edit) {
151         try {
152         var obj = {};
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();
156
157         var title = list.length == 1 ? '' : 'Batch '; 
158         title += edit == 1 ? 'Edit' : 'View';
159         title += ' Copy Attributes';
160
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');
166         var w = win.open(
167                 window.xulG.url_prefix(urls.XUL_COPY_EDITOR)
168                         +'?edit='+edit,
169                 title,
170                 'chrome,modal,resizable'
171         );
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') {
181                 try {
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 ]
186                         );
187                         /* FIXME -- revisit the return value here */
188                 } catch(E) {
189                         obj.error.standard_unexpected_error_alert('copy update error',E);
190                 }
191         } else {
192                 //alert('not updating');
193         }
194         } catch(E) {
195                 alert(E);
196         }
197 }
198
199 cat.util.mark_item_damaged = function(copy_ids) {
200         var error;
201         try {
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;
212                 }
213                 if (magic_status) {
214                 
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');
216
217                 } else {
218
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');
220
221                         if (r == 0) {
222                                 var count = 0;
223                                 for (var i = 0; i < copies.length; i++) {
224                                         try {
225                                                 var robj = network.simple_request('MARK_ITEM_DAMAGED',[ses(),copies[i].id()]);
226                                                 if (typeof robj.ilsevent != 'undefined') throw(robj);
227                                                 count++;
228                                         } catch(E) {
229                                                 error.standard_unexpected_error_alert('Error marking item ' + copies[i].barcode() + ' damaged.',E);
230                                         }
231                                 }
232                                 alert(count == 1 ? 'Item marked Damaged' : count + ' items marked Damaged.');
233                         }
234                 }
235
236         } catch(E) {
237                 if (error) error.standard_unexpected_error_alert('cat.util.mark_item_damaged',E); else alert('FIXME: ' + E);
238         }
239 }
240
241 cat.util.mark_item_missing = function(copy_ids) {
242         var error;
243         try {
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;
254                 }
255                 if (magic_status) {
256                 
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');
258
259                 } else {
260
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');
262
263                         if (r == 0) {
264                                 var count = 0;
265                                 for (var i = 0; i < copies.length; i++) {
266                                         try {
267                                                 var robj = network.simple_request('MARK_ITEM_MISSING',[ses(),copies[i].id()]);
268                                                 if (typeof robj.ilsevent != 'undefined') throw(robj);
269                                                 count++;
270                                         } catch(E) {
271                                                 error.standard_unexpected_error_alert('Error marking item ' + copies[i].barcode() + ' missing.',E);
272                                         }
273                                 }
274                                 alert(count == 1 ? 'Item marked Missing' : count + ' items marked Missing.');
275                         }
276                 }
277
278         } catch(E) {
279                 if (error) error.standard_unexpected_error_alert('cat.util.mark_item_missing',E); else alert('FIXME: ' + E);
280         }
281 }
282
283
284 dump('exiting cat/util.js\n');