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 has_key = prefs.prefHasUserValue(key);
65 var value = has_key ? prefs.getCharPref(key) : null;
66 if (value == 'true') { value = true; }
67 if (value == 'false') { value = false; }
68 dump('persist_helper: >>> retrieving key = ' + key + ' (' + (has_key ? 'found' : 'not found') + ') value = ' + value + ' for ' + nodes[i].nodeName + '\n');
70 if (attribute_list[j]=='checked') {
71 nodes[i].checked = value;
72 dump('\t.checked = ' + value + '\n');
74 nodes[i].removeAttribute('checked');
75 dump('\tremoving @checked\n');
78 nodes[i].setAttribute( attribute_list[j], value);
79 dump('\t@' + attribute_list[j] + ' = ' + value + '\n');
81 if (attribute_list[j]=='value') {
82 nodes[i].value = value;
83 dump('\t.value = ' + value + '\n');
87 if ( (nodes[i].nodeName == 'checkbox' || nodes[i].nodeName == 'menuitem' || nodes[i].nodeName == 'toolbarbutton') && attribute_list.indexOf('checked') > -1 ) {
88 var cmd = nodes[i].getAttribute('command');
89 var cmd_el = document.getElementById(cmd);
90 if (nodes[i].disabled == false && nodes[i].hidden == false) {
91 var no_poke = nodes[i].getAttribute('oils_persist_no_poke');
92 if (no_poke && no_poke == 'true') {
93 // Timing issue for some checkboxes; don't poke them with an event
94 dump('\tpersist_helper: not poking element with key = ' + key + '\n');
97 dump('\tpersist_helper: poking @command element for element with key = ' + key + '\n');
98 var evt = document.createEvent("Events");
99 evt.initEvent( 'command', true, true );
100 cmd_el.dispatchEvent(evt);
102 dump('\tpersist_helper: poking element with key = ' + key + '\n');
103 var evt = document.createEvent("Events");
104 evt.initEvent( 'command', true, true );
105 nodes[i].dispatchEvent(evt);
110 cmd_el.addEventListener(
114 var evt = document.createEvent("Events");
115 evt.initEvent( 'oils_persist', true, true );
116 ev.target.dispatchEvent(evt);
118 alert('Error in persist_helper, firing virtual event oils_persist after command event on <command> element: ' + E);
123 cmd_el.addEventListener(
125 function (bk,explicit_original_node) {
126 return function(ev) {
128 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
129 if (ev.explicitOriginalTarget != explicit_original_node) return;
130 var key = bk + 'checked';
132 if ( ['checkbox','toolbarbutton'].indexOf( ev.explicitOriginalTarget.nodeName ) > -1 ) {
133 value = ev.explicitOriginalTarget.checked;
134 ev.explicitOriginalTarget.setAttribute( 'checked', value ? value : '' );
136 value = ev.explicitOriginalTarget.getAttribute('checked'); // menuitem with type="checkbox"
138 prefs.setCharPref( key, value );
139 dump('persist_helper: <<< setting key = ' + key + ' value = ' + value + ' for checkbox/menuitem/toolbarbutton via <command>\n');
141 alert('Error in persist_helper(), checkbox/menuitem/toolbarbutton -> command, oils_persist event listener: ' + E);
144 }( base_key, nodes[i] ),
148 nodes[i].addEventListener(
152 var evt = document.createEvent("Events");
153 evt.initEvent( 'oils_persist', true, true );
154 ev.target.dispatchEvent(evt);
156 alert('Error in persist_helper, firing virtual event oils_persist after command event on element: ' + E);
161 nodes[i].addEventListener(
164 return function(ev) {
166 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
167 var key = bk + 'checked';
169 if ( ['checkbox','toolbarbutton'].indexOf( ev.target.nodeName ) > -1 ) {
170 value = ev.target.checked;
171 ev.target.setAttribute( 'checked', value ? value : '' );
173 value = ev.target.getAttribute('checked'); // menuitem with type="checkbox"
175 prefs.setCharPref( key, value );
176 dump('persist_helper: <<< setting key = ' + key + ' value = ' + value + ' for checkbox/menuitem/toolbarbutton\n');
178 alert('Error in persist_helper(), checkbox/menuitem/toolbarbutton oils_persist event listener: ' + E);
185 } else if ( (nodes[i].nodeName == 'textbox') && attribute_list.indexOf('value') > -1) {
186 if (nodes[i].disabled == false && nodes[i].hidden == false) {
187 var no_poke = nodes[i].getAttribute('oils_persist_no_poke');
188 if (no_poke && no_poke == 'true') {
189 dump('\tpersist_helper: not poking element with key = ' + key + '\n');
191 dump('\tpersist_helper: poking element with key = ' + key + '\n');
192 var evt = document.createEvent("Events");
193 evt.initEvent( 'change', true, true );
194 nodes[i].dispatchEvent(evt);
197 nodes[i].addEventListener(
201 var evt = document.createEvent("Events");
202 evt.initEvent( 'oils_persist', true, true );
203 ev.target.dispatchEvent(evt);
205 alert('Error in persist_helper, firing virtual event oils_persist after change event on element: ' + E);
210 nodes[i].addEventListener(
213 return function(ev) {
215 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
216 var key = bk + 'value';
217 var value = ev.target.value;
218 ev.target.setAttribute( 'value', value );
219 prefs.setCharPref( key, value );
220 dump('persist_helper: <<< setting key = ' + key + ' value = ' + value + ' for value\n');
222 alert('Error in persist_helper(), textbox oils_persist event listener: ' + E);
229 // TODO: Need to add event listeners for window resizing, splitter repositioning, grippy state, etc.
232 alert('Error in persist_helper(): ' + E);
236 function getKeys(o) {
238 for (var k in o) keys.push(k);
242 function get_contentWindow(frame) {
244 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
245 if (frame && frame.contentWindow) {
247 if (typeof frame.contentWindow.wrappedJSObject != 'undefined') {
248 return frame.contentWindow.wrappedJSObject;
251 var Strings = $('offlineStrings') || $('commonStrings');
252 alert(Strings.getFormattedString('openils.global_util.content_window_jsobject.error', [frame, E]));
254 return frame.contentWindow;
259 var Strings = $('offlineStrings') || $('commonStrings');
260 alert(Strings.getFormattedString('openils.global_util.content_window.error', [frame, E]));
264 function update_modal_xulG(v) {
266 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
267 var key = location.pathname + location.search + location.hash;
268 if (typeof data.modal_xulG_stack != 'undefined' && typeof data.modal_xulG_stack[key] != 'undefined') {
269 data.modal_xulG_stack[key][ data.modal_xulG_stack[key].length - 1 ] = v;
270 data.stash('modal_xulG_stack');
273 alert('FIXME: update_modal_xulG => ' + E);
277 function xul_param(param_name,_params) {
278 /* 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 */
280 //dump('xul_param('+param_name+','+js2JSON(_params)+')\n');
281 var value = undefined; if (!_params) _params = {};
282 if (typeof _params.no_cgi == 'undefined') {
284 if (cgi.param(param_name)) {
285 var x = cgi.param(param_name);
286 //dump('\tfound via location.href = ' + x + '\n');
287 if (typeof _params.JSON2js_if_cgi != 'undefined') {
289 //dump('\tJSON2js = ' + x + '\n');
291 if (typeof _params.concat == 'undefined') {
292 //alert(param_name + ' x = ' + x);
296 if (value.constructor != Array) value = [ value ];
297 value = value.concat(x);
304 if (typeof _params.no_xulG == 'undefined') {
305 if (typeof _params.modal_xulG != 'undefined') {
306 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
307 var key = location.pathname + location.search + location.hash;
308 //dump('xul_param, considering modal key = ' + key + '\n');
309 if (typeof data.modal_xulG_stack != 'undefined' && typeof data.modal_xulG_stack[key] != 'undefined') {
310 xulG = data.modal_xulG_stack[key][ data.modal_xulG_stack[key].length - 1 ];
313 if (typeof xulG == 'object' && typeof xulG[ param_name ] != 'undefined') {
314 var x = xulG[ param_name ];
315 //dump('\tfound via xulG = ' + x + '\n');
316 if (typeof _params.JSON2js_if_xulG != 'undefined') {
318 //dump('\tJSON2js = ' + x + '\n');
320 if (typeof _params.concat == 'undefined') {
321 //alert(param_name + ' x = ' + x);
325 if (value.constructor != Array) value = [ value ];
326 value = value.concat(x);
333 if (typeof _params.no_xpcom == 'undefined') {
334 /* 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 */
335 if (typeof _params.stash_name != 'undefined') {
336 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
337 if (typeof data[ _params.stash_name ] != 'undefined') {
338 var x = data[ _params.stash_name ];
339 //dump('\tfound via xpcom = ' + x + '\n');
340 if (typeof _params.JSON2js_if_xpcom != 'undefined') {
342 //dump('\tJSON2js = ' + x + '\n');
344 if (_params.clear_xpcom) {
345 data[ _params.stash_name ] = undefined; data.stash( _params.stash_name );
347 if (typeof _params.concat == 'undefined') {
348 //alert(param_name + ' x = ' + x);
352 if (value.constructor != Array) value = [ value ];
353 value = value.concat(x);
361 //alert(param_name + ' value = ' + value);
364 dump('xul_param error: ' + E + '\n');
368 function get_bool(a) {
369 // Normal javascript interpretation except 'f' == false, per postgres, and 'F' == false, and '0' == false (newer JSON is returning '0' instead of 0 in cases)
370 // So false includes 'f', '', '0', 0, null, and undefined
371 if (a == 'f') return false;
372 if (a == 'F') return false;
373 if (a == '0') return false;
374 if (a) return true; else return false;
377 function get_db_true() {
381 function get_db_false() {
385 function copy_to_clipboard(ev) {
387 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
389 if (typeof ev == 'object') {
390 if (typeof ev.target != 'undefined') {
391 if (typeof ev.target.textContent != 'undefined') if (ev.target.textContent) text = ev.target.textContent;
392 if (typeof ev.target.value != 'undefined') if (ev.target.value) text = ev.target.value;
394 } else if (typeof ev == 'string') {
397 const gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"]
398 .getService(Components.interfaces.nsIClipboardHelper);
399 gClipboardHelper.copyString(text);
400 var Strings = $('offlineStrings') || $('commonStrings');
401 alert(Strings.getFormattedString('openils.global_util.clipboard', [text]));
403 var Strings = $('offlineStrings') || $('commonStrings');
404 alert(Strings.getFormattedString('openils.global_util.clipboard.error', [E]));
408 function clear_the_cache() {
410 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
411 var cacheClass = Components.classes["@mozilla.org/network/cache-service;1"];
412 var cacheService = cacheClass.getService(Components.interfaces.nsICacheService);
413 cacheService.evictEntries(Components.interfaces.nsICache.STORE_ON_DISK);
414 cacheService.evictEntries(Components.interfaces.nsICache.STORE_IN_MEMORY);
416 var Strings = $('offlineStrings') || $('commonStrings');
417 alert(Strings.getFormattedString('openils.global_util.clear_cache.error', [E]));
421 function toOpenWindowByType(inType, uri) {
422 var winopts = "chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar";
423 window.open(uri, "_blank", winopts);
426 function url_prefix(url) {
427 if (url.match(/^\//)) url = urls.remote + url;
428 if (! url.match(/^(http|chrome):\/\//) && ! url.match(/^data:/) ) url = 'http://' + url;
429 dump('url_prefix = ' + url + '\n');