1 function $(id) { return document.getElementById(id); }
3 function ses(a,params) {
5 if (!params) params = {};
8 data = params.data; data.stash_retrieve();
10 // 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
11 JSAN.use('OpenILS.data'); data = new OpenILS.data(); data.stash_retrieve();
15 case 'staff_id' : return data.list.au[0].id(); break;
16 case 'staff_usrname' : return data.list.au[0].usrname(); break;
18 return data.list.au[0].ws_ou();
21 return data.session.authtime;
25 return data.session.key;
29 alert(location.href + '\nError in global_utils.js, ses(): ' + E);
34 function font_helper() {
36 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
37 removeCSSClass(document.documentElement,'ALL_FONTS_LARGER');
38 removeCSSClass(document.documentElement,'ALL_FONTS_SMALLER');
39 removeCSSClass(document.documentElement,'ALL_FONTS_XX_SMALL');
40 removeCSSClass(document.documentElement,'ALL_FONTS_X_SMALL');
41 removeCSSClass(document.documentElement,'ALL_FONTS_SMALL');
42 removeCSSClass(document.documentElement,'ALL_FONTS_MEDIUM');
43 removeCSSClass(document.documentElement,'ALL_FONTS_LARGE');
44 removeCSSClass(document.documentElement,'ALL_FONTS_X_LARGE');
45 removeCSSClass(document.documentElement,'ALL_FONTS_XX_LARGE');
46 addCSSClass(document.documentElement,data.global_font_adjust);
48 var Strings = $('offlineStrings') || $('commonStrings');
49 alert(Strings.getFormattedString('openils.global_util.font_size.error', [E]));
53 function persist_helper() {
55 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
56 var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces['nsIPrefBranch']);
57 var nodes = document.getElementsByAttribute('oils_persist','*');
58 for (var i = 0; i < nodes.length; i++) {
59 var filename = location.pathname.split('/')[ location.pathname.split('/').length - 1 ];
60 var base_key = 'oils_persist_' + String(location.hostname + '_' + filename + '_' + nodes[i].getAttribute('id')).replace('/','_','g') + '_';
61 var attribute_list = nodes[i].getAttribute('oils_persist').split(' ');
62 for (var j = 0; j < attribute_list.length; j++) {
63 var key = base_key + attribute_list[j];
64 var value = prefs.prefHasUserValue(key) ? prefs.getCharPref(key) : null;
65 dump('persist_helper: retrieving key = ' + key + ' value = ' + value + ' for ' + nodes[i].nodeName + '\n');
66 if (value) nodes[i].setAttribute( attribute_list[j], value );
68 if ( (nodes[i].nodeName == 'checkbox' || nodes[i].nodeName == 'menuitem') && attribute_list.indexOf('checked') > -1) {
69 var cmd = nodes[i].getAttribute('command');
70 var cmd_el = document.getElementById(cmd);
71 if (nodes[i].disabled == false && nodes[i].hidden == false) {
72 var no_poke = nodes[i].getAttribute('oils_persist_no_poke');
73 if (no_poke && no_poke == 'true') {
74 // Timing issue for some checkboxes; don't poke them with an event
75 dump('\tpersist_helper: not poking element with key = ' + key + '\n');
78 dump('\tpersist_helper: poking @command element for element with key = ' + key + '\n');
79 var evt = document.createEvent("Events");
80 evt.initEvent( 'command', true, true );
81 cmd_el.dispatchEvent(evt);
83 dump('\tpersist_helper: poking element with key = ' + key + '\n');
84 var evt = document.createEvent("Events");
85 evt.initEvent( 'command', true, true );
86 nodes[i].dispatchEvent(evt);
91 cmd_el.addEventListener(
93 function (bk,explicit_original_node) {
96 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
97 if (ev.explicitOriginalTarget != explicit_original_node) return;
98 var key = bk + 'checked';
100 if (ev.explicitOriginalTarget.nodeName == 'checkbox') {
101 value = ev.explicitOriginalTarget.checked;
103 value = ev.explicitOriginalTarget.getAttribute('checked'); // menuitem with type="checkbox"
105 ev.explicitOriginalTarget.setAttribute( 'checked', value );
106 prefs.setCharPref( key, value );
107 dump('persist_helper: setting key = ' + key + ' value = ' + value + ' for checkbox/menuitem via <command>\n');
109 alert('Error in persist_helper(), checkbox/menuitem -> command, command event listener: ' + E);
112 }( base_key, nodes[i] ),
116 nodes[i].addEventListener(
119 return function(ev) {
121 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
122 var key = bk + 'checked';
124 if (ev.target.nodeName == 'checkbox') {
125 value = ev.target.checked;
127 value = ev.target.getAttribute('checked'); // menuitem with type="checkbox"
129 ev.target.setAttribute( 'checked', value );
130 prefs.setCharPref( key, value );
131 dump('persist_helper: setting key = ' + key + ' value = ' + value + ' for checkbox/menuitem\n');
133 alert('Error in persist_helper(), checkbox/menuitem command event listener: ' + E);
141 // TODO: Need to add event listeners for window resizing, splitter repositioning, grippy state, etc.
144 alert('Error in persist_helper(): ' + E);
148 function getKeys(o) {
150 for (var k in o) keys.push(k);
154 function get_contentWindow(frame) {
156 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
157 if (frame && frame.contentWindow) {
159 if (typeof frame.contentWindow.wrappedJSObject != 'undefined') {
160 return frame.contentWindow.wrappedJSObject;
163 var Strings = $('offlineStrings') || $('commonStrings');
164 alert(Strings.getFormattedString('openils.global_util.content_window_jsobject.error', [frame, E]));
166 return frame.contentWindow;
171 var Strings = $('offlineStrings') || $('commonStrings');
172 alert(Strings.getFormattedString('openils.global_util.content_window.error', [frame, E]));
176 function update_modal_xulG(v) {
178 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
179 var key = location.pathname + location.search + location.hash;
180 if (typeof data.modal_xulG_stack != 'undefined' && typeof data.modal_xulG_stack[key] != 'undefined') {
181 data.modal_xulG_stack[key][ data.modal_xulG_stack[key].length - 1 ] = v;
182 data.stash('modal_xulG_stack');
185 alert('FIXME: update_modal_xulG => ' + E);
189 function xul_param(param_name,_params) {
190 /* 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 */
192 //dump('xul_param('+param_name+','+js2JSON(_params)+')\n');
193 var value = undefined; if (!_params) _params = {};
194 if (typeof _params.no_cgi == 'undefined') {
196 if (cgi.param(param_name)) {
197 var x = cgi.param(param_name);
198 //dump('\tfound via location.href = ' + x + '\n');
199 if (typeof _params.JSON2js_if_cgi != 'undefined') {
201 //dump('\tJSON2js = ' + x + '\n');
203 if (typeof _params.concat == 'undefined') {
204 //alert(param_name + ' x = ' + x);
208 if (value.constructor != Array) value = [ value ];
209 value = value.concat(x);
216 if (typeof _params.no_xulG == 'undefined') {
217 if (typeof _params.modal_xulG != 'undefined') {
218 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
219 var key = location.pathname + location.search + location.hash;
220 //dump('xul_param, considering modal key = ' + key + '\n');
221 if (typeof data.modal_xulG_stack != 'undefined' && typeof data.modal_xulG_stack[key] != 'undefined') {
222 xulG = data.modal_xulG_stack[key][ data.modal_xulG_stack[key].length - 1 ];
225 if (typeof xulG == 'object' && typeof xulG[ param_name ] != 'undefined') {
226 var x = xulG[ param_name ];
227 //dump('\tfound via xulG = ' + x + '\n');
228 if (typeof _params.JSON2js_if_xulG != 'undefined') {
230 //dump('\tJSON2js = ' + x + '\n');
232 if (typeof _params.concat == 'undefined') {
233 //alert(param_name + ' x = ' + x);
237 if (value.constructor != Array) value = [ value ];
238 value = value.concat(x);
245 if (typeof _params.no_xpcom == 'undefined') {
246 /* 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 */
247 if (typeof _params.stash_name != 'undefined') {
248 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
249 if (typeof data[ _params.stash_name ] != 'undefined') {
250 var x = data[ _params.stash_name ];
251 //dump('\tfound via xpcom = ' + x + '\n');
252 if (typeof _params.JSON2js_if_xpcom != 'undefined') {
254 //dump('\tJSON2js = ' + x + '\n');
256 if (_params.clear_xpcom) {
257 data[ _params.stash_name ] = undefined; data.stash( _params.stash_name );
259 if (typeof _params.concat == 'undefined') {
260 //alert(param_name + ' x = ' + x);
264 if (value.constructor != Array) value = [ value ];
265 value = value.concat(x);
273 //alert(param_name + ' value = ' + value);
276 dump('xul_param error: ' + E + '\n');
280 function get_bool(a) {
281 // Normal javascript interpretation except 'f' == false, per postgres, and 'F' == false, and '0' == false (newer JSON is returning '0' instead of 0 in cases)
282 // So false includes 'f', '', '0', 0, null, and undefined
283 if (a == 'f') return false;
284 if (a == 'F') return false;
285 if (a == '0') return false;
286 if (a) return true; else return false;
289 function get_db_true() {
293 function get_db_false() {
297 function copy_to_clipboard(ev) {
299 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
301 if (typeof ev == 'object') {
302 if (typeof ev.target != 'undefined') {
303 if (typeof ev.target.textContent != 'undefined') if (ev.target.textContent) text = ev.target.textContent;
304 if (typeof ev.target.value != 'undefined') if (ev.target.value) text = ev.target.value;
306 } else if (typeof ev == 'string') {
309 const gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"]
310 .getService(Components.interfaces.nsIClipboardHelper);
311 gClipboardHelper.copyString(text);
312 var Strings = $('offlineStrings') || $('commonStrings');
313 alert(Strings.getFormattedString('openils.global_util.clipboard', [text]));
315 var Strings = $('offlineStrings') || $('commonStrings');
316 alert(Strings.getFormattedString('openils.global_util.clipboard.error', [E]));
320 function clear_the_cache() {
322 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
323 var cacheClass = Components.classes["@mozilla.org/network/cache-service;1"];
324 var cacheService = cacheClass.getService(Components.interfaces.nsICacheService);
325 cacheService.evictEntries(Components.interfaces.nsICache.STORE_ON_DISK);
326 cacheService.evictEntries(Components.interfaces.nsICache.STORE_IN_MEMORY);
328 var Strings = $('offlineStrings') || $('commonStrings');
329 alert(Strings.getFormattedString('openils.global_util.clear_cache.error', [E]));
333 function toOpenWindowByType(inType, uri) {
334 var winopts = "chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar";
335 window.open(uri, "_blank", winopts);
338 function url_prefix(url) {
339 if (url.match(/^\//)) url = urls.remote + url;
340 if (! url.match(/^(http|chrome):\/\//) && ! url.match(/^data:/) ) url = 'http://' + url;
341 dump('url_prefix = ' + url + '\n');