1 dump('entering main/main.js\n');
8 function grant_perms(url) {
9 var perms = "UniversalXPConnect UniversalPreferencesWrite UniversalBrowserWrite UniversalPreferencesRead UniversalBrowserRead UniversalFileRead";
10 dump('Granting ' + perms + ' to ' + url + '\n');
12 G.pref.setCharPref("capability.principal.codebase.p0.granted", perms);
13 G.pref.setCharPref("capability.principal.codebase.p0.id", url);
14 G.pref.setCharPref("capability.principal.codebase.p1.granted", perms);
15 G.pref.setCharPref("capability.principal.codebase.p1.id", url.replace('http:','https:'));
16 G.pref.setBoolPref("dom.disable_open_during_load",false);
17 G.pref.setBoolPref("browser.popups.showPopupBlocker",false);
22 function clear_the_cache() {
24 var cacheClass = Components.classes["@mozilla.org/network/cache-service;1"];
25 var cacheService = cacheClass.getService(Components.interfaces.nsICacheService);
26 cacheService.evictEntries(Components.interfaces.nsICache.STORE_ON_DISK);
27 cacheService.evictEntries(Components.interfaces.nsICache.STORE_IN_MEMORY);
29 dump(E+'\n');alert(E);
33 function toOpenWindowByType(inType, uri) { /* for Venkman */
35 var winopts = "chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar";
36 window.open(uri, "_blank", winopts);
42 function start_debugger() {
45 try { start_venkman(); } catch(E) { alert(E); }
50 function start_inspector() {
53 try { inspectDOMDocument(); } catch(E) { alert(E); }
58 function start_chrome_list() {
61 try { startChromeList(); } catch(E) { alert(E); }
66 function start_js_shell() {
69 try { window.open('chrome://open_ils_staff_client/content/util/shell.html','shell','chrome,resizable,scrollbars'); } catch(E) { alert(E); }
74 function main_init() {
75 dump('entering main_init()\n');
79 // Now we can safely load the strings without the cache getting wiped
80 offlineStrings = document.getElementById('offlineStrings');
81 authStrings = document.getElementById('authStrings');
83 if (typeof JSAN == 'undefined') {
85 offlineStrings.getString('common.jsan.missing')
88 /////////////////////////////////////////////////////////////////////////////
90 JSAN.errorLevel = "die"; // none, warn, or die
91 JSAN.addRepository('..');
93 //JSAN.use('test.test'); test.test.hello_world();
98 G.pref = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
100 JSAN.use('util.error');
101 G.error = new util.error();
102 G.error.sdump('D_ERROR', offlineStrings.getString('main.testing'));
104 JSAN.use('util.window');
105 G.window = new util.window();
107 JSAN.use('auth.controller');
108 G.auth = new auth.controller( { 'window' : mw } );
110 JSAN.use('OpenILS.data');
111 G.data = new OpenILS.data();
112 G.data.on_error = G.auth.logoff;
114 JSAN.use('util.file');
115 G.file = new util.file();
117 G.file.get('ws_info');
118 G.ws_info = G.file.get_object(); G.file.close();
122 G.data.ws_info = G.ws_info; G.data.stash('ws_info');
124 G.auth.on_login = function() {
126 var url = G.auth.controller.view.server_prompt.value || urls.remote;
128 G.data.server_unadorned = url; G.data.stash('server_unadorned'); G.data.stash_retrieve();
130 if (! url.match( '^http://' ) ) { url = 'http://' + url; }
132 G.data.server = url; G.data.stash('server');
133 G.data.session = { 'key' : G.auth.session.key, 'auth' : G.auth.session.authtime }; G.data.stash('session');
134 G.data.stash_retrieve();
136 var ios = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
137 var cookieUri = ios.newURI("http://" + G.data.server_unadorned, null, null);
138 var cookieUriSSL = ios.newURI("https://" + G.data.server_unadorned, null, null);
139 var cookieSvc = Components.classes["@mozilla.org/cookieService;1"].getService(Components.interfaces.nsICookieService);
141 cookieSvc.setCookieString(cookieUri, null, "ses="+G.data.session.key, null);
142 cookieSvc.setCookieString(cookieUriSSL, null, "ses="+G.data.session.key, null);
143 cookieSvc.setCookieString(cookieUri, null, "xul=1", null);
144 cookieSvc.setCookieString(cookieUriSSL, null, "xul=1", null);
147 alert(offlineStrings.getFormattedString(main.session_cookie.error, [E]));
160 if (G.data.ws_info && G.data.ws_info[G.auth.controller.view.server_prompt.value]) {
161 JSAN.use('util.widgets');
162 var deck = document.getElementById('progress_space');
163 util.widgets.remove_children( deck );
164 var iframe = document.createElement('iframe'); deck.appendChild(iframe);
165 iframe.setAttribute( 'src', url + '/xul/server/main/data.xul' );
166 iframe.contentWindow.xulG = xulG;
167 G.data_xul = iframe.contentWindow;
170 var deck = G.auth.controller.view.ws_deck;
171 JSAN.use('util.widgets'); util.widgets.remove_children('ws_deck');
172 var iframe = document.createElement('iframe'); deck.appendChild(iframe);
173 iframe.setAttribute( 'src', url + '/xul/server/main/ws_info.xul' );
174 iframe.contentWindow.xulG = xulG;
175 deck.selectedIndex = deck.childNodes.length - 1;
179 G.auth.on_standalone = function() {
181 G.window.open(urls.XUL_STANDALONE,'Offline','chrome,resizable');
187 G.auth.on_standalone_export = function() {
189 JSAN.use('util.file'); var file = new util.file('pending_xacts');
190 if (file._file.exists()) {
191 var file2 = new util.file('');
192 var f = file2.pick_file( { 'mode' : 'save', 'title' : offlineStrings.getString('main.transaction_export.title') } );
195 var r = G.error.yns_alert(
196 offlineStrings.getFormattedString('main.transaction_export.prompt', [f.leafName]),
197 offlineStrings.getString('main.transaction_export.prompt.title'),
198 offlineStrings.getString('common.yes'),
199 offlineStrings.getString('common.no'),
201 offlineStrings.getString('common.confirm')
203 if (r != 0) { file.close(); return; }
205 var e_file = new util.file(''); e_file._file = f;
206 e_file.write_content( 'truncate', file.get_content() );
208 var r = G.error.yns_alert(
209 offlineStrings.getFormattedString('main.transaction_export.success.prompt', [f.leafName]),
210 offlineStrings.getString('main.transaction_export.success.title'),
211 offlineStrings.getString('common.yes'),
212 offlineStrings.getString('common.no'),
214 offlineStrings.getString('common.confirm')
218 var filename = 'pending_xacts_exported_' + new Date().getTime();
219 var t_file = new util.file(filename);
220 while (t_file._file.exists()) {
221 filename = 'pending_xacts_' + new Date().getTime() + '.exported';
222 t_file = new util.file(filename);
224 throw(offlineStrings.getString('main.transaction_export.filename.error'));
227 file._file.moveTo(null,filename);
229 alert(offlineStrings.getString('main.transaction_export.duplicate.warning'));
232 alert(offlineStrings.getString('main.transaction_export.no_filename.error'));
235 alert(offlineStrings.getString('main.transaction_export.no_transactions.error'));
243 G.auth.on_standalone_import = function() {
245 JSAN.use('util.file'); var file = new util.file('pending_xacts');
246 if (file._file.exists()) {
247 alert(offlineStrings.getString('main.transaction_import.outstanding.error'));
249 var file2 = new util.file('');
250 var f = file2.pick_file( { 'mode' : 'open', 'title' : offlineStrings.getString('main.transaction_import.title')} );
251 if (f && f.exists()) {
252 var i_file = new util.file(''); i_file._file = f;
253 file.write_content( 'truncate', i_file.get_content() );
255 var r = G.error.yns_alert(
256 offlineStrings.getFormattedString('main.transaction_import.delete.prompt', [f.leafName]),
257 offlineStrings.getString('main.transaction_import.success'),
258 offlineStrings.getString('common.yes'),
259 offlineStrings.getString('common.no'),
261 offlineStrings.getString('common.confirm')
274 G.auth.on_debug = function(action) {
277 G.window.open(urls.XUL_DEBUG_CONSOLE,'testconsole','chrome,resizable');
281 alert(offlineStrings.getString('main.on_debug.clear_cache'));
284 alert(offlineStrings.getString('main.on_debug.debug'));
290 // XML_HTTP_SERVER will get reset to G.auth.controller.view.server_prompt.value
292 /////////////////////////////////////////////////////////////////////////////
294 var version = '/xul/server/'.split(/\//)[2];
295 if (version == 'server') {
296 version = 'versionless debug build';
297 document.getElementById('debug_gb').hidden = false;
300 if (G.pref && G.pref.getBoolPref('open-ils.debug_options')) {
301 document.getElementById('debug_gb').hidden = false;
304 window.title = authStrings.getFormattedString('staff.auth.titlebar.label', version);
305 var x = document.getElementById('about_btn');
310 G.window.open('about.html','about','chrome,resizable,width=800,height=600');
311 } catch(E) { alert(E); }
316 var y = document.getElementById('new_window_btn');
320 if (G.data.session) {
322 //G.data_xul.g.open_menu();
323 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
324 var mframe = xulG.window.open(( String(urls.XUL_MENU_FRAME).match(/^chrome:/) ? '' : G.data.server ) + urls.XUL_MENU_FRAME
325 + '?server='+window.escape(G.data.server),
326 'main'+xulG.window.window_name_increment(),'chrome,resizable'
329 } catch(E) { alert(E); }
331 alert ( offlineStrings.getString('main.new_window_btn.login_first_warning') );
337 JSAN.use('util.mozilla');
338 var z = document.getElementById('locale_menupopup');
340 while (z.lastChild) z.removeChild(z.lastChild);
341 var locales = util.mozilla.chromeRegistry().getLocalesForPackage( String( location.href ).split(/\//)[2] );
342 var current_locale = util.mozilla.prefs().getCharPref('general.useragent.locale');
343 while (locales.hasMore()) {
344 var locale = locales.getNext();
345 var parts = locale.split(/-/);
348 label = locale + ' : ' + util.mozilla.languages().GetStringFromName(parts[0]);
349 if (parts.length > 1) {
351 label += ' (' + util.mozilla.regions().GetStringFromName(parts[1].toLowerCase()) + ')';
353 label += ' (' + parts[1] + ')';
359 var mi = document.createElement('menuitem');
360 mi.setAttribute('label',label);
361 mi.setAttribute('value',locale);
362 if (locale == current_locale) {
363 if (z.parentNode.tagName == 'menulist') {
364 mi.setAttribute('selected','true');
365 z.parentNode.setAttribute('label',label);
366 z.parentNode.setAttribute('value',locale);
372 var xx = document.getElementById('apply_locale_btn');
376 util.mozilla.change_locale(z.parentNode.value);
381 if ( found_ws_info_in_Achrome() && G.pref && G.pref.getBoolPref("open-ils.write_in_user_chrome_directory") ) {
382 //var hbox = x.parentNode; var b = document.createElement('button');
383 //b.setAttribute('label','Migrate legacy settings'); hbox.appendChild(b);
384 //b.addEventListener(
388 // handle_migration();
389 // } catch(E) { alert(E); }
393 if (window.confirm(offlineStrings.getString('main.settings.migrate'))) {
394 setTimeout( function() { handle_migration(); }, 0 );
399 var error = offlineStrings.getFormattedString('common.exception', [E, '']);
400 try { G.error.sdump('D_ERROR',error); } catch(E) { dump(error); }
403 dump('exiting main_init()\n');
406 function found_ws_info_in_Achrome() {
407 JSAN.use('util.file');
408 var f = new util.file();
409 var f_in_chrome = f.get('ws_info','chrome');
410 var path = f_in_chrome.exists() ? f_in_chrome.path : false;
415 function found_ws_info_in_Uchrome() {
416 JSAN.use('util.file');
417 var f = new util.file();
418 var f_in_uchrome = f.get('ws_info','uchrome');
419 var path = f_in_uchrome.exists() ? f_in_uchrome.path : false;
424 function handle_migration() {
425 if ( found_ws_info_in_Uchrome() ) {
426 alert(offlineStrings.getFormattedString('main.settings.migrate.failed', [found_ws_info_in_Uchrome(), found_ws_info_in_Achrome()])
429 var dirService = Components.classes["@mozilla.org/file/directory_service;1"].getService( Components.interfaces.nsIProperties );
430 var f_new = dirService.get( "UChrm", Components.interfaces.nsIFile );
431 var f_old = dirService.get( "AChrom", Components.interfaces.nsIFile );
432 f_old.append(myPackageDir); f_old.append("content"); f_old.append("conf");
433 if (window.confirm(offlineStrings.getFormattedString("main.settings.migrate.confirm", [f_old.path, f_new.path]))) {
434 var files = f_old.directoryEntries;
435 while (files.hasMoreElements()) {
436 var file = files.getNext();
437 var file2 = file.QueryInterface( Components.interfaces.nsILocalFile );
439 file2.moveTo( f_new, '' );
441 alert(offlineStrings.getFormattedString('main.settings.migrate.error', [file2.path, f_new.path]) + '\n');
444 location.href = location.href; // huh?
449 dump('exiting main/main.js\n');