]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/cat/opac.js
undelete for bib records. This is local chrome, so need to deploy a new staff client...
[Evergreen.git] / Open-ILS / xul / staff_client / chrome / content / cat / opac.js
1 var docid; var marc_html; var top_pane; var bottom_pane; var opac_frame; var opac_url;
2
3 function $(id) { return document.getElementById(id); }
4
5 function my_init() {
6         try {
7                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
8                 if (typeof JSAN == 'undefined') { throw(document.getElementById('offlineStrings').getString('common.jsan.missing')); }
9                 JSAN.errorLevel = "die"; // none, warn, or die
10                 JSAN.addRepository('..');
11                 JSAN.use('util.error'); g.error = new util.error();
12                 g.error.sdump('D_TRACE','my_init() for cat/opac.xul');
13
14                 JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
15                 XML_HTTP_SERVER = g.data.server_unadorned;
16
17                 JSAN.use('util.network'); g.network = new util.network();
18
19                 g.cgi = new CGI();
20                 try { authtime = g.cgi.param('authtime') || xulG.authtime; } catch(E) { g.error.sdump('D_ERROR',E); }
21                 try { docid = g.cgi.param('docid') || xulG.docid; } catch(E) { g.error.sdump('D_ERROR',E); }
22                 try { opac_url = g.cgi.param('opac_url') || xulG.opac_url; } catch(E) { g.error.sdump('D_ERROR',E); }
23
24                 JSAN.use('util.deck');
25                 top_pane = new util.deck('top_pane');
26                 bottom_pane = new util.deck('bottom_pane');
27
28                 set_opac();
29
30         } catch(E) {
31                 var err_msg = document.getElementById("offlineStrings").getFormattedString("common.exception", ["cat/opac.xul", E]);
32                 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
33                 alert(err_msg);
34         }
35 }
36
37 function set_brief_view(reset) {
38         var url = xulG.url_prefix( urls.XUL_BIB_BRIEF ) + '?docid=' + window.escape(docid); 
39         dump('spawning ' + url + '\n');
40         top_pane.set_iframe( 
41                 url,
42                 {}, 
43                 { 
44                         'set_tab_name' : function(n) { 
45                                 if (typeof window.xulG == 'object' && typeof window.xulG.set_tab_name == 'function') {
46                                         try { window.xulG.set_tab_name(document.getElementById('offlineStrings').getFormattedString("cat.bib_record", [n])); } catch(E) { alert(E); }
47                                 } else {
48                                         dump('no set_tab_name\n');
49                                 }
50                         }
51                 }  
52         );
53 }
54
55 function set_marc_view(reset) {
56         g.view = 'marc_view';
57         if (reset) {
58                 bottom_pane.reset_iframe( xulG.url_prefix( urls.XUL_MARC_VIEW ) + '?docid=' + window.escape(docid),{},xulG);
59         } else {
60                 bottom_pane.set_iframe( xulG.url_prefix( urls.XUL_MARC_VIEW ) + '?docid=' + window.escape(docid),{},xulG);
61         }
62 }
63
64 function set_marc_edit(reset) {
65         g.view = 'marc_edit';
66         var a = xulG.url_prefix( urls.XUL_MARC_EDIT );
67         var b = {};
68         var c = {
69                         'record' : { 'url' : '/opac/extras/supercat/retrieve/marcxml/record/' + docid },
70                         'save' : {
71                                 'label' : document.getElementById('offlineStrings').getString('cat.save_record'),
72                                 'func' : function (new_marcxml) {
73                                         try {
74                                                 var r = g.network.simple_request('MARC_XML_RECORD_UPDATE', [ ses(), docid, new_marcxml ]);
75                                                 if (typeof r.ilsevent != 'undefined') {
76                                                         throw(r);
77                                                 } else {
78                                                         alert(document.getElementById('offlineStrings').getString("cat.save.success"));
79                                                 }
80                                         } catch(E) {
81                                                         g.error.standard_unexpected_error_alert(document.getElementById('offlineStrings').getString("cat.save.failure"), E);
82                                         }
83                                 }
84                         }
85                 };
86         if (reset) {
87                 bottom_pane.reset_iframe( a,b,c );
88         } else {
89                 bottom_pane.set_iframe( a,b,c );
90         }
91 }
92
93 function set_copy_browser(reset) {
94         g.view = 'copy_browser';
95         if (reset) {
96                 bottom_pane.reset_iframe( xulG.url_prefix( urls.XUL_COPY_VOLUME_BROWSE ) + '?docid=' + window.escape(docid),{},xulG);
97         } else {
98                 bottom_pane.set_iframe( xulG.url_prefix( urls.XUL_COPY_VOLUME_BROWSE ) + '?docid=' + window.escape(docid),{},xulG);
99         }
100 }
101
102 function set_hold_browser(reset) {
103         g.view = 'hold_browser';
104         if (reset) {
105                 bottom_pane.reset_iframe( xulG.url_prefix( urls.XUL_HOLDS_BROWSER ) + '?docid=' + window.escape(docid),{},xulG);
106         } else {
107                 bottom_pane.set_iframe( xulG.url_prefix( urls.XUL_HOLDS_BROWSER ) + '?docid=' + window.escape(docid),{},xulG);
108         }
109 }
110
111 function set_opac(reset) {
112         g.view = 'opac';
113         try {
114                 var content_params = { 
115                         'show_nav_buttons' : true,
116                         'show_print_button' : true,
117                         'passthru_content_params' : { 
118                                 'authtoken' : ses(), 
119                                 'authtime' : ses('authtime'),
120                                 'window_open' : function(a,b,c) {
121                                         try {
122                                                 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
123                                                 return window.open(a,b,c);
124                                         } catch(E) {
125                                                 g.error.standard_unexpected_error_alert('window_open',E);
126                                         }
127                                 }
128                         },
129                         'on_url_load' : function(f) {
130                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
131                                 var win;
132                                 try {
133                                         if (typeof f.contentWindow.wrappedJSObject.attachEvt != 'undefined') {
134                                                 win = f.contentWindow.wrappedJSObject;
135                                         } else {
136                                                 win = f.contentWindow;
137                                         }
138                                 } catch(E) {
139                                         win = f.contentWindow;
140                                 }
141                                 win.attachEvt("rdetail", "recordRetrieved",
142                                         function(id){
143                                                 try {
144                                                         if (docid == id) return;
145                                                         docid = id;
146                                                         refresh_display(id,true);
147                                                 } catch(E) {
148                                                         g.error.standard_unexpected_error_alert('rdetail -> recordRetrieved',E);
149                                                 }
150                                         }
151                                 );
152                                 
153                                 g.f_record_start = null; g.f_record_prev = null; g.f_record_next = null; g.f_record_end = null;
154                                 $('record_start').disabled = true; $('record_next').disabled = true;
155                                 $('record_prev').disabled = true; $('record_end').disabled = true;
156                                 $('record_pos').setAttribute('value','');
157
158                                 win.attachEvt("rdetail", "nextPrevDrawn",
159                                         function(rIndex,rCount){
160                                                 $('record_pos').setAttribute('value', document.getElementById('offlineStrings').getFormattedString('cat.record.counter', [(1+rIndex), rCount]));
161                                                 if (win.rdetailNext) {
162                                                         g.f_record_next = function() { 
163                                                                 g.view_override = g.view; 
164                                                                 win.rdetailNext(); 
165                                                         }
166                                                         $('record_next').disabled = false;
167                                                 }
168                                                 if (win.rdetailPrev) {
169                                                         g.f_record_prev = function() { 
170                                                                 g.view_override = g.view; 
171                                                                 win.rdetailPrev(); 
172                                                         }
173                                                         $('record_prev').disabled = false;
174                                                 }
175                                                 if (win.rdetailStart) {
176                                                         g.f_record_start = function() { 
177                                                                 g.view_override = g.view; 
178                                                                 win.rdetailStart(); 
179                                                         }
180                                                         $('record_start').disabled = false;
181                                                 }
182                                                 if (win.rdetailEnd) {
183                                                         g.f_record_end = function() { 
184                                                                 g.view_override = g.view; 
185                                                                 win.rdetailEnd(); 
186                                                         }
187                                                         $('record_end').disabled = false;
188                                                 }
189                                         }
190                                 );
191                         },
192                         'url_prefix' : xulG.url_prefix,
193                 };
194                 if (opac_url) { content_params.url = opac_url; } else { content_params.url = xulG.url_prefix( urls.browser ); }
195                 browser_frame = bottom_pane.set_iframe( xulG.url_prefix(urls.XUL_BROWSER) + '?name=Catalog', {}, content_params);
196         } catch(E) {
197                 g.error.sdump('D_ERROR','set_opac: ' + E);
198         }
199 }
200
201 function bib_in_new_tab() {
202         try {
203                 var url = browser_frame.contentWindow.g.browser.controller.view.browser_browser.contentWindow.wrappedJSObject.location.href;
204                 var content_params = { 'session' : ses(), 'authtime' : ses('authtime'), 'opac_url' : url };
205                 xulG.new_tab(xulG.url_prefix(urls.XUL_OPAC_WRAPPER), {}, content_params);
206         } catch(E) {
207                 g.error.sdump('D_ERROR',E);
208         }
209 }
210
211 function remove_me() {
212         var url = xulG.url_prefix( urls.XUL_BIB_BRIEF ) + '?docid=' + window.escape(docid);
213         dump('removing ' + url + '\n');
214         try { top_pane.remove_iframe( url ); } catch(E) { dump(E + '\n'); }
215         $('nav').setAttribute('hidden','true');
216 }
217
218 function add_to_bucket() {
219         JSAN.use('util.window'); var win = new util.window();
220         win.open(
221                 xulG.url_prefix(urls.XUL_RECORD_BUCKETS_QUICK)
222                 + '?record_ids=' + js2JSON( [ docid ] ),
223                 'sel_bucket_win' + win.window_name_increment(),
224                 'chrome,resizable,modal,center'
225         );
226 }
227
228 function mark_for_overlay() {
229         g.data.marked_record = docid;
230         g.data.stash('marked_record');
231 }
232
233 function delete_record() {
234         if (g.error.yns_alert(
235                 document.getElementById('offlineStrings').getFormattedString('cat.opac.delete_record.confirm', [docid]),
236                 document.getElementById('offlineStrings').getString('cat.opac.delete_record'),
237                 document.getElementById('offlineStrings').getString('cat.opac.delete'),
238                 document.getElementById('offlineStrings').getString('cat.opac.cancel'),
239                 null,
240                 document.getElementById('offlineStrings').getString('cat.opac.record_deleted.confirm')) == 0) {
241                 var robj = g.network.simple_request('FM_BRE_DELETE',[ses(),docid]);
242                 if (typeof robj.ilsevent != 'undefined') {
243                         alert(document.getElementById('offlineStrings').getFormattedString('cat.opac.record_deleted.error',  [docid, robj.textcode, robj.desc]) + '\n');
244                 } else {
245                         alert(document.getElementById('offlineStrings').getString('cat.opac.record_deleted'));
246                         refresh_display(docid,true);
247                 }
248         }
249 }
250
251 function undelete_record() {
252     if (g.error.yns_alert(
253                 document.getElementById('offlineStrings').getFormattedString('cat.opac.undelete_record.confirm', [docid]),
254                 document.getElementById('offlineStrings').getString('cat.opac.undelete_record'),
255                 document.getElementById('offlineStrings').getString('cat.opac.undelete'),
256                 document.getElementById('offlineStrings').getString('cat.opac.cancel'),
257                 null,
258                 document.getElementById('offlineStrings').getString('cat.opac.record_undeleted.confirm')) == 0) {
259
260         var robj = g.network.simple_request('FM_BRE_UNDELETE',[ses(),docid]);
261         if (typeof robj.ilsevent != 'undefined') {
262                         alert(document.getElementById('offlineStrings').getFormattedString('cat.opac.record_undeleted.error',  [docid, robj.textcode, robj.desc]) + '\n');
263         } else {
264                         alert(document.getElementById('offlineStrings').getString('cat.opac.record_undeleted'));
265                         refresh_display(docid,true);
266         }
267     }
268 }
269
270 function refresh_display(id,reset) {
271         try { 
272                 while(top_pane.node.lastChild) top_pane.node.removeChild( top_pane.node.lastChild );
273                 var children = bottom_pane.node.childNodes;
274                 for (var i = 0; i < children.length; i++) {
275                         if (children[i] != browser_frame) bottom_pane.node.removeChild(children[i]);
276                 }
277
278                 set_brief_view(reset);
279                 $('nav').setAttribute('hidden','false');
280                 var settings = g.network.simple_request(
281                         'FM_AUS_RETRIEVE',
282                         [ ses(), g.data.list.au[0].id() ]
283                 );
284                 var view = settings['staff_client.catalog.record_view.default'];
285                 if (g.view_override) {
286                         view = g.view_override;
287                         g.view_override = null;
288                 }
289                 switch(view) {
290                         case 'marc_view' : set_marc_view(reset); break;
291                         case 'marc_edit' : set_marc_edit(reset); break;
292                         case 'copy_browser' : set_copy_browser(reset); break;
293                         case 'hold_browser' : set_hold_browser(reset); break;
294                         case 'opac' :
295                         default: set_opac(reset); break;
296                 }
297         } catch(E) {
298                 g.error.standard_unexpected_error_alert('in refresh_display',E);
299         }
300 }
301
302 function set_default() {
303         var robj = g.network.simple_request(
304                 'FM_AUS_UPDATE',
305                 [ ses(), g.data.list.au[0].id(), { 'staff_client.catalog.record_view.default' : g.view } ]
306         )
307         if (typeof robj.ilsevent != 'undefined') {
308                 if (robj.ilsevent != 0) g.error.standard_unexpected_error_alert(document.getElementById('offlineStrings').getString('cat.preference.error'), robj);
309         }
310 }
311
312