1 dump('entering main/main.js\n');
7 function grant_perms(url) {
8 var perms = "UniversalXPConnect UniversalPreferencesWrite UniversalBrowserWrite UniversalPreferencesRead UniversalBrowserRead UniversalFileRead";
9 dump('Granting ' + perms + ' to ' + url + '\n');
10 var pref = Components.classes["@mozilla.org/preferences-service;1"]
11 .getService(Components.interfaces.nsIPrefBranch);
13 pref.setCharPref("capability.principal.codebase.p0.granted", perms);
14 pref.setCharPref("capability.principal.codebase.p0.id", url);
15 pref.setCharPref("capability.principal.codebase.p1.granted", perms);
16 pref.setCharPref("capability.principal.codebase.p1.id", url.replace('http:','https:'));
17 pref.setBoolPref("dom.disable_open_during_load",false);
18 pref.setBoolPref("browser.popups.showPopupBlocker",false);
23 function clear_the_cache() {
25 var cacheClass = Components.classes["@mozilla.org/network/cache-service;1"];
26 var cacheService = cacheClass.getService(Components.interfaces.nsICacheService);
27 cacheService.evictEntries(Components.interfaces.nsICache.STORE_ON_DISK);
28 cacheService.evictEntries(Components.interfaces.nsICache.STORE_IN_MEMORY);
30 dump(E+'\n');alert(E);
34 function main_init() {
35 dump('entering main_init()\n');
39 // Now we can safely load the strings without the cache getting wiped
40 offlineStrings = document.getElementById('offlineStrings');
41 authStrings = document.getElementById('authStrings');
43 if (typeof JSAN == 'undefined') {
45 offlineStrings.getString('common.jsan.missing')
48 /////////////////////////////////////////////////////////////////////////////
50 JSAN.errorLevel = "die"; // none, warn, or die
51 JSAN.addRepository('..');
53 //JSAN.use('test.test'); test.test.hello_world();
58 JSAN.use('util.error');
59 G.error = new util.error();
60 G.error.sdump('D_ERROR', offlineStrings.getString('main.testing'));
62 JSAN.use('util.window');
63 G.window = new util.window();
65 JSAN.use('auth.controller');
66 G.auth = new auth.controller( { 'window' : mw } );
68 JSAN.use('OpenILS.data');
69 G.data = new OpenILS.data();
70 G.data.on_error = G.auth.logoff;
72 JSAN.use('util.file');
73 G.file = new util.file();
75 G.file.get('ws_info');
76 G.ws_info = G.file.get_object(); G.file.close();
80 G.data.ws_info = G.ws_info; G.data.stash('ws_info');
82 G.auth.on_login = function() {
84 var url = G.auth.controller.view.server_prompt.value || urls.remote;
86 G.data.server_unadorned = url; G.data.stash('server_unadorned'); G.data.stash_retrieve();
88 if (! url.match( '^http://' ) ) { url = 'http://' + url; }
90 G.data.server = url; G.data.stash('server');
91 G.data.session = { 'key' : G.auth.session.key, 'auth' : G.auth.session.authtime }; G.data.stash('session');
92 G.data.stash_retrieve();
102 if (G.data.ws_info && G.data.ws_info[G.auth.controller.view.server_prompt.value]) {
103 JSAN.use('util.widgets');
104 var deck = document.getElementById('progress_space');
105 util.widgets.remove_children( deck );
106 var iframe = document.createElement('iframe'); deck.appendChild(iframe);
107 iframe.setAttribute( 'src', url + '/xul/server/main/data.xul' );
108 iframe.contentWindow.xulG = xulG;
111 var deck = G.auth.controller.view.ws_deck;
112 JSAN.use('util.widgets'); util.widgets.remove_children('ws_deck');
113 var iframe = document.createElement('iframe'); deck.appendChild(iframe);
114 iframe.setAttribute( 'src', url + '/xul/server/main/ws_info.xul' );
115 iframe.contentWindow.xulG = xulG;
116 deck.selectedIndex = deck.childNodes.length - 1;
120 G.auth.on_standalone = function() {
122 G.window.open(urls.XUL_STANDALONE,'Offline','chrome,resizable');
128 G.auth.on_standalone_export = function() {
130 JSAN.use('util.file'); var file = new util.file('pending_xacts');
131 if (file._file.exists()) {
132 var file2 = new util.file('');
133 var f = file2.pick_file( { 'mode' : 'save', 'title' : offlineStrings.getString('main.transaction_export.title') } );
136 var r = G.error.yns_alert(
137 offlineStrings.getFormattedString('main.transaction_export.prompt', [f.leafName]),
138 offlineStrings.getString('main.transaction_export.prompt.title'),
139 offlineStrings.getString('common.yes'),
140 offlineStrings.getString('common.no'),
142 offlineStrings.getString('common.confirm')
144 if (r != 0) { file.close(); return; }
146 var e_file = new util.file(''); e_file._file = f;
147 e_file.write_content( 'truncate', file.get_content() );
149 var r = G.error.yns_alert(
150 offlineStrings.getFormattedString('main.transaction_export.success.prompt', [f.leafName]),
151 offlineStrings.getString('main.transaction_export.success.title'),
152 offlineStrings.getString('common.yes'),
153 offlineStrings.getString('common.no'),
155 offlineStrings.getString('common.confirm')
159 var filename = 'pending_xacts_exported_' + new Date().getTime();
160 var t_file = new util.file(filename);
161 while (t_file._file.exists()) {
162 filename = 'pending_xacts_' + new Date().getTime() + '.exported';
163 t_file = new util.file(filename);
165 throw(offlineStrings.getString('main.transaction_export.filename.error'));
168 file._file.moveTo(null,filename);
170 alert(offlineStrings.getString('main.transaction_export.duplicate.warning'));
173 alert(offlineStrings.getString('main.transaction_export.no_filename.error'));
176 alert(offlineStrings.getString('main.transaction_export.no_transactions.error'));
184 G.auth.on_standalone_import = function() {
186 JSAN.use('util.file'); var file = new util.file('pending_xacts');
187 if (file._file.exists()) {
188 alert(offlineStrings.getString('main.transaction_import.outstanding.error'));
190 var file2 = new util.file('');
191 var f = file2.pick_file( { 'mode' : 'open', 'title' : offlineStrings.getString('main.transaction_import.title')} );
192 if (f && f.exists()) {
193 var i_file = new util.file(''); i_file._file = f;
194 file.write_content( 'truncate', i_file.get_content() );
196 var r = G.error.yns_alert(
197 offlineStrings.getFormattedString('main.transaction_import.delete.prompt', [f.leafName]),
198 offlineStrings.getString('main.transaction_import.success'),
199 offlineStrings.getString('common.yes'),
200 offlineStrings.getString('common.no'),
202 offlineStrings.getString('common.confirm')
215 G.auth.on_debug = function(action) {
218 G.window.open(urls.XUL_DEBUG_CONSOLE,'testconsole','chrome,resizable');
222 alert(offlineStrings.getString('main.on_debug.clear_cache'));
225 alert(offlineStrings.getString('main.on_debug.debug'));
231 // XML_HTTP_SERVER will get reset to G.auth.controller.view.server_prompt.value
233 /////////////////////////////////////////////////////////////////////////////
235 var version = '/xul/server/'.split(/\//)[2];
236 if (version == 'server') {
237 version = 'versionless debug build';
238 document.getElementById('debug_gb').hidden = false;
240 window.title = authStrings.getFormattedString('staff.auth.titlebar.label', version);
241 var x = document.getElementById('about_btn');
246 G.window.open('about.html','about','chrome,resizable,width=800,height=600');
247 } catch(E) { alert(E); }
252 var y = document.getElementById('new_window_btn');
256 if (G.data.session) {
258 G.window.open('chrome://open_ils_staff_client/content/main/menu_frame.xul?server=' +
259 G.data.server,'main','chrome,resizable' );
261 } catch(E) { alert(E); }
263 alert ( offlineStrings.getString('main.new_window_btn.login_first_warning') );
269 JSAN.use('util.mozilla');
270 var z = document.getElementById('locale_menupopup');
272 while (z.lastChild) z.removeChild(z.lastChild);
273 var locales = util.mozilla.chromeRegistry().getLocalesForPackage( String( location.href ).split(/\//)[2] );
274 var current_locale = util.mozilla.prefs().getCharPref('general.useragent.locale');
275 while (locales.hasMore()) {
276 var locale = locales.getNext();
277 var parts = locale.split(/-/);
280 label = locale + ' : ' + util.mozilla.languages().GetStringFromName(parts[0]);
281 if (parts.length > 1) {
283 label += ' (' + util.mozilla.regions().GetStringFromName(parts[1].toLowerCase()) + ')';
285 label += ' (' + parts[1] + ')';
291 var mi = document.createElement('menuitem');
292 mi.setAttribute('label',label);
293 mi.setAttribute('value',locale);
294 if (locale == current_locale) {
295 if (z.parentNode.tagName == 'menulist') {
296 mi.setAttribute('selected','true');
297 z.parentNode.setAttribute('label',label);
298 z.parentNode.setAttribute('value',locale);
304 var xx = document.getElementById('apply_locale_btn');
308 util.mozilla.change_locale(z.parentNode.value);
313 var pref = Components.classes["@mozilla.org/preferences-service;1"]
314 .getService(Components.interfaces.nsIPrefBranch);
316 if ( found_ws_info_in_Achrome() && pref.getBoolPref("open-ils.write_in_user_chrome_directory") ) {
317 //var hbox = x.parentNode; var b = document.createElement('button');
318 //b.setAttribute('label','Migrate legacy settings'); hbox.appendChild(b);
319 //b.addEventListener(
323 // handle_migration();
324 // } catch(E) { alert(E); }
328 if (window.confirm(offlineStrings.getString('main.settings.migrate'))) {
329 setTimeout( function() { handle_migration(); }, 0 );
334 var error = offlineStrings.getFormattedString('common.exception', [E, '']);
335 try { G.error.sdump('D_ERROR',error); } catch(E) { dump(error); }
338 dump('exiting main_init()\n');
341 function found_ws_info_in_Achrome() {
342 JSAN.use('util.file');
343 var f = new util.file();
344 var f_in_chrome = f.get('ws_info','chrome');
345 var path = f_in_chrome.exists() ? f_in_chrome.path : false;
350 function found_ws_info_in_Uchrome() {
351 JSAN.use('util.file');
352 var f = new util.file();
353 var f_in_uchrome = f.get('ws_info','uchrome');
354 var path = f_in_uchrome.exists() ? f_in_uchrome.path : false;
359 function handle_migration() {
360 if ( found_ws_info_in_Uchrome() ) {
361 alert(offlineStrings.getFormattedString('main.settings.migrate.failed', [found_ws_info_in_Uchrome(), found_ws_info_in_Achrome()])
364 var dirService = Components.classes["@mozilla.org/file/directory_service;1"].getService( Components.interfaces.nsIProperties );
365 var f_new = dirService.get( "UChrm", Components.interfaces.nsIFile );
366 var f_old = dirService.get( "AChrom", Components.interfaces.nsIFile );
367 f_old.append(myPackageDir); f_old.append("content"); f_old.append("conf");
368 if (window.confirm(offlineStrings.getFormattedString("main.settings.migrate.confirm", [f_old.path, f_new.path]))) {
369 var files = f_old.directoryEntries;
370 while (files.hasMoreElements()) {
371 var file = files.getNext();
372 var file2 = file.QueryInterface( Components.interfaces.nsILocalFile );
374 file2.moveTo( f_new, '' );
376 alert(offlineStrings.getFormattedString('main.settings.migrate.error', [file2.path, f_new.path]) + '\n');
379 location.href = location.href; // huh?
384 dump('exiting main/main.js\n');