]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/OpenILS/global_util.js
tweaking the debug output for page/tab locking
[Evergreen.git] / Open-ILS / xul / staff_client / chrome / content / OpenILS / global_util.js
1     function $(id) { return document.getElementById(id); }
2
3     function oils_unsaved_data_V() {
4         JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.stash_retrieve();
5         data.stash_retrieve();
6         if (typeof data.unsaved_data == 'undefined') { data.unsaved_data = 0; }
7         data.unsaved_data++;
8         window.oils_lock++;
9         data.stash('unsaved_data');
10         dump('\n=-=-=-=-=\n');
11         dump('oils_unsaved_data_V for ' + location.href + '\n');
12         dump('incrementing window.oils_lock\n');
13         dump('incrementing data.unsaved_data\n');
14         dump('\twindow.oils_lock == ' + window.oils_lock + '\n');
15         dump('\tdata.unsaved_data == ' + data.unsaved_data + '\n');
16     }
17
18     function oils_unsaved_data_P(count) {
19         dump('\n=-=-=-=-=\n');
20         dump('oils_unsaved_data_P for ' + location.href + '\n');
21         if (!count) { count = 1; }
22         dump('decrementing window.oils_lock by ' + count + '\n');
23         window.oils_lock -= count;
24         if (window.oils_lock < 0) { window.oils_lock = 0; }
25         JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.stash_retrieve();
26         data.stash_retrieve();
27         if (typeof data.unsaved_data == 'undefined') { data.unsaved_data = 0; }
28         dump('decrementing data.unsaved_data by ' + count + '\n');
29         data.unsaved_data -= count;
30         if (data.unsaved_data < 0) { data.unsaved_data = 0; }
31         data.stash('unsaved_data');
32         dump('\twindow.oils_lock == ' + window.oils_lock + '\n');
33         dump('\tdata.unsaved_data == ' + data.unsaved_data + '\n');
34     }
35
36     function oils_lock_page(params) {
37         dump('\n=-=-=-=-=\n');
38         dump('oils_lock_page for ' + location.href + '\n');
39         if (!params) { params = {}; }
40         if (window.oils_lock > 0) {
41             if (!params.allow_multiple_locks) {
42                 return window.oils_lock;
43             }
44         }
45         if (typeof xulG != 'undefined') {
46             if (typeof xulG.unlock_tab == 'function') {
47                 dump('\twith xulG.lock_tab\n');
48                 xulG.lock_tab();
49             } else {
50                 dump('\twithout xulG.lock_tab\n');
51                 oils_unsaved_data_V();
52             }
53         } else {
54             dump('\twithout xulG.lock_tab\n');
55             oils_unsaved_data_V();
56         }
57         return window.oils_lock;
58     }
59
60     function oils_unlock_page(params) {
61         dump('\n=-=-=-=-=\n');
62         dump('oils_unlock_page for ' + location.href + '\n');
63         if (typeof xulG != 'undefined') {
64             if (typeof xulG.unlock_tab == 'function') {
65                 dump('\twith xulG.unlock_tab\n');
66                 xulG.unlock_tab();
67             } else {
68                 dump('\twithout xulG.unlock_tab\n');
69                 oils_unsaved_data_P();
70             }
71         } else {
72             dump('\twithout xulG.unlock_tab\n');
73             oils_unsaved_data_P();
74         }
75         return window.oils_lock;
76     }
77
78     window.oils_lock = 0;
79     dump('\n=-=-=-=-=\n');
80     dump('init window.oils_lock == ' + window.oils_lock + ' for ' + location.href + '\n');
81     window.addEventListener(
82         'close',
83         function(ev) {
84             try {
85                 dump('\n=-=-=-=-=\n');
86                 dump('oils_lock_page/oils_unlock_page onclose handler for ' + location.href + '\n');
87                 if (window.oils_lock > 0) {
88                     var confirmation = window.confirm($('offlineStrings').getString('menu.close_window.unsaved_data_warning'));
89                     if (!confirmation) {
90                         ev.preventDefault();
91                         return false;
92                     }
93                 }
94
95                 if (typeof xulG != 'undefined') {
96                     if (typeof xulG.unlock_tab == 'function') {
97                         xulG.unlock_tab();
98                     } else {
99                         oils_unsaved_data_P( window.oils_lock );
100                     }
101                 } else {
102                     oils_unsaved_data_P( window.oils_lock );
103                 }
104                 window.oils_lock = 0;
105                 dump('forcing window.oils_lock == ' + window.oils_lock + '\n');
106
107                 // Dispatching the window close event doesn't always close the window, even though the event does happen
108                 setTimeout(
109                     function() {
110                         try {
111                             window.close();
112                         } catch(E) {
113                             dump('Error inside global_util.js, onclose handler, setTimeout window.close KLUDGE: ' + E + '\n');
114                         }
115                     }, 0
116                 );
117
118                 return true;
119             } catch(E) {
120                 dump('Error inside global_util.js, onclose handler: ' + E + '\n');
121                 return true;
122             }
123         },
124         false
125     );
126
127     function ses(a,params) {
128         try {
129             if (!params) params = {};
130             var data;
131             if (params.data) {
132                 data = params.data; data.stash_retrieve();
133             } else {
134                 // This has been breaking in certain contexts, with an internal instantiation of util.error failing because of util.error being an object instead of the constructor function it should be
135                 JSAN.use('OpenILS.data'); data = new OpenILS.data(); data.stash_retrieve();
136             }
137
138             switch(a) {
139                 case 'staff' : return data.list.au[0]; break;
140                 case 'staff_id' : return data.list.au[0].id(); break;
141                 case 'staff_usrname' : return data.list.au[0].usrname(); break;
142                 case 'ws_ou' :
143                     return data.list.au[0].ws_ou();
144                 break;
145                 case 'ws_ou_shortname' :
146                     return data.hash.aou[ data.list.au[0].ws_ou() ].shortname();
147                 break;
148                 case 'authtime' :
149                     return data.session.authtime;
150                 break;
151                 case 'key':
152                 default:
153                     return data.session.key;
154                 break;
155             }
156         } catch(E) {
157             alert(location.href + '\nError in global_utils.js, ses(): ' + E);
158             throw(E);
159         }
160     }
161
162     function font_helper() {
163         try {
164             JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
165             removeCSSClass(document.documentElement,'ALL_FONTS_LARGER');
166             removeCSSClass(document.documentElement,'ALL_FONTS_SMALLER');
167             removeCSSClass(document.documentElement,'ALL_FONTS_XX_SMALL');
168             removeCSSClass(document.documentElement,'ALL_FONTS_X_SMALL');
169             removeCSSClass(document.documentElement,'ALL_FONTS_SMALL');
170             removeCSSClass(document.documentElement,'ALL_FONTS_MEDIUM');
171             removeCSSClass(document.documentElement,'ALL_FONTS_LARGE');
172             removeCSSClass(document.documentElement,'ALL_FONTS_X_LARGE');
173             removeCSSClass(document.documentElement,'ALL_FONTS_XX_LARGE');
174             addCSSClass(document.documentElement,data.global_font_adjust);
175         } catch(E) {
176             var Strings = $('offlineStrings') || $('commonStrings');
177             alert(Strings.getFormattedString('openils.global_util.font_size.error', [E]));
178         }
179     }
180
181     function oils_persist(e,cancelable) {
182         try {
183             if (!e) { return; }
184             if (typeof cancelable == 'undefined') { cancelable = false; } 
185             var evt = document.createEvent("Events");
186             evt.initEvent( 'oils_persist', false, cancelable ); // event name, bubbles, cancelable
187             e.dispatchEvent(evt);
188         } catch(E) {
189             alert('Error with oils_persist():' + E);
190         }
191     }
192
193     function persist_helper(base_key_suffix) {
194         try {
195             if (base_key_suffix) {
196                 base_key_suffix = base_key_suffix.replace(/[^A-Za-z]/g,'_') + '_';
197             } else {
198                 base_key_suffix = '';
199             }
200
201             function gen_event_handler(etype,node) {
202                 return function(ev) {
203                     try {
204                         oils_persist(ev.target);
205                     } catch(E) {
206                         alert('Error in persist_helper, firing virtual event oils_persist after ' + etype + ' event on ' + node.nodeName + '.id = ' + node.id + ': ' + E);
207                     }
208                 };
209             };
210
211             function gen_oils_persist_handler(bk,node) {
212                 return function(ev) {
213                     try {
214                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
215                         var target;
216                         if (ev.target.nodeName == 'command') {
217                             target = node;
218                             if (ev.explicitOriginalTarget != node) return;
219                         } else {
220                             target = ev.target;
221                             if (target == window) {
222                                 target = window.document.documentElement;
223                             }
224                         }
225                         var filename = location.pathname.split('/')[ location.pathname.split('/').length - 1 ];
226                         var base_key = 'oils_persist_' + String(location.hostname + '_' + filename + '_' + target.getAttribute('id')).replace('/','_','g') + '_' + base_key_suffix;
227                         var attribute_list = target.getAttribute('oils_persist').split(' ');
228                         dump('on_oils_persist: <<< ' + target.nodeName + '.id = ' + target.id + '\t' + bk + '\n');
229                         for (var j = 0; j < attribute_list.length; j++) {
230                             var key = base_key + attribute_list[j];
231                             var value = target.getAttribute( attribute_list[j] );
232                             if ( attribute_list[j] == 'checked' && ['checkbox','toolbarbutton'].indexOf( target.nodeName ) > -1 ) {
233                                 value = target.checked;
234                                 dump('\t' + value + ' <== .' + attribute_list[j] + '\n');
235                             } else if ( attribute_list[j] == 'value' && ['textbox'].indexOf( target.nodeName ) > -1 ) {
236                                 value = target.value;
237                                 dump('\t' + value + ' <== .' + attribute_list[j] + '\n');
238                             } else if ( attribute_list[j] == 'sizemode' && ['window'].indexOf( target.nodeName ) > -1 ) {
239                                 value = window.windowState;
240                                 dump('\t' + value + ' <== window.windowState, @' + attribute_list[j] + '\n');
241                             } else if ( attribute_list[j] == 'height' && ['window'].indexOf( target.nodeName ) > -1 ) {
242                                 value = window.outerHeight;
243                                 dump('\t' + value + ' <== window.outerHeight, @' + attribute_list[j] + '\n');
244                             } else if ( attribute_list[j] == 'width' && ['window'].indexOf( target.nodeName ) > -1 ) {
245                                 value = window.outerWidth;
246                                 dump('\t' + value + ' <== window.outerWidth, @' + attribute_list[j] + '\n');
247                             } else {
248                                 dump('\t' + value + ' <== @' + attribute_list[j] + '\n');
249                             }
250                             prefs.setCharPref( key, value );
251                             // TODO: Need to add logic for splitter repositioning, grippy state, etc.
252                             // NOTE: oils_persist_peers and oils_persist="width" on those peers can help with the elements adjacent to a splitter
253                         }
254                         if (target.hasAttribute('oils_persist_peers') && ! ev.cancelable) { // We abuse the .cancelable field on the oils_persist event to prevent looping
255                             var peer_list = target.getAttribute('oils_persist_peers').split(' ');
256                             for (var j = 0; j < peer_list.length; j++) {
257                                 dump('on_oils_persist: dispatching oils_persist to peer ' + peer_list[j] + '\n');
258                                 oils_persist( document.getElementById( peer_list[j] ), true );
259                             } 
260                         }
261                     } catch(E) {
262                         alert('Error in persist_helper() event listener for ' + bk + ': ' + E);
263                     }
264                 };
265             }
266
267             netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
268             var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces['nsIPrefBranch']);
269             var nodes = document.getElementsByAttribute('oils_persist','*');
270             for (var i = 0; i < nodes.length; i++) {
271                 var filename = location.pathname.split('/')[ location.pathname.split('/').length - 1 ];
272                 var base_key = 'oils_persist_' + String(location.hostname + '_' + filename + '_' + nodes[i].getAttribute('id')).replace('/','_','g') + '_' + base_key_suffix;
273                 var attribute_list = nodes[i].getAttribute('oils_persist').split(' ');
274                 dump('persist_helper: >>> ' + nodes[i].nodeName + '.id = ' + nodes[i].id + '\t' + base_key + '\n');
275                 for (var j = 0; j < attribute_list.length; j++) {
276                     var key = base_key + attribute_list[j];
277                     var has_key = prefs.prefHasUserValue(key);
278                     var value = has_key ? prefs.getCharPref(key) : null;
279                     if (value == 'true') { value = true; }
280                     if (value == 'false') { value = false; }
281                     if (has_key) {
282                         if ( attribute_list[j] == 'checked' && ['checkbox','toolbarbutton'].indexOf( nodes[i].nodeName ) > -1 ) {
283                             nodes[i].checked = value; 
284                             dump('\t' + value + ' ==> .' + attribute_list[j] + '\n');
285                             if (!value) {
286                                 nodes[i].removeAttribute('checked');
287                                 dump('\tremoving @checked\n');
288                             }
289                         } else if ( attribute_list[j] == 'value' && ['textbox'].indexOf( nodes[i].nodeName ) > -1 ) {
290                             nodes[i].value = value;
291                             dump('\t' + value + ' ==> .' + attribute_list[j] + '\n');
292                         } else if ( attribute_list[j] == 'sizemode' && ['window'].indexOf( nodes[i].nodeName ) > -1 ) {
293                             switch(value) {
294                                 case window.STATE_MAXIMIZED:
295                                     window.maximize();
296                                     break;
297                                 case window.STATE_MINIMIZED:
298                                     window.minimize();
299                                     break;
300                             };
301                             dump('\t' + value + ' ==> window.windowState, @' + attribute_list[j] + '\n');
302                         } else if ( attribute_list[j] == 'height' && ['window'].indexOf( nodes[i].nodeName ) > -1 ) {
303                             window.outerHeight = value;
304                             dump('\t' + value + ' ==> window.outerHeight, @' + attribute_list[j] + '\n');
305                         } else if ( attribute_list[j] == 'width' && ['window'].indexOf( nodes[i].nodeName ) > -1 ) {
306                             window.outerWidth = value;
307                             dump('\t' + value + ' ==> window.outerWidth, @' + attribute_list[j] + '\n');
308                         } else {
309                             nodes[i].setAttribute( attribute_list[j], value);
310                             dump('\t' + value + ' ==> @' + attribute_list[j] + '\n');
311                         }
312                     }
313                 }
314                 var cmd = nodes[i].getAttribute('command');
315                 var cmd_el = document.getElementById(cmd);
316                 if (nodes[i].disabled == false && nodes[i].hidden == false) {
317                     var no_poke = nodes[i].getAttribute('oils_persist_no_poke');
318                     if (no_poke && no_poke == 'true') {
319                         // Timing issue for some checkboxes; don't poke them with an event
320                         dump('\tnot poking\n');
321                     } else {
322                         if (cmd_el) {
323                             dump('\tpoking @command\n');
324                             var evt = document.createEvent("Events");
325                             evt.initEvent( 'command', true, true );
326                             cmd_el.dispatchEvent(evt);
327                         } else {
328                             dump('\tpoking\n');
329                             var evt = document.createEvent("Events");
330                             evt.initEvent( 'command', true, true );
331                             nodes[i].dispatchEvent(evt);
332                         }
333                     }
334                 }
335                 if (cmd_el) {
336                     cmd_el.addEventListener(
337                         'command',
338                         gen_event_handler('command',cmd_el),
339                         false
340                     );
341                     cmd_el.addEventListener(
342                         'oils_persist',
343                         gen_oils_persist_handler( base_key, nodes[i] ),
344                         false
345                     );
346                 } else {
347                     var node = nodes[i];
348                     var event_types = [];
349                     if (node.hasAttribute('oils_persist_events')) {
350                         var event_type_list = node.getAttribute('oils_persist_events').split(' ');
351                         for (var j = 0; j < event_type_list.length; j++) {
352                             event_types.push( event_type_list[j] );
353                         }
354                     } else {
355                         if (node.nodeName == 'textbox') { 
356                             event_types.push('change'); 
357                         } else if (node.nodeName == 'window') {
358                             event_types.push('resize'); 
359                             node = window; // xul window is an element of window.document
360                         } else {
361                             event_types.push('command'); 
362                         }
363                     }
364                     for (var j = 0; j < event_types.length; j++) {
365                         node.addEventListener(
366                             event_types[j],
367                             gen_event_handler(event_types[j],node),
368                             false
369                         );
370                     }
371                     node.addEventListener(
372                         'oils_persist',
373                         gen_oils_persist_handler( base_key, node ),
374                         false
375                     );
376                 }
377             }
378         } catch(E) {
379             alert('Error in persist_helper(): ' + E);
380         }
381     }
382
383     function getKeys(o) {
384         var keys = [];
385         for (var k in o) keys.push(k);
386         return keys;
387     }
388
389     function get_contentWindow(frame) {
390         try {
391             netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
392             if (frame && frame.contentWindow) {
393                 try {
394                     if (typeof frame.contentWindow.wrappedJSObject != 'undefined') {
395                                      return frame.contentWindow.wrappedJSObject;
396                           }
397                 } catch(E) {
398                     var Strings = $('offlineStrings') || $('commonStrings');
399                     alert(Strings.getFormattedString('openils.global_util.content_window_jsobject.error', [frame, E]));
400                 }
401                 return frame.contentWindow;
402             } else {
403                 return null;
404             }
405         } catch(E) {
406             var Strings = $('offlineStrings') || $('commonStrings');
407             alert(Strings.getFormattedString('openils.global_util.content_window.error', [frame, E]));
408         }
409     }
410
411     function update_modal_xulG(v) {
412         try {
413             JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
414             var key = location.pathname + location.search + location.hash;
415             if (typeof data.modal_xulG_stack != 'undefined' && typeof data.modal_xulG_stack[key] != 'undefined') {
416                 data.modal_xulG_stack[key][ data.modal_xulG_stack[key].length - 1 ] = v;
417                 data.stash('modal_xulG_stack');
418             }
419         } catch(E) {
420             alert('FIXME: update_modal_xulG => ' + E);
421         }
422     }
423
424     function xul_param(param_name,_params) {
425         /* By default, this function looks for a CGI-style query param identified by param_name.  If one isn't found, it then looks in xulG.  If one still isn't found, and _params.stash_name is true, it looks in the global xpcom stash for the field identified by stash_name.  If _params.concat is true, then it looks in all these places and concatenates the results.  There are also options for converting JSON to javascript objects, and clearing the xpcom stash_name field after retrieval.  Also added, ability to search a specific spot in the xpcom stash that implements a stack to hold xulG's for modal windows */
426         try {
427             //dump('xul_param('+param_name+','+js2JSON(_params)+')\n');
428             var value = undefined; if (!_params) _params = {};
429             if (typeof _params.no_cgi == 'undefined') {
430                 var cgi = new CGI();
431                 if (cgi.param(param_name)) {
432                     var x = cgi.param(param_name);
433                     //dump('\tfound via location.href = ' + x + '\n');
434                     if (typeof _params.JSON2js_if_cgi != 'undefined') {
435                         x = JSON2js( x );
436                         //dump('\tJSON2js = ' + x + '\n');
437                     }
438                     if (typeof _params.concat == 'undefined') {
439                         //alert(param_name + ' x = ' + x);
440                         return x; // value
441                     } else {
442                         if (value) {
443                             if (value.constructor != Array) value = [ value ];
444                             value = value.concat(x);
445                         } else {
446                             value = x;
447                         }
448                     }
449                 }
450             }
451             if (typeof _params.no_xulG == 'undefined') {
452                 if (typeof _params.modal_xulG != 'undefined') {
453                     JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
454                     var key = location.pathname + location.search + location.hash;
455                     //dump('xul_param, considering modal key = ' + key + '\n');
456                     if (typeof data.modal_xulG_stack != 'undefined' && typeof data.modal_xulG_stack[key] != 'undefined') {
457                         xulG = data.modal_xulG_stack[key][ data.modal_xulG_stack[key].length - 1 ];
458                     }
459                 }
460                 if (typeof xulG == 'object' && typeof xulG[ param_name ] != 'undefined') {
461                     var x = xulG[ param_name ];
462                     //dump('\tfound via xulG = ' + x + '\n');
463                     if (typeof _params.JSON2js_if_xulG != 'undefined') {
464                         x = JSON2js( x );
465                         //dump('\tJSON2js = ' + x + '\n');
466                     }
467                     if (typeof _params.concat == 'undefined') {
468                         //alert(param_name + ' x = ' + x);
469                         return x; // value
470                     } else {
471                         if (value) {
472                             if (value.constructor != Array) value = [ value ];
473                             value = value.concat(x);
474                         } else {
475                             value = x;
476                         }
477                     }
478                 }
479             }
480             if (typeof _params.no_xpcom == 'undefined') {
481                 /* the field names used for temp variables in the global stash tend to be more unique than xuLG or CGI param names, to avoid collisions */
482                 if (typeof _params.stash_name != 'undefined') { 
483                     JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
484                     if (typeof data[ _params.stash_name ] != 'undefined') {
485                         var x = data[ _params.stash_name ];
486                         //dump('\tfound via xpcom = ' + x + '\n');
487                         if (typeof _params.JSON2js_if_xpcom != 'undefined') {
488                             x = JSON2js( x );
489                             //dump('\tJSON2js = ' + x + '\n');
490                         }
491                         if (_params.clear_xpcom) { 
492                             data[ _params.stash_name ] = undefined; data.stash( _params.stash_name ); 
493                         }
494                         if (typeof _params.concat == 'undefined') {
495                             //alert(param_name + ' x = ' + x);
496                             return x; // value
497                         } else {
498                             if (value) {
499                                 if (value.constructor != Array) value = [ value ];
500                                 value = value.concat(x);
501                             } else {
502                                 value = x;
503                             }
504                         }
505                     }
506                 }
507             }
508             //alert(param_name + ' value = ' + value);
509             return value;
510         } catch(E) {
511             dump('xul_param error: ' + E + '\n');
512         }
513     }
514
515     function get_bool(a) {
516         // Normal javascript interpretation except 'f' == false, per postgres, and 'F' == false, and '0' == false (newer JSON is returning '0' instead of 0 in cases)
517         // So false includes 'f', '', '0', 0, null, and undefined
518         if (a == 'f') return false;
519         if (a == 'F') return false;
520         if (a == '0') return false;
521         if (a) return true; else return false;
522     }
523
524     function get_localized_bool(a) {
525         var Strings = $('offlineStrings') || $('commonStrings');
526         return get_bool(a) ? Strings.getString('common.yes') : Strings.getString('common.no');
527     }
528
529     function get_db_true() {
530         return 't';
531     }
532
533     function get_db_false() {
534         return 'f';
535     }
536
537     function copy_to_clipboard(ev) {
538         try {
539             netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
540             var text;
541             if (typeof ev == 'object') {
542                 if (typeof ev.target != 'undefined') {
543                     if (typeof ev.target.textContent != 'undefined') if (ev.target.textContent) text = ev.target.textContent;
544                     if (typeof ev.target.value != 'undefined') if (ev.target.value) text = ev.target.value;
545                 }
546             } else if (typeof ev == 'string') {
547                 text = ev;
548             }
549             const gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"]
550                 .getService(Components.interfaces.nsIClipboardHelper);
551             gClipboardHelper.copyString(text);
552             var Strings = $('offlineStrings') || $('commonStrings');
553             alert(Strings.getFormattedString('openils.global_util.clipboard', [text]));
554         } catch(E) {
555             var Strings = $('offlineStrings') || $('commonStrings');
556             alert(Strings.getFormattedString('openils.global_util.clipboard.error', [E]));    
557         }
558     }
559
560     function clear_the_cache() {
561         try {
562             netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
563             var cacheClass         = Components.classes["@mozilla.org/network/cache-service;1"];
564             var cacheService    = cacheClass.getService(Components.interfaces.nsICacheService);
565             cacheService.evictEntries(Components.interfaces.nsICache.STORE_ON_DISK);
566             cacheService.evictEntries(Components.interfaces.nsICache.STORE_IN_MEMORY);
567         } catch(E) {
568             var Strings = $('offlineStrings') || $('commonStrings');
569             alert(Strings.getFormattedString('openils.global_util.clear_cache.error', [E]));
570         }
571     }
572
573     function toOpenWindowByType(inType, uri) {
574         var winopts = "chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar";
575         window.open(uri, "_blank", winopts);
576     }
577
578     function url_prefix(url) {
579         if (url.match(/^\//)) url = urls.remote + url;
580         if (! url.match(/^(http|chrome):\/\//) && ! url.match(/^data:/) ) url = 'http://' + url;
581         dump('url_prefix = ' + url + '\n');
582         return url;
583     }
584