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 if (nodes[i].disabled == false && nodes[i].hidden == false) {
69 var no_poke = nodes[i].getAttribute('oils_persist_no_poke');
70 if (no_poke && no_poke == 'true') {
71 // Timing issue for some checkboxes; don't poke them with an event
73 var evt = document.createEvent("Events");
74 evt.initEvent( 'command', true, true );
75 nodes[i].dispatchEvent(evt);
78 nodes[i].addEventListener(
83 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
84 var key = bk + 'checked';
86 if (ev.target.nodeName == 'checkbox') {
87 value = ev.target.checked;
89 value = ev.target.getAttribute('checked'); // menuitem with type="checkbox"
91 ev.target.setAttribute( 'checked', value );
92 prefs.setCharPref( key, value );
93 dump('persist_helper: setting key = ' + key + ' value = ' + value + ' for checkbox/menuitem\n');
95 alert('Error in persist_helper(), checkbox/menuitem command event listener: ' + E);
102 // TODO: Need to add event listeners for window resizing, splitter repositioning, grippy state, etc.
105 alert('Error in persist_helper(): ' + E);
109 function getKeys(o) {
111 for (var k in o) keys.push(k);
115 function get_contentWindow(frame) {
117 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
118 if (frame && frame.contentWindow) {
120 if (typeof frame.contentWindow.wrappedJSObject != 'undefined') {
121 return frame.contentWindow.wrappedJSObject;
124 var Strings = $('offlineStrings') || $('commonStrings');
125 alert(Strings.getFormattedString('openils.global_util.content_window_jsobject.error', [frame, E]));
127 return frame.contentWindow;
132 var Strings = $('offlineStrings') || $('commonStrings');
133 alert(Strings.getFormattedString('openils.global_util.content_window.error', [frame, E]));
137 function update_modal_xulG(v) {
139 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
140 var key = location.pathname + location.search + location.hash;
141 if (typeof data.modal_xulG_stack != 'undefined' && typeof data.modal_xulG_stack[key] != 'undefined') {
142 data.modal_xulG_stack[key][ data.modal_xulG_stack[key].length - 1 ] = v;
143 data.stash('modal_xulG_stack');
146 alert('FIXME: update_modal_xulG => ' + E);
150 function xul_param(param_name,_params) {
151 /* 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 */
153 //dump('xul_param('+param_name+','+js2JSON(_params)+')\n');
154 var value = undefined; if (!_params) _params = {};
155 if (typeof _params.no_cgi == 'undefined') {
157 if (cgi.param(param_name)) {
158 var x = cgi.param(param_name);
159 //dump('\tfound via location.href = ' + x + '\n');
160 if (typeof _params.JSON2js_if_cgi != 'undefined') {
162 //dump('\tJSON2js = ' + x + '\n');
164 if (typeof _params.concat == 'undefined') {
165 //alert(param_name + ' x = ' + x);
169 if (value.constructor != Array) value = [ value ];
170 value = value.concat(x);
177 if (typeof _params.no_xulG == 'undefined') {
178 if (typeof _params.modal_xulG != 'undefined') {
179 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
180 var key = location.pathname + location.search + location.hash;
181 //dump('xul_param, considering modal key = ' + key + '\n');
182 if (typeof data.modal_xulG_stack != 'undefined' && typeof data.modal_xulG_stack[key] != 'undefined') {
183 xulG = data.modal_xulG_stack[key][ data.modal_xulG_stack[key].length - 1 ];
186 if (typeof xulG == 'object' && typeof xulG[ param_name ] != 'undefined') {
187 var x = xulG[ param_name ];
188 //dump('\tfound via xulG = ' + x + '\n');
189 if (typeof _params.JSON2js_if_xulG != 'undefined') {
191 //dump('\tJSON2js = ' + x + '\n');
193 if (typeof _params.concat == 'undefined') {
194 //alert(param_name + ' x = ' + x);
198 if (value.constructor != Array) value = [ value ];
199 value = value.concat(x);
206 if (typeof _params.no_xpcom == 'undefined') {
207 /* 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 */
208 if (typeof _params.stash_name != 'undefined') {
209 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
210 if (typeof data[ _params.stash_name ] != 'undefined') {
211 var x = data[ _params.stash_name ];
212 //dump('\tfound via xpcom = ' + x + '\n');
213 if (typeof _params.JSON2js_if_xpcom != 'undefined') {
215 //dump('\tJSON2js = ' + x + '\n');
217 if (_params.clear_xpcom) {
218 data[ _params.stash_name ] = undefined; data.stash( _params.stash_name );
220 if (typeof _params.concat == 'undefined') {
221 //alert(param_name + ' x = ' + x);
225 if (value.constructor != Array) value = [ value ];
226 value = value.concat(x);
234 //alert(param_name + ' value = ' + value);
237 dump('xul_param error: ' + E + '\n');
241 function get_bool(a) {
242 // Normal javascript interpretation except 'f' == false, per postgres, and 'F' == false, and '0' == false (newer JSON is returning '0' instead of 0 in cases)
243 // So false includes 'f', '', '0', 0, null, and undefined
244 if (a == 'f') return false;
245 if (a == 'F') return false;
246 if (a == '0') return false;
247 if (a) return true; else return false;
250 function get_db_true() {
254 function get_db_false() {
258 function copy_to_clipboard(ev) {
260 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
262 if (typeof ev == 'object') {
263 if (typeof ev.target != 'undefined') {
264 if (typeof ev.target.textContent != 'undefined') if (ev.target.textContent) text = ev.target.textContent;
265 if (typeof ev.target.value != 'undefined') if (ev.target.value) text = ev.target.value;
267 } else if (typeof ev == 'string') {
270 const gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"]
271 .getService(Components.interfaces.nsIClipboardHelper);
272 gClipboardHelper.copyString(text);
273 var Strings = $('offlineStrings') || $('commonStrings');
274 alert(Strings.getFormattedString('openils.global_util.clipboard', [text]));
276 var Strings = $('offlineStrings') || $('commonStrings');
277 alert(Strings.getFormattedString('openils.global_util.clipboard.error', [E]));
281 function clear_the_cache() {
283 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
284 var cacheClass = Components.classes["@mozilla.org/network/cache-service;1"];
285 var cacheService = cacheClass.getService(Components.interfaces.nsICacheService);
286 cacheService.evictEntries(Components.interfaces.nsICache.STORE_ON_DISK);
287 cacheService.evictEntries(Components.interfaces.nsICache.STORE_IN_MEMORY);
289 var Strings = $('offlineStrings') || $('commonStrings');
290 alert(Strings.getFormattedString('openils.global_util.clear_cache.error', [E]));
294 function toOpenWindowByType(inType, uri) {
295 var winopts = "chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar";
296 window.open(uri, "_blank", winopts);
299 function url_prefix(url) {
300 if (url.match(/^\//)) url = urls.remote + url;
301 if (! url.match(/^(http|chrome):\/\//) && ! url.match(/^data:/) ) url = 'http://' + url;
302 dump('url_prefix = ' + url + '\n');