1 function $(id) { return document.getElementById(id); }
4 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
6 case 'staff_id' : return data.list.au[0].id(); break;
7 case 'staff_usrname' : return data.list.au[0].usrname(); break;
9 return data.list.au[0].ws_ou();
12 return data.session.authtime;
16 return data.session.key;
21 function font_helper() {
23 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
24 removeCSSClass(document.documentElement,'ALL_FONTS_LARGER');
25 removeCSSClass(document.documentElement,'ALL_FONTS_SMALLER');
26 removeCSSClass(document.documentElement,'ALL_FONTS_XX_SMALL');
27 removeCSSClass(document.documentElement,'ALL_FONTS_X_SMALL');
28 removeCSSClass(document.documentElement,'ALL_FONTS_SMALL');
29 removeCSSClass(document.documentElement,'ALL_FONTS_MEDIUM');
30 removeCSSClass(document.documentElement,'ALL_FONTS_LARGE');
31 removeCSSClass(document.documentElement,'ALL_FONTS_X_LARGE');
32 removeCSSClass(document.documentElement,'ALL_FONTS_XX_LARGE');
33 addCSSClass(document.documentElement,data.global_font_adjust);
35 var Strings = $('offlineStrings') || $('commonStrings');
36 alert(Strings.getFormattedString('openils.global_util.font_size.error', [E]));
40 function persist_helper() {
42 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
43 var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces['nsIPrefBranch']);
44 var nodes = document.getElementsByAttribute('oils_persist','*');
45 for (var i = 0; i < nodes.length; i++) {
46 var base_key = 'oils_persist_' + String(location.hostname + location.pathname + '_' + nodes[i].getAttribute('id')).replace('/','_','g') + '_';
47 var attribute_list = nodes[i].getAttribute('oils_persist').split(' ');
48 for (var j = 0; j < attribute_list.length; j++) {
49 var key = base_key + attribute_list[j];
50 var value = prefs.prefHasUserValue(key) ? prefs.getCharPref(key) : null;
51 dump('persist_helper: retrieving key = ' + key + ' value = ' + value + ' for ' + nodes[i].nodeName + '\n');
52 if (value) nodes[i].setAttribute( attribute_list[j], value );
54 if (nodes[i].nodeName == 'checkbox' && attribute_list.indexOf('checked') > -1) {
55 if (nodes[i].disabled == false && nodes[i].hidden == false) {
56 var no_poke = nodes[i].getAttribute('oils_persist_no_poke');
57 if (no_poke && no_poke == 'true') {
58 // Timing issue for some checkboxes; don't poke them with an event
60 var evt = document.createEvent("Events");
61 evt.initEvent( 'command', true, true );
62 nodes[i].dispatchEvent(evt);
65 nodes[i].addEventListener(
70 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
71 var key = bk + 'checked';
72 var value = ev.target.checked;
73 ev.target.setAttribute( 'checked', value );
74 prefs.setCharPref( key, value );
75 dump('persist_helper: setting key = ' + key + ' value = ' + value + ' for checkbox\n');
77 alert('Error in persist_helper(), checkbox command event listener: ' + E);
84 // TODO: Need to add event listeners for window resizing, splitter repositioning, grippy state, etc.
87 alert('Error in persist_helper(): ' + E);
93 for (var k in o) keys.push(k);
97 function get_contentWindow(frame) {
99 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
100 if (frame && frame.contentWindow) {
102 if (typeof frame.contentWindow.wrappedJSObject != 'undefined') {
103 return frame.contentWindow.wrappedJSObject;
106 var Strings = $('offlineStrings') || $('commonStrings');
107 alert(Strings.getFormattedString('openils.global_util.content_window_jsobject.error', [frame, E]));
109 return frame.contentWindow;
114 var Strings = $('offlineStrings') || $('commonStrings');
115 alert(Strings.getFormattedString('openils.global_util.content_window.error', [frame, E]));
119 function update_modal_xulG(v) {
121 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
122 var key = location.pathname + location.search + location.hash;
123 if (typeof data.modal_xulG_stack != 'undefined' && typeof data.modal_xulG_stack[key] != 'undefined') {
124 data.modal_xulG_stack[key][ data.modal_xulG_stack[key].length - 1 ] = v;
125 data.stash('modal_xulG_stack');
128 alert('FIXME: update_modal_xulG => ' + E);
132 function xul_param(param_name,_params) {
133 /* 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 */
135 //dump('xul_param('+param_name+','+js2JSON(_params)+')\n');
136 var value = undefined; if (!_params) _params = {};
137 if (typeof _params.no_cgi == 'undefined') {
139 if (cgi.param(param_name)) {
140 var x = cgi.param(param_name);
141 //dump('\tfound via location.href = ' + x + '\n');
142 if (typeof _params.JSON2js_if_cgi != 'undefined') {
144 //dump('\tJSON2js = ' + x + '\n');
146 if (typeof _params.concat == 'undefined') {
147 //alert(param_name + ' x = ' + x);
151 if (value.constructor != Array) value = [ value ];
152 value = value.concat(x);
159 if (typeof _params.no_xulG == 'undefined') {
160 if (typeof _params.modal_xulG != 'undefined') {
161 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
162 var key = location.pathname + location.search + location.hash;
163 //dump('xul_param, considering modal key = ' + key + '\n');
164 if (typeof data.modal_xulG_stack != 'undefined' && typeof data.modal_xulG_stack[key] != 'undefined') {
165 xulG = data.modal_xulG_stack[key][ data.modal_xulG_stack[key].length - 1 ];
168 if (typeof xulG == 'object' && typeof xulG[ param_name ] != 'undefined') {
169 var x = xulG[ param_name ];
170 //dump('\tfound via xulG = ' + x + '\n');
171 if (typeof _params.JSON2js_if_xulG != 'undefined') {
173 //dump('\tJSON2js = ' + x + '\n');
175 if (typeof _params.concat == 'undefined') {
176 //alert(param_name + ' x = ' + x);
180 if (value.constructor != Array) value = [ value ];
181 value = value.concat(x);
188 if (typeof _params.no_xpcom == 'undefined') {
189 /* 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 */
190 if (typeof _params.stash_name != 'undefined') {
191 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
192 if (typeof data[ _params.stash_name ] != 'undefined') {
193 var x = data[ _params.stash_name ];
194 //dump('\tfound via xpcom = ' + x + '\n');
195 if (typeof _params.JSON2js_if_xpcom != 'undefined') {
197 //dump('\tJSON2js = ' + x + '\n');
199 if (_params.clear_xpcom) {
200 data[ _params.stash_name ] = undefined; data.stash( _params.stash_name );
202 if (typeof _params.concat == 'undefined') {
203 //alert(param_name + ' x = ' + x);
207 if (value.constructor != Array) value = [ value ];
208 value = value.concat(x);
216 //alert(param_name + ' value = ' + value);
219 dump('xul_param error: ' + E + '\n');
223 function get_bool(a) {
224 // Normal javascript interpretation except 'f' == false, per postgres, and 'F' == false, and '0' == false (newer JSON is returning '0' instead of 0 in cases)
225 // So false includes 'f', '', '0', 0, null, and undefined
226 if (a == 'f') return false;
227 if (a == 'F') return false;
228 if (a == '0') return false;
229 if (a) return true; else return false;
232 function get_db_true() {
236 function get_db_false() {
240 function copy_to_clipboard(ev) {
242 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
244 if (typeof ev == 'object') {
245 if (typeof ev.target != 'undefined') {
246 if (typeof ev.target.textContent != 'undefined') if (ev.target.textContent) text = ev.target.textContent;
247 if (typeof ev.target.value != 'undefined') if (ev.target.value) text = ev.target.value;
249 } else if (typeof ev == 'string') {
252 const gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"]
253 .getService(Components.interfaces.nsIClipboardHelper);
254 gClipboardHelper.copyString(text);
255 var Strings = $('offlineStrings') || $('commonStrings');
256 alert(Strings.getFormattedString('openils.global_util.clipboard', [text]));
258 var Strings = $('offlineStrings') || $('commonStrings');
259 alert(Strings.getFormattedString('openils.global_util.clipboard.error', [E]));
263 function clear_the_cache() {
265 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
266 var cacheClass = Components.classes["@mozilla.org/network/cache-service;1"];
267 var cacheService = cacheClass.getService(Components.interfaces.nsICacheService);
268 cacheService.evictEntries(Components.interfaces.nsICache.STORE_ON_DISK);
269 cacheService.evictEntries(Components.interfaces.nsICache.STORE_IN_MEMORY);
271 var Strings = $('offlineStrings') || $('commonStrings');
272 alert(Strings.getFormattedString('openils.global_util.clear_cache.error', [E]));
276 function toOpenWindowByType(inType, uri) {
277 var winopts = "chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar";
278 window.open(uri, "_blank", winopts);
281 function url_prefix(url) {
282 if (url.match(/^\//)) url = urls.remote + url;
283 if (! url.match(/^(http|chrome):\/\//) && ! url.match(/^data:/) ) url = 'http://' + url;
284 dump('url_prefix = ' + url + '\n');