]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/cat/util.js
xul_param and modal xulG conversion
[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', 'replace_barcode',
9 ];
10 cat.util.EXPORT_TAGS    = { ':all' : cat.util.EXPORT_OK };
11
12 cat.util.replace_barcode = function(old_bc) {
13         try {
14                 JSAN.use('util.network');
15                 var network = new util.network();
16
17                 if (!old_bc) old_bc = window.prompt('Enter original barcode for the copy:','','Replace Barcode');
18                 if (!old_bc) return;
19
20                 var copy = network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[ old_bc ]);
21                 if (typeof copy.ilsevent != 'undefined') throw(copy); 
22                 if (!copy) throw(copy);
23
24                 // Why did I want to do this twice?  Because this copy is more fleshed?
25                 copy = network.simple_request('FM_ACP_RETRIEVE',[ copy.id() ]);
26                 if (typeof copy.ilsevent != 'undefined') throw(copy);
27                 if (!copy) throw(copy);
28
29                 var new_bc = window.prompt('Enter the replacement barcode for the copy with barcode ' + old_bc + ':','','Replace Barcode');
30                 new_bc = String( new_bc ).replace(/\s/g,'');
31                 if (!new_bc) {
32                         alert('Rename aborted.  Blank for barcode not allowed.');
33                         return old_bc;
34                 }
35
36                 var test = network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[ ses(), new_bc ]);
37                 if (typeof test.ilsevent == 'undefined') {
38                         alert('Rename aborted.  Another copy has that barcode');
39                         return old_bc;
40                 }
41                 copy.barcode(new_bc); copy.ischanged('1');
42                 var r = network.simple_request('FM_ACP_FLESHED_BATCH_UPDATE', [ ses(), [ copy ] ]);
43                 if (typeof r.ilsevent != 'undefined') { if (r.ilsevent != 0) throw(r); }
44                 return new_bc;
45         } catch(E) {
46                 JSAN.use('util.error'); var error = new util.error();
47                 error.standard_unexpected_error_alert('Rename did not likely occur.',E);
48         }
49 }
50
51 cat.util.transfer_copies = function(params) {
52         JSAN.use('util.error'); var error = new util.error();
53         JSAN.use('OpenILS.data'); var data = new OpenILS.data();
54         JSAN.use('util.network'); var network = new util.network();
55         try {
56                 data.stash_retrieve();
57                 if (!data.marked_volume) {
58                         alert('Please mark a volume as the destination from within holdings maintenance and then try this again.');
59                         return;
60                 }
61                 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
62                 var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: auto">';
63                 if (!params.message) {
64                         params.message = 'Transfer items from their original volumes to ';
65                         params.message += data.hash.aou[ params.owning_lib ].shortname() + "'s volume labelled ";
66                         params.message += '"' + params.volume_label + '" on the following record (and change their circ libs to match)?';
67                 }
68
69                 xml += '<description>' + params.message.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;') + '</description>';
70                 xml += '<hbox><button label="Transfer" name="fancy_submit"/>';
71                 xml += '<button label="Cancel" accesskey="C" name="fancy_cancel"/></hbox>';
72                 xml += '<iframe style="overflow: scroll" flex="1" src="' + urls.XUL_BIB_BRIEF + '?docid=' + params.docid + '"/>';
73                 xml += '</vbox>';
74                 //data.temp_transfer = xml; data.stash('temp_transfer');
75                 JSAN.use('util.window'); var win = new util.window();
76                 var fancy_prompt_data = win.open(
77                         urls.XUL_FANCY_PROMPT,
78                         //+ '?xml_in_stash=temp_transfer'
79                         //+ '&title=' + window.escape('Item Transfer'),
80                         'fancy_prompt', 'chrome,resizable,modal,width=500,height=300',
81                         { 'xml' : xml, 'title' : 'Item Transfer' }
82                 );
83                 if (fancy_prompt_data.fancy_status == 'incomplete') { alert('Transfer Aborted'); return; }
84
85                 JSAN.use('util.functional');
86
87                 var copies = network.simple_request('FM_ACP_FLESHED_BATCH_RETRIEVE', [ params.copy_ids ]);
88
89                 for (var i = 0; i < copies.length; i++) {
90                         copies[i].call_number( data.marked_volume );
91                         copies[i].circ_lib( params.owning_lib );
92                         copies[i].ischanged( 1 );
93                 }
94
95                 var robj = network.simple_request(
96                         'FM_ACP_FLESHED_BATCH_UPDATE', 
97                         [ ses(), copies, true ], 
98                         null,
99                         {
100                                 'title' : 'Override Transfer Failure?',
101                                 'overridable_events' : [
102                                         1208 /* TITLE_LAST_COPY */,
103                                         1227 /* COPY_DELETE_WARNING */,
104                                 ]
105                         }
106                 );
107                 
108                 if (typeof robj.ilsevent != 'undefined') {
109                         throw(robj);
110                 } else {
111                         alert('Items transferred.');
112                 }
113
114         } catch(E) {
115                 error.standard_unexpected_error_alert('All items not likely transferred.',E);
116         }
117 }
118
119 cat.util.spawn_spine_editor = function(selection_list) {
120         JSAN.use('util.error'); var error = new util.error();
121         try {
122                 JSAN.use('util.functional');
123                 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.stash_retrieve();
124                 data.temp_barcodes_for_labels = util.functional.map_list( selection_list, function(o){return o.barcode;}) ; 
125                 data.stash('temp_barcodes_for_labels');
126                 xulG.new_tab(
127                         xulG.url_prefix( urls.XUL_SPINE_LABEL ),
128                         { 'tab_name' : 'Spine Labels' },
129                         {}
130                 );
131         } catch(E) {
132                 error.standard_unexpected_error_alert('Spine Labels',E);
133         }
134 }
135
136 cat.util.show_in_opac = function(selection_list) {
137         JSAN.use('util.error'); var error = new util.error();
138         var doc_id; var seen = {};
139         try {
140                 for (var i = 0; i < selection_list.length; i++) {
141                         doc_id = selection_list[i].doc_id;
142                         if (!doc_id) {
143                                 alert(selection_list[i].barcode + ' is not cataloged');
144                                 continue;
145                         }
146                         if (typeof seen[doc_id] != 'undefined') {
147                                 continue;
148                         }
149                         seen[doc_id] = true;
150                         var opac_url = xulG.url_prefix( urls.opac_rdetail ) + '?r=' + doc_id;
151                         var content_params = { 
152                                 'session' : ses(),
153                                 'authtime' : ses('authtime'),
154                                 'opac_url' : opac_url,
155                         };
156                         xulG.new_tab(
157                                 xulG.url_prefix(urls.XUL_OPAC_WRAPPER), 
158                                 {'tab_name':'Retrieving title...'}, 
159                                 content_params
160                         );
161                 }
162         } catch(E) {
163                 error.standard_unexpected_error_alert('Error opening catalog for document id = ' + doc_id,E);
164         }
165 }
166
167 cat.util.add_copies_to_bucket = function(selection_list) {
168         JSAN.use('util.functional');
169         JSAN.use('util.window'); var win = new util.window();
170         JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
171         data.cb_temp_copy_ids = js2JSON(
172                 util.functional.map_list(
173                         selection_list,
174                         function (o) {
175                                 if (typeof o.copy_id != 'undefined' && o.copy_id != null) {
176                                         return o.copy_id;
177                                 } else {
178                                         return o;
179                                 }
180                         }
181                 )
182         );
183         data.stash('cb_temp_copy_ids');
184         win.open( 
185                 xulG.url_prefix(urls.XUL_COPY_BUCKETS_QUICK),
186                 'sel_bucket_win' + win.window_name_increment(),
187                 'chrome,resizable,center'
188         );
189 }
190
191 cat.util.spawn_copy_editor = function(list,edit) {
192         try {
193                 var obj = {};
194                 JSAN.use('util.network'); obj.network = new util.network();
195                 JSAN.use('util.error'); obj.error = new util.error();
196         
197                 if (list.length == 0) return;
198         
199                 var title = list.length == 1 ? '' : 'Batch '; 
200                 title += edit == 1 ? 'Edit' : 'View';
201                 title += ' Copy Attributes';
202         
203                 JSAN.use('util.window'); var win = new util.window();
204                 //JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
205                 //obj.data.temp_copies = undefined; obj.data.stash('temp_copies');
206                 //obj.data.temp_callnumbers = undefined; obj.data.stash('temp_callnumbers');
207                 //obj.data.temp_copy_ids = js2JSON(list); obj.data.stash('temp_copy_ids');
208                 var my_xulG = win.open(
209                         //window.xulG.url_prefix(urls.XUL_COPY_EDITOR),
210                         (urls.XUL_COPY_EDITOR),
211                         //      +'?handle_update=1&edit='+edit,
212                         title,
213                         'chrome,modal,resizable',
214                         {
215                                 'handle_update' : 1,
216                                 'edit' : edit,
217                                 'copy_ids' : js2JSON(list),
218                         }
219                 );
220                 //obj.data.stash_retrieve();
221                 if (!my_xulG.copies) alert('Copies not modified.');
222                 //if (!obj.data.temp_copies) alert('Copies not modified.');
223                 //obj.data.temp_copies = undefined; obj.data.stash('temp_copies');
224         } catch(E) {
225                 JSAN.use('util.error'); var error = new util.error();
226                 error.standard_unexpected_error_alert('error in cat.util.spawn_copy_editor',E);
227         }
228 }
229
230 cat.util.mark_item_damaged = function(copy_ids) {
231         var error;
232         try {
233                 JSAN.use('util.error'); error = new util.error();
234                 JSAN.use('util.functional');
235                 JSAN.use('util.network'); var network = new util.network();
236                 var copies = network.simple_request('FM_ACP_FLESHED_BATCH_RETRIEVE', [ copy_ids ]);
237                 if (typeof copies.ilsevent != 'undefined') throw(copies);
238                 var magic_status = false;
239                 for (var i = 0; i < copies.length; i++) {
240                         var status = copies[i].status(); if (typeof status == 'object') status = status.id();
241                         if (typeof my_constants.magical_statuses[ status ] != 'undefined') 
242                                 if (my_constants.magical_statuses[ status ].block_mark_item_action) magic_status = true;
243                 }
244                 if (magic_status) {
245                 
246                         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');
247
248                 } else {
249
250                         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');
251
252                         if (r == 0) {
253                                 var count = 0;
254                                 for (var i = 0; i < copies.length; i++) {
255                                         try {
256                                                 var robj = network.simple_request('MARK_ITEM_DAMAGED',[ses(),copies[i].id()]);
257                                                 if (typeof robj.ilsevent != 'undefined') throw(robj);
258                                                 count++;
259                                         } catch(E) {
260                                                 error.standard_unexpected_error_alert('Error marking item ' + copies[i].barcode() + ' damaged.',E);
261                                         }
262                                 }
263                                 alert(count == 1 ? 'Item marked Damaged' : count + ' items marked Damaged.');
264                         }
265                 }
266
267         } catch(E) {
268                 if (error) error.standard_unexpected_error_alert('cat.util.mark_item_damaged',E); else alert('FIXME: ' + E);
269         }
270 }
271
272 cat.util.mark_item_missing = function(copy_ids) {
273         var error;
274         try {
275                 JSAN.use('util.error'); error = new util.error();
276                 JSAN.use('util.functional');
277                 JSAN.use('util.network'); var network = new util.network();
278                 var copies = network.simple_request('FM_ACP_FLESHED_BATCH_RETRIEVE', [ copy_ids ]);
279                 if (typeof copies.ilsevent != 'undefined') throw(copies);
280                 var magic_status = false;
281                 for (var i = 0; i < copies.length; i++) {
282                         var status = copies[i].status(); if (typeof status == 'object') status = status.id();
283                         if (typeof my_constants.magical_statuses[ status ] != 'undefined') 
284                                 if (my_constants.magical_statuses[ status ].block_mark_item_action) magic_status = true;
285                 }
286                 if (magic_status) {
287                 
288                         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');
289
290                 } else {
291
292                         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');
293
294                         if (r == 0) {
295                                 var count = 0;
296                                 for (var i = 0; i < copies.length; i++) {
297                                         try {
298                                                 var robj = network.simple_request('MARK_ITEM_MISSING',[ses(),copies[i].id()]);
299                                                 if (typeof robj.ilsevent != 'undefined') throw(robj);
300                                                 count++;
301                                         } catch(E) {
302                                                 error.standard_unexpected_error_alert('Error marking item ' + copies[i].barcode() + ' missing.',E);
303                                         }
304                                 }
305                                 alert(count == 1 ? 'Item marked Missing' : count + ' items marked Missing.');
306                         }
307                 }
308
309         } catch(E) {
310                 if (error) error.standard_unexpected_error_alert('cat.util.mark_item_missing',E); else alert('FIXME: ' + E);
311         }
312 }
313
314
315 dump('exiting cat/util.js\n');