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' : return data.list.au[0]; break;
16 case 'staff_id' : return data.list.au[0].id(); break;
17 case 'staff_usrname' : return data.list.au[0].usrname(); break;
19 return data.list.au[0].ws_ou();
22 return data.session.authtime;
26 return data.session.key;
30 alert(location.href + '\nError in global_utils.js, ses(): ' + E);
35 function font_helper() {
37 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
38 removeCSSClass(document.documentElement,'ALL_FONTS_LARGER');
39 removeCSSClass(document.documentElement,'ALL_FONTS_SMALLER');
40 removeCSSClass(document.documentElement,'ALL_FONTS_XX_SMALL');
41 removeCSSClass(document.documentElement,'ALL_FONTS_X_SMALL');
42 removeCSSClass(document.documentElement,'ALL_FONTS_SMALL');
43 removeCSSClass(document.documentElement,'ALL_FONTS_MEDIUM');
44 removeCSSClass(document.documentElement,'ALL_FONTS_LARGE');
45 removeCSSClass(document.documentElement,'ALL_FONTS_X_LARGE');
46 removeCSSClass(document.documentElement,'ALL_FONTS_XX_LARGE');
47 addCSSClass(document.documentElement,data.global_font_adjust);
49 var Strings = $('offlineStrings') || $('commonStrings');
50 alert(Strings.getFormattedString('openils.global_util.font_size.error', [E]));
54 function oils_persist(e,cancelable) {
57 if (typeof cancelable == 'undefined') { cancelable = false; }
58 var evt = document.createEvent("Events");
59 evt.initEvent( 'oils_persist', false, cancelable ); // event name, bubbles, cancelable
62 alert('Error with oils_persist():' + E);
66 function persist_helper() {
68 function gen_event_handler(etype,node) {
71 oils_persist(ev.target);
73 alert('Error in persist_helper, firing virtual event oils_persist after ' + etype + ' event on ' + node.nodeName + '.id = ' + node.id + ': ' + E);
78 function gen_oils_persist_handler(bk,node) {
81 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
83 if (ev.target.nodeName == 'command') {
85 if (ev.explicitOriginalTarget != node) return;
89 var filename = location.pathname.split('/')[ location.pathname.split('/').length - 1 ];
90 var base_key = 'oils_persist_' + String(location.hostname + '_' + filename + '_' + target.getAttribute('id')).replace('/','_','g') + '_';
91 var attribute_list = target.getAttribute('oils_persist').split(' ');
92 dump('on_oils_persist: <<< ' + target.nodeName + '.id = ' + target.id + '\t' + bk + '\n');
93 for (var j = 0; j < attribute_list.length; j++) {
94 var key = base_key + attribute_list[j];
95 var value = target.getAttribute( attribute_list[j] );
96 if ( attribute_list[j] == 'checked' && ['checkbox','toolbarbutton'].indexOf( target.nodeName ) > -1 ) {
97 value = target.checked;
98 dump('\t' + value + ' <== .' + attribute_list[j] + '\n');
99 } else if ( attribute_list[j] == 'value' && ['textbox'].indexOf( target.nodeName ) > -1 ) {
100 value = target.value;
101 dump('\t' + value + ' <== .' + attribute_list[j] + '\n');
103 dump('\t' + value + ' <== @' + attribute_list[j] + '\n');
105 prefs.setCharPref( key, value );
106 // TODO: Need to add logic for window resizing, splitter repositioning, grippy state, etc.
108 if (target.hasAttribute('oils_persist_peers') && ! ev.cancelable) { // We abuse the .cancelable field on the oils_persist event to prevent looping
109 var peer_list = target.getAttribute('oils_persist_peers').split(' ');
110 for (var j = 0; j < peer_list.length; j++) {
111 dump('on_oils_persist: dispatching oils_persist to peer ' + peer_list[j] + '\n');
112 oils_persist( document.getElementById( peer_list[j] ), true );
116 alert('Error in persist_helper() event listener for ' + bk + ': ' + E);
121 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
122 var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces['nsIPrefBranch']);
123 var nodes = document.getElementsByAttribute('oils_persist','*');
124 for (var i = 0; i < nodes.length; i++) {
125 var filename = location.pathname.split('/')[ location.pathname.split('/').length - 1 ];
126 var base_key = 'oils_persist_' + String(location.hostname + '_' + filename + '_' + nodes[i].getAttribute('id')).replace('/','_','g') + '_';
127 var attribute_list = nodes[i].getAttribute('oils_persist').split(' ');
128 dump('persist_helper: >>> ' + nodes[i].nodeName + '.id = ' + nodes[i].id + '\t' + base_key + '\n');
129 for (var j = 0; j < attribute_list.length; j++) {
130 var key = base_key + attribute_list[j];
131 var has_key = prefs.prefHasUserValue(key);
132 var value = has_key ? prefs.getCharPref(key) : null;
133 if (value == 'true') { value = true; }
134 if (value == 'false') { value = false; }
136 if ( attribute_list[j] == 'checked' && ['checkbox','toolbarbutton'].indexOf( nodes[i].nodeName ) > -1 ) {
137 nodes[i].checked = value;
138 dump('\t' + value + ' ==> .' + attribute_list[j] + '\n');
140 nodes[i].removeAttribute('checked');
141 dump('\tremoving @checked\n');
143 } else if ( attribute_list[j] == 'value' && ['textbox'].indexOf( nodes[i].nodeName ) > -1 ) {
144 nodes[i].value = value;
145 dump('\t' + value + ' ==> .' + attribute_list[j] + '\n');
147 nodes[i].setAttribute( attribute_list[j], value);
148 dump('\t' + value + ' ==> @' + attribute_list[j] + '\n');
152 var cmd = nodes[i].getAttribute('command');
153 var cmd_el = document.getElementById(cmd);
154 if (nodes[i].disabled == false && nodes[i].hidden == false) {
155 var no_poke = nodes[i].getAttribute('oils_persist_no_poke');
156 if (no_poke && no_poke == 'true') {
157 // Timing issue for some checkboxes; don't poke them with an event
158 dump('\tnot poking\n');
161 dump('\tpoking @command\n');
162 var evt = document.createEvent("Events");
163 evt.initEvent( 'command', true, true );
164 cmd_el.dispatchEvent(evt);
167 var evt = document.createEvent("Events");
168 evt.initEvent( 'command', true, true );
169 nodes[i].dispatchEvent(evt);
174 cmd_el.addEventListener(
176 gen_event_handler('command',cmd_el),
179 cmd_el.addEventListener(
181 gen_oils_persist_handler( base_key, nodes[i] ),
185 var event_types = [];
186 if (nodes[i].hasAttribute('oils_persist_events')) {
187 var event_type_list = nodes[i].getAttribute('oils_persist_events').split(' ');
188 for (var j = 0; j < event_type_list.length; j++) {
189 event_types.push( event_type_list[j] );
192 if (nodes[i].nodeName == 'textbox') {
193 event_types.push('change');
195 event_types.push('command');
198 for (var j = 0; j < event_types.length; j++) {
199 nodes[i].addEventListener(
201 gen_event_handler(event_types[j],nodes[i]),
205 nodes[i].addEventListener(
207 gen_oils_persist_handler( base_key, nodes[i] ),
213 alert('Error in persist_helper(): ' + E);
217 function getKeys(o) {
219 for (var k in o) keys.push(k);
223 function get_contentWindow(frame) {
225 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
226 if (frame && frame.contentWindow) {
228 if (typeof frame.contentWindow.wrappedJSObject != 'undefined') {
229 return frame.contentWindow.wrappedJSObject;
232 var Strings = $('offlineStrings') || $('commonStrings');
233 alert(Strings.getFormattedString('openils.global_util.content_window_jsobject.error', [frame, E]));
235 return frame.contentWindow;
240 var Strings = $('offlineStrings') || $('commonStrings');
241 alert(Strings.getFormattedString('openils.global_util.content_window.error', [frame, E]));
245 function update_modal_xulG(v) {
247 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
248 var key = location.pathname + location.search + location.hash;
249 if (typeof data.modal_xulG_stack != 'undefined' && typeof data.modal_xulG_stack[key] != 'undefined') {
250 data.modal_xulG_stack[key][ data.modal_xulG_stack[key].length - 1 ] = v;
251 data.stash('modal_xulG_stack');
254 alert('FIXME: update_modal_xulG => ' + E);
258 function xul_param(param_name,_params) {
259 /* 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 */
261 //dump('xul_param('+param_name+','+js2JSON(_params)+')\n');
262 var value = undefined; if (!_params) _params = {};
263 if (typeof _params.no_cgi == 'undefined') {
265 if (cgi.param(param_name)) {
266 var x = cgi.param(param_name);
267 //dump('\tfound via location.href = ' + x + '\n');
268 if (typeof _params.JSON2js_if_cgi != 'undefined') {
270 //dump('\tJSON2js = ' + x + '\n');
272 if (typeof _params.concat == 'undefined') {
273 //alert(param_name + ' x = ' + x);
277 if (value.constructor != Array) value = [ value ];
278 value = value.concat(x);
285 if (typeof _params.no_xulG == 'undefined') {
286 if (typeof _params.modal_xulG != 'undefined') {
287 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
288 var key = location.pathname + location.search + location.hash;
289 //dump('xul_param, considering modal key = ' + key + '\n');
290 if (typeof data.modal_xulG_stack != 'undefined' && typeof data.modal_xulG_stack[key] != 'undefined') {
291 xulG = data.modal_xulG_stack[key][ data.modal_xulG_stack[key].length - 1 ];
294 if (typeof xulG == 'object' && typeof xulG[ param_name ] != 'undefined') {
295 var x = xulG[ param_name ];
296 //dump('\tfound via xulG = ' + x + '\n');
297 if (typeof _params.JSON2js_if_xulG != 'undefined') {
299 //dump('\tJSON2js = ' + x + '\n');
301 if (typeof _params.concat == 'undefined') {
302 //alert(param_name + ' x = ' + x);
306 if (value.constructor != Array) value = [ value ];
307 value = value.concat(x);
314 if (typeof _params.no_xpcom == 'undefined') {
315 /* 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 */
316 if (typeof _params.stash_name != 'undefined') {
317 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
318 if (typeof data[ _params.stash_name ] != 'undefined') {
319 var x = data[ _params.stash_name ];
320 //dump('\tfound via xpcom = ' + x + '\n');
321 if (typeof _params.JSON2js_if_xpcom != 'undefined') {
323 //dump('\tJSON2js = ' + x + '\n');
325 if (_params.clear_xpcom) {
326 data[ _params.stash_name ] = undefined; data.stash( _params.stash_name );
328 if (typeof _params.concat == 'undefined') {
329 //alert(param_name + ' x = ' + x);
333 if (value.constructor != Array) value = [ value ];
334 value = value.concat(x);
342 //alert(param_name + ' value = ' + value);
345 dump('xul_param error: ' + E + '\n');
349 function get_bool(a) {
350 // Normal javascript interpretation except 'f' == false, per postgres, and 'F' == false, and '0' == false (newer JSON is returning '0' instead of 0 in cases)
351 // So false includes 'f', '', '0', 0, null, and undefined
352 if (a == 'f') return false;
353 if (a == 'F') return false;
354 if (a == '0') return false;
355 if (a) return true; else return false;
358 function get_db_true() {
362 function get_db_false() {
366 function copy_to_clipboard(ev) {
368 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
370 if (typeof ev == 'object') {
371 if (typeof ev.target != 'undefined') {
372 if (typeof ev.target.textContent != 'undefined') if (ev.target.textContent) text = ev.target.textContent;
373 if (typeof ev.target.value != 'undefined') if (ev.target.value) text = ev.target.value;
375 } else if (typeof ev == 'string') {
378 const gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"]
379 .getService(Components.interfaces.nsIClipboardHelper);
380 gClipboardHelper.copyString(text);
381 var Strings = $('offlineStrings') || $('commonStrings');
382 alert(Strings.getFormattedString('openils.global_util.clipboard', [text]));
384 var Strings = $('offlineStrings') || $('commonStrings');
385 alert(Strings.getFormattedString('openils.global_util.clipboard.error', [E]));
389 function clear_the_cache() {
391 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
392 var cacheClass = Components.classes["@mozilla.org/network/cache-service;1"];
393 var cacheService = cacheClass.getService(Components.interfaces.nsICacheService);
394 cacheService.evictEntries(Components.interfaces.nsICache.STORE_ON_DISK);
395 cacheService.evictEntries(Components.interfaces.nsICache.STORE_IN_MEMORY);
397 var Strings = $('offlineStrings') || $('commonStrings');
398 alert(Strings.getFormattedString('openils.global_util.clear_cache.error', [E]));
402 function toOpenWindowByType(inType, uri) {
403 var winopts = "chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar";
404 window.open(uri, "_blank", winopts);
407 function url_prefix(url) {
408 if (url.match(/^\//)) url = urls.remote + url;
409 if (! url.match(/^(http|chrome):\/\//) && ! url.match(/^data:/) ) url = 'http://' + url;
410 dump('url_prefix = ' + url + '\n');