]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/cat/util.js
tweak magical statuses and mark item actions
[working/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                 xulG.new_tab(
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' },
86                         {}
87                 );
88         } catch(E) {
89                 error.standard_unexpected_error_alert('Spine Labels',E);
90         }
91 }
92
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 = {};
96         try {
97                 for (var i = 0; i < selection_list.length; i++) {
98                         doc_id = selection_list[i].doc_id;
99                         if (!doc_id) {
100                                 alert(selection_list[i].barcode + ' is not cataloged');
101                                 continue;
102                         }
103                         if (typeof seen[doc_id] != 'undefined') {
104                                 continue;
105                         }
106                         seen[doc_id] = true;
107                         var opac_url = xulG.url_prefix( urls.opac_rdetail ) + '?r=' + doc_id;
108                         var content_params = { 
109                                 'session' : ses(),
110                                 'authtime' : ses('authtime'),
111                                 'opac_url' : opac_url,
112                         };
113                         xulG.new_tab(
114                                 xulG.url_prefix(urls.XUL_OPAC_WRAPPER), 
115                                 {'tab_name':'Retrieving title...'}, 
116                                 content_params
117                         );
118                 }
119         } catch(E) {
120                 error.standard_unexpected_error_alert('Error opening catalog for document id = ' + doc_id,E);
121         }
122 }
123
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(
130                         selection_list,
131                         function (o) {
132                                 if (typeof o.copy_id != 'undefined' && o.copy_id != null) {
133                                         return o.copy_id;
134                                 } else {
135                                         return o;
136                                 }
137                         }
138                 )
139         );
140         data.stash('cb_temp_copy_ids');
141         win.open( 
142                 xulG.url_prefix(urls.XUL_COPY_BUCKETS_QUICK),
143                 'sel_bucket_win' + win.window_name_increment(),
144                 'chrome,resizable,modal,center'
145         );
146 }
147
148 cat.util.spawn_copy_editor = function(list,edit) {
149         try {
150         var obj = {};
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();
154
155         var title = list.length == 1 ? '' : 'Batch '; 
156         title += edit == 1 ? 'Edit' : 'View';
157         title += ' Copy Attributes';
158
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');
164         var w = win.open(
165                 window.xulG.url_prefix(urls.XUL_COPY_EDITOR)
166                         +'?edit='+edit,
167                 title,
168                 'chrome,modal,resizable'
169         );
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') {
179                 try {
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 ]
184                         );
185                         /* FIXME -- revisit the return value here */
186                 } catch(E) {
187                         obj.error.standard_unexpected_error_alert('copy update error',E);
188                 }
189         } else {
190                 //alert('not updating');
191         }
192         } catch(E) {
193                 alert(E);
194         }
195 }
196
197 cat.util.mark_item_damaged = function(copy_ids) {
198         var error;
199         try {
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;
210                 }
211                 if (magic_status) {
212                 
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');
214
215                 } else {
216
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');
218
219                         if (r == 0) {
220                                 var count = 0;
221                                 for (var i = 0; i < copies.length; i++) {
222                                         try {
223                                                 var robj = network.simple_request('MARK_ITEM_DAMAGED',[ses(),copies[i].id()]);
224                                                 if (typeof robj.ilsevent != 'undefined') throw(robj);
225                                                 count++;
226                                         } catch(E) {
227                                                 error.standard_unexpected_error_alert('Error marking item ' + copies[i].barcode() + ' damaged.',E);
228                                         }
229                                 }
230                                 alert(count == 1 ? 'Item marked Damaged' : count + ' items marked Damaged.');
231                         }
232                 }
233
234         } catch(E) {
235                 if (error) error.standard_unexpected_error_alert('cat.util.mark_item_damaged',E); else alert('FIXME: ' + E);
236         }
237 }
238
239 cat.util.mark_item_missing = function(copy_ids) {
240         var error;
241         try {
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;
252                 }
253                 if (magic_status) {
254                 
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');
256
257                 } else {
258
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');
260
261                         if (r == 0) {
262                                 var count = 0;
263                                 for (var i = 0; i < copies.length; i++) {
264                                         try {
265                                                 var robj = network.simple_request('MARK_ITEM_MISSING',[ses(),copies[i].id()]);
266                                                 if (typeof robj.ilsevent != 'undefined') throw(robj);
267                                                 count++;
268                                         } catch(E) {
269                                                 error.standard_unexpected_error_alert('Error marking item ' + copies[i].barcode() + ' missing.',E);
270                                         }
271                                 }
272                                 alert(count == 1 ? 'Item marked Missing' : count + ' items marked Missing.');
273                         }
274                 }
275
276         } catch(E) {
277                 if (error) error.standard_unexpected_error_alert('cat.util.mark_item_missing',E); else alert('FIXME: ' + E);
278         }
279 }
280
281
282 dump('exiting cat/util.js\n');