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 base_key = 'oils_persist_' + String(location.hostname + location.pathname + '_' + nodes[i].getAttribute('id')).replace('/','_','g') + '_';
60 var attribute_list = nodes[i].getAttribute('oils_persist').split(' ');
61 for (var j = 0; j < attribute_list.length; j++) {
62 var key = base_key + attribute_list[j];
63 var value = prefs.prefHasUserValue(key) ? prefs.getCharPref(key) : null;
64 dump('persist_helper: retrieving key = ' + key + ' value = ' + value + ' for ' + nodes[i].nodeName + '\n');
65 if (value) nodes[i].setAttribute( attribute_list[j], value );
67 if ( (nodes[i].nodeName == 'checkbox' || nodes[i].nodeName == 'menuitem') && attribute_list.indexOf('checked') > -1) {
68 var cmd = nodes[i].getAttribute('command');
69 var cmd_el = document.getElementById(cmd);
70 if (nodes[i].disabled == false && nodes[i].hidden == false) {
71 var no_poke = nodes[i].getAttribute('oils_persist_no_poke');
72 if (no_poke && no_poke == 'true') {
73 // Timing issue for some checkboxes; don't poke them with an event
74 dump('\tpersist_helper: not poking element with key = ' + key + '\n');
77 dump('\tpersist_helper: poking @command element for element with key = ' + key + '\n');
78 var evt = document.createEvent("Events");
79 evt.initEvent( 'command', true, true );
80 cmd_el.dispatchEvent(evt);
82 dump('\tpersist_helper: poking element with key = ' + key + '\n');
83 var evt = document.createEvent("Events");
84 evt.initEvent( 'command', true, true );
85 nodes[i].dispatchEvent(evt);
90 cmd_el.addEventListener(
92 function (bk,explicit_original_node) {
95 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
96 if (ev.explicitOriginalTarget != explicit_original_node) return;
97 var key = bk + 'checked';
99 if (ev.explicitOriginalTarget.nodeName == 'checkbox') {
100 value = ev.explicitOriginalTarget.checked;
102 value = ev.explicitOriginalTarget.getAttribute('checked'); // menuitem with type="checkbox"
104 ev.explicitOriginalTarget.setAttribute( 'checked', value );
105 prefs.setCharPref( key, value );
106 dump('persist_helper: setting key = ' + key + ' value = ' + value + ' for checkbox/menuitem via <command>\n');
108 alert('Error in persist_helper(), checkbox/menuitem -> command, command event listener: ' + E);
111 }( base_key, nodes[i] ),
115 nodes[i].addEventListener(
118 return function(ev) {
120 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
121 var key = bk + 'checked';
123 if (ev.target.nodeName == 'checkbox') {
124 value = ev.target.checked;
126 value = ev.target.getAttribute('checked'); // menuitem with type="checkbox"
128 ev.target.setAttribute( 'checked', value );
129 prefs.setCharPref( key, value );
130 dump('persist_helper: setting key = ' + key + ' value = ' + value + ' for checkbox/menuitem\n');
132 alert('Error in persist_helper(), checkbox/menuitem command event listener: ' + E);
140 // TODO: Need to add event listeners for window resizing, splitter repositioning, grippy state, etc.
143 alert('Error in persist_helper(): ' + E);
147 function getKeys(o) {
149 for (var k in o) keys.push(k);
153 function get_contentWindow(frame) {
155 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
156 if (frame && frame.contentWindow) {
158 if (typeof frame.contentWindow.wrappedJSObject != 'undefined') {
159 return frame.contentWindow.wrappedJSObject;
162 var Strings = $('offlineStrings') || $('commonStrings');
163 alert(Strings.getFormattedString('openils.global_util.content_window_jsobject.error', [frame, E]));
165 return frame.contentWindow;
170 var Strings = $('offlineStrings') || $('commonStrings');
171 alert(Strings.getFormattedString('openils.global_util.content_window.error', [frame, E]));
175 function update_modal_xulG(v) {
177 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
178 var key = location.pathname + location.search + location.hash;
179 if (typeof data.modal_xulG_stack != 'undefined' && typeof data.modal_xulG_stack[key] != 'undefined') {
180 data.modal_xulG_stack[key][ data.modal_xulG_stack[key].length - 1 ] = v;
181 data.stash('modal_xulG_stack');
184 alert('FIXME: update_modal_xulG => ' + E);
188 function xul_param(param_name,_params) {
189 /* 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 */
191 //dump('xul_param('+param_name+','+js2JSON(_params)+')\n');
192 var value = undefined; if (!_params) _params = {};
193 if (typeof _params.no_cgi == 'undefined') {
195 if (cgi.param(param_name)) {
196 var x = cgi.param(param_name);
197 //dump('\tfound via location.href = ' + x + '\n');
198 if (typeof _params.JSON2js_if_cgi != 'undefined') {
200 //dump('\tJSON2js = ' + x + '\n');
202 if (typeof _params.concat == 'undefined') {
203 //alert(param_name + ' x = ' + x);
207 if (value.constructor != Array) value = [ value ];
208 value = value.concat(x);
215 if (typeof _params.no_xulG == 'undefined') {
216 if (typeof _params.modal_xulG != 'undefined') {
217 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
218 var key = location.pathname + location.search + location.hash;
219 //dump('xul_param, considering modal key = ' + key + '\n');
220 if (typeof data.modal_xulG_stack != 'undefined' && typeof data.modal_xulG_stack[key] != 'undefined') {
221 xulG = data.modal_xulG_stack[key][ data.modal_xulG_stack[key].length - 1 ];
224 if (typeof xulG == 'object' && typeof xulG[ param_name ] != 'undefined') {
225 var x = xulG[ param_name ];
226 //dump('\tfound via xulG = ' + x + '\n');
227 if (typeof _params.JSON2js_if_xulG != 'undefined') {
229 //dump('\tJSON2js = ' + x + '\n');
231 if (typeof _params.concat == 'undefined') {
232 //alert(param_name + ' x = ' + x);
236 if (value.constructor != Array) value = [ value ];
237 value = value.concat(x);
244 if (typeof _params.no_xpcom == 'undefined') {
245 /* 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 */
246 if (typeof _params.stash_name != 'undefined') {
247 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
248 if (typeof data[ _params.stash_name ] != 'undefined') {
249 var x = data[ _params.stash_name ];
250 //dump('\tfound via xpcom = ' + x + '\n');
251 if (typeof _params.JSON2js_if_xpcom != 'undefined') {
253 //dump('\tJSON2js = ' + x + '\n');
255 if (_params.clear_xpcom) {
256 data[ _params.stash_name ] = undefined; data.stash( _params.stash_name );
258 if (typeof _params.concat == 'undefined') {
259 //alert(param_name + ' x = ' + x);
263 if (value.constructor != Array) value = [ value ];
264 value = value.concat(x);
272 //alert(param_name + ' value = ' + value);
275 dump('xul_param error: ' + E + '\n');
279 function get_bool(a) {
280 // Normal javascript interpretation except 'f' == false, per postgres, and 'F' == false, and '0' == false (newer JSON is returning '0' instead of 0 in cases)
281 // So false includes 'f', '', '0', 0, null, and undefined
282 if (a == 'f') return false;
283 if (a == 'F') return false;
284 if (a == '0') return false;
285 if (a) return true; else return false;
288 function get_db_true() {
292 function get_db_false() {
296 function copy_to_clipboard(ev) {
298 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
300 if (typeof ev == 'object') {
301 if (typeof ev.target != 'undefined') {
302 if (typeof ev.target.textContent != 'undefined') if (ev.target.textContent) text = ev.target.textContent;
303 if (typeof ev.target.value != 'undefined') if (ev.target.value) text = ev.target.value;
305 } else if (typeof ev == 'string') {
308 const gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"]
309 .getService(Components.interfaces.nsIClipboardHelper);
310 gClipboardHelper.copyString(text);
311 var Strings = $('offlineStrings') || $('commonStrings');
312 alert(Strings.getFormattedString('openils.global_util.clipboard', [text]));
314 var Strings = $('offlineStrings') || $('commonStrings');
315 alert(Strings.getFormattedString('openils.global_util.clipboard.error', [E]));
319 function clear_the_cache() {
321 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
322 var cacheClass = Components.classes["@mozilla.org/network/cache-service;1"];
323 var cacheService = cacheClass.getService(Components.interfaces.nsICacheService);
324 cacheService.evictEntries(Components.interfaces.nsICache.STORE_ON_DISK);
325 cacheService.evictEntries(Components.interfaces.nsICache.STORE_IN_MEMORY);
327 var Strings = $('offlineStrings') || $('commonStrings');
328 alert(Strings.getFormattedString('openils.global_util.clear_cache.error', [E]));
332 function toOpenWindowByType(inType, uri) {
333 var winopts = "chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar";
334 window.open(uri, "_blank", winopts);
337 function url_prefix(url) {
338 if (url.match(/^\//)) url = urls.remote + url;
339 if (! url.match(/^(http|chrome):\/\//) && ! url.match(/^data:/) ) url = 'http://' + url;
340 dump('url_prefix = ' + url + '\n');