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');
67 nodes[i].setAttribute( attribute_list[j], value );
68 if (attribute_list[j]=='value') { nodes[i].value = value; }
71 if ( (nodes[i].nodeName == 'checkbox' || nodes[i].nodeName == 'menuitem') && attribute_list.indexOf('checked') > -1) {
72 var cmd = nodes[i].getAttribute('command');
73 var cmd_el = document.getElementById(cmd);
74 if (nodes[i].disabled == false && nodes[i].hidden == false) {
75 var no_poke = nodes[i].getAttribute('oils_persist_no_poke');
76 if (no_poke && no_poke == 'true') {
77 // Timing issue for some checkboxes; don't poke them with an event
78 dump('\tpersist_helper: not poking element with key = ' + key + '\n');
81 dump('\tpersist_helper: poking @command element for element with key = ' + key + '\n');
82 var evt = document.createEvent("Events");
83 evt.initEvent( 'command', true, true );
84 cmd_el.dispatchEvent(evt);
86 dump('\tpersist_helper: poking element with key = ' + key + '\n');
87 var evt = document.createEvent("Events");
88 evt.initEvent( 'command', true, true );
89 nodes[i].dispatchEvent(evt);
94 cmd_el.addEventListener(
96 function (bk,explicit_original_node) {
99 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
100 if (ev.explicitOriginalTarget != explicit_original_node) return;
101 var key = bk + 'checked';
103 if (ev.explicitOriginalTarget.nodeName == 'checkbox') {
104 value = ev.explicitOriginalTarget.checked;
106 value = ev.explicitOriginalTarget.getAttribute('checked'); // menuitem with type="checkbox"
108 ev.explicitOriginalTarget.setAttribute( 'checked', value );
109 prefs.setCharPref( key, value );
110 dump('persist_helper: setting key = ' + key + ' value = ' + value + ' for checkbox/menuitem via <command>\n');
112 alert('Error in persist_helper(), checkbox/menuitem -> command, command event listener: ' + E);
115 }( base_key, nodes[i] ),
119 nodes[i].addEventListener(
122 return function(ev) {
124 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
125 var key = bk + 'checked';
127 if (ev.target.nodeName == 'checkbox') {
128 value = ev.target.checked;
130 value = ev.target.getAttribute('checked'); // menuitem with type="checkbox"
132 ev.target.setAttribute( 'checked', value );
133 prefs.setCharPref( key, value );
134 dump('persist_helper: setting key = ' + key + ' value = ' + value + ' for checkbox/menuitem\n');
136 alert('Error in persist_helper(), checkbox/menuitem command event listener: ' + E);
143 } else if ( (nodes[i].nodeName == 'textbox') && attribute_list.indexOf('value') > -1) {
144 if (nodes[i].disabled == false && nodes[i].hidden == false) {
145 var no_poke = nodes[i].getAttribute('oils_persist_no_poke');
146 if (no_poke && no_poke == 'true') {
147 dump('\tpersist_helper: not poking element with key = ' + key + '\n');
149 dump('\tpersist_helper: poking element with key = ' + key + '\n');
150 var evt = document.createEvent("Events");
151 evt.initEvent( 'change', true, true );
152 nodes[i].dispatchEvent(evt);
155 nodes[i].addEventListener(
158 return function(ev) {
160 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
161 var key = bk + 'value';
162 var value = ev.target.value;
163 ev.target.setAttribute( 'value', value );
164 prefs.setCharPref( key, value );
165 dump('persist_helper: setting key = ' + key + ' value = ' + value + ' for value\n');
167 alert('Error in persist_helper(), textbox change event listener: ' + E);
174 // TODO: Need to add event listeners for window resizing, splitter repositioning, grippy state, etc.
177 alert('Error in persist_helper(): ' + E);
181 function getKeys(o) {
183 for (var k in o) keys.push(k);
187 function get_contentWindow(frame) {
189 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
190 if (frame && frame.contentWindow) {
192 if (typeof frame.contentWindow.wrappedJSObject != 'undefined') {
193 return frame.contentWindow.wrappedJSObject;
196 var Strings = $('offlineStrings') || $('commonStrings');
197 alert(Strings.getFormattedString('openils.global_util.content_window_jsobject.error', [frame, E]));
199 return frame.contentWindow;
204 var Strings = $('offlineStrings') || $('commonStrings');
205 alert(Strings.getFormattedString('openils.global_util.content_window.error', [frame, E]));
209 function update_modal_xulG(v) {
211 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
212 var key = location.pathname + location.search + location.hash;
213 if (typeof data.modal_xulG_stack != 'undefined' && typeof data.modal_xulG_stack[key] != 'undefined') {
214 data.modal_xulG_stack[key][ data.modal_xulG_stack[key].length - 1 ] = v;
215 data.stash('modal_xulG_stack');
218 alert('FIXME: update_modal_xulG => ' + E);
222 function xul_param(param_name,_params) {
223 /* 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 */
225 //dump('xul_param('+param_name+','+js2JSON(_params)+')\n');
226 var value = undefined; if (!_params) _params = {};
227 if (typeof _params.no_cgi == 'undefined') {
229 if (cgi.param(param_name)) {
230 var x = cgi.param(param_name);
231 //dump('\tfound via location.href = ' + x + '\n');
232 if (typeof _params.JSON2js_if_cgi != 'undefined') {
234 //dump('\tJSON2js = ' + x + '\n');
236 if (typeof _params.concat == 'undefined') {
237 //alert(param_name + ' x = ' + x);
241 if (value.constructor != Array) value = [ value ];
242 value = value.concat(x);
249 if (typeof _params.no_xulG == 'undefined') {
250 if (typeof _params.modal_xulG != 'undefined') {
251 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
252 var key = location.pathname + location.search + location.hash;
253 //dump('xul_param, considering modal key = ' + key + '\n');
254 if (typeof data.modal_xulG_stack != 'undefined' && typeof data.modal_xulG_stack[key] != 'undefined') {
255 xulG = data.modal_xulG_stack[key][ data.modal_xulG_stack[key].length - 1 ];
258 if (typeof xulG == 'object' && typeof xulG[ param_name ] != 'undefined') {
259 var x = xulG[ param_name ];
260 //dump('\tfound via xulG = ' + x + '\n');
261 if (typeof _params.JSON2js_if_xulG != 'undefined') {
263 //dump('\tJSON2js = ' + x + '\n');
265 if (typeof _params.concat == 'undefined') {
266 //alert(param_name + ' x = ' + x);
270 if (value.constructor != Array) value = [ value ];
271 value = value.concat(x);
278 if (typeof _params.no_xpcom == 'undefined') {
279 /* 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 */
280 if (typeof _params.stash_name != 'undefined') {
281 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
282 if (typeof data[ _params.stash_name ] != 'undefined') {
283 var x = data[ _params.stash_name ];
284 //dump('\tfound via xpcom = ' + x + '\n');
285 if (typeof _params.JSON2js_if_xpcom != 'undefined') {
287 //dump('\tJSON2js = ' + x + '\n');
289 if (_params.clear_xpcom) {
290 data[ _params.stash_name ] = undefined; data.stash( _params.stash_name );
292 if (typeof _params.concat == 'undefined') {
293 //alert(param_name + ' x = ' + x);
297 if (value.constructor != Array) value = [ value ];
298 value = value.concat(x);
306 //alert(param_name + ' value = ' + value);
309 dump('xul_param error: ' + E + '\n');
313 function get_bool(a) {
314 // Normal javascript interpretation except 'f' == false, per postgres, and 'F' == false, and '0' == false (newer JSON is returning '0' instead of 0 in cases)
315 // So false includes 'f', '', '0', 0, null, and undefined
316 if (a == 'f') return false;
317 if (a == 'F') return false;
318 if (a == '0') return false;
319 if (a) return true; else return false;
322 function get_db_true() {
326 function get_db_false() {
330 function copy_to_clipboard(ev) {
332 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
334 if (typeof ev == 'object') {
335 if (typeof ev.target != 'undefined') {
336 if (typeof ev.target.textContent != 'undefined') if (ev.target.textContent) text = ev.target.textContent;
337 if (typeof ev.target.value != 'undefined') if (ev.target.value) text = ev.target.value;
339 } else if (typeof ev == 'string') {
342 const gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"]
343 .getService(Components.interfaces.nsIClipboardHelper);
344 gClipboardHelper.copyString(text);
345 var Strings = $('offlineStrings') || $('commonStrings');
346 alert(Strings.getFormattedString('openils.global_util.clipboard', [text]));
348 var Strings = $('offlineStrings') || $('commonStrings');
349 alert(Strings.getFormattedString('openils.global_util.clipboard.error', [E]));
353 function clear_the_cache() {
355 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
356 var cacheClass = Components.classes["@mozilla.org/network/cache-service;1"];
357 var cacheService = cacheClass.getService(Components.interfaces.nsICacheService);
358 cacheService.evictEntries(Components.interfaces.nsICache.STORE_ON_DISK);
359 cacheService.evictEntries(Components.interfaces.nsICache.STORE_IN_MEMORY);
361 var Strings = $('offlineStrings') || $('commonStrings');
362 alert(Strings.getFormattedString('openils.global_util.clear_cache.error', [E]));
366 function toOpenWindowByType(inType, uri) {
367 var winopts = "chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar";
368 window.open(uri, "_blank", winopts);
371 function url_prefix(url) {
372 if (url.match(/^\//)) url = urls.remote + url;
373 if (! url.match(/^(http|chrome):\/\//) && ! url.match(/^data:/) ) url = 'http://' + url;
374 dump('url_prefix = ' + url + '\n');