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 oils_persist(e) {
55 var evt = document.createEvent("Events");
56 evt.initEvent( 'oils_persist', true, true );
59 alert('Error with oils_persist():' + E);
63 function persist_helper() {
65 function gen_event_handler(etype,node) {
68 var evt = document.createEvent("Events");
69 evt.initEvent( 'oils_persist', true, true );
70 ev.target.dispatchEvent(evt);
72 alert('Error in persist_helper, firing virtual event oils_persist after ' + etype + ' event on ' + node.nodeName + '.id = ' + node.id + ': ' + E);
77 function gen_oils_persist_handler(bk,node) {
80 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
82 if (ev.target.nodeName == 'command') {
84 if (ev.explicitOriginalTarget != node) return;
88 var filename = location.pathname.split('/')[ location.pathname.split('/').length - 1 ];
89 var base_key = 'oils_persist_' + String(location.hostname + '_' + filename + '_' + target.getAttribute('id')).replace('/','_','g') + '_';
90 var attribute_list = target.getAttribute('oils_persist').split(' ');
91 dump('persist_helper: <<< ' + target.nodeName + '.id = ' + target.id + '\t' + bk + '\n');
92 for (var j = 0; j < attribute_list.length; j++) {
93 var key = base_key + attribute_list[j];
94 var value = target.getAttribute( attribute_list[j] );
95 if ( attribute_list[j] == 'checked' && ['checkbox','toolbarbutton'].indexOf( target.nodeName ) > -1 ) {
96 value = target.checked;
97 dump('\t' + value + ' <== .' + attribute_list[j] + '\n');
98 } else if ( attribute_list[j] == 'value' && ['textbox'].indexOf( target.nodeName ) > -1 ) {
100 dump('\t' + value + ' <== .' + attribute_list[j] + '\n');
102 dump('\t' + value + ' <== @' + attribute_list[j] + '\n');
104 prefs.setCharPref( key, value );
105 // TODO: Need to add logic for window resizing, splitter repositioning, grippy state, etc.
108 alert('Error in persist_helper() event listener for ' + bk + ': ' + E);
113 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
114 var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces['nsIPrefBranch']);
115 var nodes = document.getElementsByAttribute('oils_persist','*');
116 for (var i = 0; i < nodes.length; i++) {
117 var filename = location.pathname.split('/')[ location.pathname.split('/').length - 1 ];
118 var base_key = 'oils_persist_' + String(location.hostname + '_' + filename + '_' + nodes[i].getAttribute('id')).replace('/','_','g') + '_';
119 var attribute_list = nodes[i].getAttribute('oils_persist').split(' ');
120 dump('persist_helper: >>> ' + nodes[i].nodeName + '.id = ' + nodes[i].id + '\t' + base_key + '\n');
121 for (var j = 0; j < attribute_list.length; j++) {
122 var key = base_key + attribute_list[j];
123 var has_key = prefs.prefHasUserValue(key);
124 var value = has_key ? prefs.getCharPref(key) : null;
125 if (value == 'true') { value = true; }
126 if (value == 'false') { value = false; }
128 if ( attribute_list[j] == 'checked' && ['checkbox','toolbarbutton'].indexOf( nodes[i].nodeName ) > -1 ) {
129 nodes[i].checked = value;
130 dump('\t' + value + ' ==> .' + attribute_list[j] + '\n');
132 nodes[i].removeAttribute('checked');
133 dump('\tremoving @checked\n');
135 } else if ( attribute_list[j] == 'value' && ['textbox'].indexOf( nodes[i].nodeName ) > -1 ) {
136 nodes[i].value = value;
137 dump('\t' + value + ' ==> .' + attribute_list[j] + '\n');
139 nodes[i].setAttribute( attribute_list[j], value);
140 dump('\t' + value + ' ==> @' + attribute_list[j] + '\n');
144 var cmd = nodes[i].getAttribute('command');
145 var cmd_el = document.getElementById(cmd);
146 if (nodes[i].disabled == false && nodes[i].hidden == false) {
147 var no_poke = nodes[i].getAttribute('oils_persist_no_poke');
148 if (no_poke && no_poke == 'true') {
149 // Timing issue for some checkboxes; don't poke them with an event
150 dump('\tnot poking\n');
153 dump('\tpoking @command\n');
154 var evt = document.createEvent("Events");
155 evt.initEvent( 'command', true, true );
156 cmd_el.dispatchEvent(evt);
159 var evt = document.createEvent("Events");
160 evt.initEvent( 'command', true, true );
161 nodes[i].dispatchEvent(evt);
166 cmd_el.addEventListener(
168 gen_event_handler('command',cmd_el),
171 cmd_el.addEventListener(
173 gen_oils_persist_handler( base_key, nodes[i] ),
177 var event_types = [];
178 if (nodes[i].hasAttribute('oils_persist_events')) {
179 var event_type_list = nodes[i].getAttribute('oils_persist_events').split(' ');
180 for (var j = 0; j < event_type_list.length; j++) {
181 event_types.push( event_type_list[j] );
184 if (nodes[i].nodeName == 'textbox') {
185 event_types.push('change');
187 event_types.push('command');
190 for (var j = 0; j < event_types.length; j++) {
191 nodes[i].addEventListener(
193 gen_event_handler(event_types[j],nodes[i]),
197 nodes[i].addEventListener(
199 gen_oils_persist_handler( base_key, nodes[i] ),
205 alert('Error in persist_helper(): ' + E);
209 function getKeys(o) {
211 for (var k in o) keys.push(k);
215 function get_contentWindow(frame) {
217 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
218 if (frame && frame.contentWindow) {
220 if (typeof frame.contentWindow.wrappedJSObject != 'undefined') {
221 return frame.contentWindow.wrappedJSObject;
224 var Strings = $('offlineStrings') || $('commonStrings');
225 alert(Strings.getFormattedString('openils.global_util.content_window_jsobject.error', [frame, E]));
227 return frame.contentWindow;
232 var Strings = $('offlineStrings') || $('commonStrings');
233 alert(Strings.getFormattedString('openils.global_util.content_window.error', [frame, E]));
237 function update_modal_xulG(v) {
239 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
240 var key = location.pathname + location.search + location.hash;
241 if (typeof data.modal_xulG_stack != 'undefined' && typeof data.modal_xulG_stack[key] != 'undefined') {
242 data.modal_xulG_stack[key][ data.modal_xulG_stack[key].length - 1 ] = v;
243 data.stash('modal_xulG_stack');
246 alert('FIXME: update_modal_xulG => ' + E);
250 function xul_param(param_name,_params) {
251 /* 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 */
253 //dump('xul_param('+param_name+','+js2JSON(_params)+')\n');
254 var value = undefined; if (!_params) _params = {};
255 if (typeof _params.no_cgi == 'undefined') {
257 if (cgi.param(param_name)) {
258 var x = cgi.param(param_name);
259 //dump('\tfound via location.href = ' + x + '\n');
260 if (typeof _params.JSON2js_if_cgi != 'undefined') {
262 //dump('\tJSON2js = ' + x + '\n');
264 if (typeof _params.concat == 'undefined') {
265 //alert(param_name + ' x = ' + x);
269 if (value.constructor != Array) value = [ value ];
270 value = value.concat(x);
277 if (typeof _params.no_xulG == 'undefined') {
278 if (typeof _params.modal_xulG != 'undefined') {
279 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
280 var key = location.pathname + location.search + location.hash;
281 //dump('xul_param, considering modal key = ' + key + '\n');
282 if (typeof data.modal_xulG_stack != 'undefined' && typeof data.modal_xulG_stack[key] != 'undefined') {
283 xulG = data.modal_xulG_stack[key][ data.modal_xulG_stack[key].length - 1 ];
286 if (typeof xulG == 'object' && typeof xulG[ param_name ] != 'undefined') {
287 var x = xulG[ param_name ];
288 //dump('\tfound via xulG = ' + x + '\n');
289 if (typeof _params.JSON2js_if_xulG != 'undefined') {
291 //dump('\tJSON2js = ' + x + '\n');
293 if (typeof _params.concat == 'undefined') {
294 //alert(param_name + ' x = ' + x);
298 if (value.constructor != Array) value = [ value ];
299 value = value.concat(x);
306 if (typeof _params.no_xpcom == 'undefined') {
307 /* 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 */
308 if (typeof _params.stash_name != 'undefined') {
309 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
310 if (typeof data[ _params.stash_name ] != 'undefined') {
311 var x = data[ _params.stash_name ];
312 //dump('\tfound via xpcom = ' + x + '\n');
313 if (typeof _params.JSON2js_if_xpcom != 'undefined') {
315 //dump('\tJSON2js = ' + x + '\n');
317 if (_params.clear_xpcom) {
318 data[ _params.stash_name ] = undefined; data.stash( _params.stash_name );
320 if (typeof _params.concat == 'undefined') {
321 //alert(param_name + ' x = ' + x);
325 if (value.constructor != Array) value = [ value ];
326 value = value.concat(x);
334 //alert(param_name + ' value = ' + value);
337 dump('xul_param error: ' + E + '\n');
341 function get_bool(a) {
342 // Normal javascript interpretation except 'f' == false, per postgres, and 'F' == false, and '0' == false (newer JSON is returning '0' instead of 0 in cases)
343 // So false includes 'f', '', '0', 0, null, and undefined
344 if (a == 'f') return false;
345 if (a == 'F') return false;
346 if (a == '0') return false;
347 if (a) return true; else return false;
350 function get_db_true() {
354 function get_db_false() {
358 function copy_to_clipboard(ev) {
360 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
362 if (typeof ev == 'object') {
363 if (typeof ev.target != 'undefined') {
364 if (typeof ev.target.textContent != 'undefined') if (ev.target.textContent) text = ev.target.textContent;
365 if (typeof ev.target.value != 'undefined') if (ev.target.value) text = ev.target.value;
367 } else if (typeof ev == 'string') {
370 const gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"]
371 .getService(Components.interfaces.nsIClipboardHelper);
372 gClipboardHelper.copyString(text);
373 var Strings = $('offlineStrings') || $('commonStrings');
374 alert(Strings.getFormattedString('openils.global_util.clipboard', [text]));
376 var Strings = $('offlineStrings') || $('commonStrings');
377 alert(Strings.getFormattedString('openils.global_util.clipboard.error', [E]));
381 function clear_the_cache() {
383 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
384 var cacheClass = Components.classes["@mozilla.org/network/cache-service;1"];
385 var cacheService = cacheClass.getService(Components.interfaces.nsICacheService);
386 cacheService.evictEntries(Components.interfaces.nsICache.STORE_ON_DISK);
387 cacheService.evictEntries(Components.interfaces.nsICache.STORE_IN_MEMORY);
389 var Strings = $('offlineStrings') || $('commonStrings');
390 alert(Strings.getFormattedString('openils.global_util.clear_cache.error', [E]));
394 function toOpenWindowByType(inType, uri) {
395 var winopts = "chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar";
396 window.open(uri, "_blank", winopts);
399 function url_prefix(url) {
400 if (url.match(/^\//)) url = urls.remote + url;
401 if (! url.match(/^(http|chrome):\/\//) && ! url.match(/^data:/) ) url = 'http://' + url;
402 dump('url_prefix = ' + url + '\n');