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.setBoolPref("dom.disable_open_during_load",false);
16 pref.setBoolPref("browser.popups.showPopupBlocker",false);
21 function clear_the_cache() {
23 var cacheClass = Components.classes["@mozilla.org/network/cache-service;1"];
24 var cacheService = cacheClass.getService(Components.interfaces.nsICacheService);
25 cacheService.evictEntries(Components.interfaces.nsICache.STORE_ON_DISK);
26 cacheService.evictEntries(Components.interfaces.nsICache.STORE_IN_MEMORY);
28 dump(E+'\n');alert(E);
32 function main_init() {
33 dump('entering main_init()\n');
37 // Now we can safely load the strings without the cache getting wiped
38 offlineStrings = document.getElementById('offlineStrings');
39 authStrings = document.getElementById('authStrings');
41 if (typeof JSAN == 'undefined') {
43 offlineStrings.getString('common.jsan.missing')
46 /////////////////////////////////////////////////////////////////////////////
48 JSAN.errorLevel = "die"; // none, warn, or die
49 JSAN.addRepository('..');
51 //JSAN.use('test.test'); test.test.hello_world();
56 JSAN.use('util.error');
57 G.error = new util.error();
58 G.error.sdump('D_ERROR', offlineStrings.getString('main.testing'));
60 JSAN.use('util.window');
61 G.window = new util.window();
63 JSAN.use('auth.controller');
64 G.auth = new auth.controller( { 'window' : mw } );
66 JSAN.use('OpenILS.data');
67 G.data = new OpenILS.data();
68 G.data.on_error = G.auth.logoff;
70 JSAN.use('util.file');
71 G.file = new util.file();
73 G.file.get('ws_info');
74 G.ws_info = G.file.get_object(); G.file.close();
78 G.data.ws_info = G.ws_info; G.data.stash('ws_info');
80 G.auth.on_login = function() {
82 var url = G.auth.controller.view.server_prompt.value || urls.remote;
84 G.data.server_unadorned = url; G.data.stash('server_unadorned'); G.data.stash_retrieve();
86 if (! url.match( '^http://' ) ) { url = 'http://' + url; }
88 G.data.server = url; G.data.stash('server');
89 G.data.session = { 'key' : G.auth.session.key, 'auth' : G.auth.session.authtime }; G.data.stash('session');
90 G.data.stash_retrieve();
100 if (G.data.ws_info && G.data.ws_info[G.auth.controller.view.server_prompt.value]) {
101 JSAN.use('util.widgets');
102 var deck = document.getElementById('progress_space');
103 util.widgets.remove_children( deck );
104 var iframe = document.createElement('iframe'); deck.appendChild(iframe);
105 iframe.setAttribute( 'src', url + '/xul/server/main/data.xul' );
106 iframe.contentWindow.xulG = xulG;
109 var deck = G.auth.controller.view.ws_deck;
110 JSAN.use('util.widgets'); util.widgets.remove_children('ws_deck');
111 var iframe = document.createElement('iframe'); deck.appendChild(iframe);
112 iframe.setAttribute( 'src', url + '/xul/server/main/ws_info.xul' );
113 iframe.contentWindow.xulG = xulG;
114 deck.selectedIndex = deck.childNodes.length - 1;
118 G.auth.on_standalone = function() {
120 G.window.open(urls.XUL_STANDALONE,'Offline','chrome,resizable');
126 G.auth.on_standalone_export = function() {
128 JSAN.use('util.file'); var file = new util.file('pending_xacts');
129 if (file._file.exists()) {
130 var file2 = new util.file('');
131 var f = file2.pick_file( { 'mode' : 'save', 'title' : offlineStrings.getString('main.transaction_export.title') } );
134 var r = G.error.yns_alert(
135 offlineStrings.getFormattedString('main.transaction_export.prompt', [f.leafName]),
136 offlineStrings.getString('main.transaction_export.prompt.title'),
137 offlineStrings.getString('common.yes'),
138 offlineStrings.getString('common.no'),
140 offlineStrings.getString('common.confirm')
142 if (r != 0) { file.close(); return; }
144 var e_file = new util.file(''); e_file._file = f;
145 e_file.write_content( 'truncate', file.get_content() );
147 var r = G.error.yns_alert(
148 offlineStrings.getFormattedString('main.transaction_export.success.prompt', [f.leafName]),
149 offlineStrings.getString('main.transaction_export.success.title'),
150 offlineStrings.getString('common.yes'),
151 offlineStrings.getString('common.no'),
153 offlineStrings.getString('common.confirm')
157 var filename = 'pending_xacts_exported_' + new Date().getTime();
158 var t_file = new util.file(filename);
159 while (t_file._file.exists()) {
160 filename = 'pending_xacts_' + new Date().getTime() + '.exported';
161 t_file = new util.file(filename);
163 throw(offlineStrings.getString('main.transaction_export.filename.error'));
166 file._file.moveTo(null,filename);
168 alert(offlineStrings.getString('main.transaction_export.duplicate.warning'));
171 alert(offlineStrings.getString('main.transaction_export.no_filename.error'));
174 alert(offlineStrings.getString('main.transaction_export.no_transactions.error'));
182 G.auth.on_standalone_import = function() {
184 JSAN.use('util.file'); var file = new util.file('pending_xacts');
185 if (file._file.exists()) {
186 alert(offlineStrings.getString('main.transaction_import.outstanding.error'));
188 var file2 = new util.file('');
189 var f = file2.pick_file( { 'mode' : 'open', 'title' : offlineStrings.getString('main.transaction_import.title')} );
190 if (f && f.exists()) {
191 var i_file = new util.file(''); i_file._file = f;
192 file.write_content( 'truncate', i_file.get_content() );
194 var r = G.error.yns_alert(
195 offlineStrings.getFormattedString('main.transaction_import.delete.prompt', [f.leafName]),
196 offlineStrings.getString('main.transaction_import.success'),
197 offlineStrings.getString('common.yes'),
198 offlineStrings.getString('common.no'),
200 offlineStrings.getString('common.confirm')
213 G.auth.on_debug = function(action) {
216 G.window.open(urls.XUL_DEBUG_CONSOLE,'testconsole','chrome,resizable');
220 alert(offlineStrings.getString('main.on_debug.clear_cache'));
223 alert(offlineStrings.getString('main.on_debug.debug'));
229 // XML_HTTP_SERVER will get reset to G.auth.controller.view.server_prompt.value
231 /////////////////////////////////////////////////////////////////////////////
233 var version = '/xul/server/'.split(/\//)[2];
234 if (version == 'server') {
235 version = 'versionless debug build';
236 document.getElementById('debug_gb').hidden = false;
238 window.title = authStrings.getFormattedString('staff.auth.titlebar.label', version);
239 var x = document.getElementById('about_btn');
244 G.window.open('about.html','about','chrome,resizable,width=800,height=600');
245 } catch(E) { alert(E); }
250 var y = document.getElementById('new_window_btn');
254 if (G.data.session) {
256 G.window.open('chrome://open_ils_staff_client/content/main/menu_frame.xul?server=' +
257 G.data.server,'main','chrome,resizable' );
259 } catch(E) { alert(E); }
261 alert ( offlineStrings.getString('main.new_window_btn.login_first_warning') );
267 JSAN.use('util.mozilla');
268 var z = document.getElementById('locale_menupopup');
270 while (z.lastChild) z.removeChild(z.lastChild);
271 var locales = util.mozilla.chromeRegistry().getLocalesForPackage( String( location.href ).split(/\//)[2] );
272 var current_locale = util.mozilla.prefs().getCharPref('general.useragent.locale');
273 while (locales.hasMore()) {
274 var locale = locales.getNext();
275 var parts = locale.split(/-/);
278 label = locale + ' : ' + util.mozilla.languages().GetStringFromName(parts[0]);
279 if (parts.length > 1) {
281 label += ' (' + util.mozilla.regions().GetStringFromName(parts[1].toLowerCase()) + ')';
283 label += ' (' + parts[1] + ')';
289 var mi = document.createElement('menuitem');
290 mi.setAttribute('label',label);
291 mi.setAttribute('value',locale);
292 if (locale == current_locale) {
293 if (z.parentNode.tagName == 'menulist') {
294 mi.setAttribute('selected','true');
295 z.parentNode.setAttribute('label',label);
296 z.parentNode.setAttribute('value',locale);
302 var xx = document.getElementById('apply_locale_btn');
306 util.mozilla.change_locale(z.parentNode.value);
311 var pref = Components.classes["@mozilla.org/preferences-service;1"]
312 .getService(Components.interfaces.nsIPrefBranch);
314 if ( found_ws_info_in_Achrome() && pref.getBoolPref("open-ils.write_in_user_chrome_directory") ) {
315 //var hbox = x.parentNode; var b = document.createElement('button');
316 //b.setAttribute('label','Migrate legacy settings'); hbox.appendChild(b);
317 //b.addEventListener(
321 // handle_migration();
322 // } catch(E) { alert(E); }
326 if (window.confirm(offlineStrings.getString('main.settings.migrate'))) {
327 setTimeout( function() { handle_migration(); }, 0 );
332 var error = offlineStrings.getFormattedString('common.exception', [E, '']);
333 try { G.error.sdump('D_ERROR',error); } catch(E) { dump(error); }
336 dump('exiting main_init()\n');
339 function found_ws_info_in_Achrome() {
340 JSAN.use('util.file');
341 var f = new util.file();
342 var f_in_chrome = f.get('ws_info','chrome');
343 var path = f_in_chrome.exists() ? f_in_chrome.path : false;
348 function found_ws_info_in_Uchrome() {
349 JSAN.use('util.file');
350 var f = new util.file();
351 var f_in_uchrome = f.get('ws_info','uchrome');
352 var path = f_in_uchrome.exists() ? f_in_uchrome.path : false;
357 function handle_migration() {
358 if ( found_ws_info_in_Uchrome() ) {
359 alert(offlineStrings.getFormattedString('main.settings.migrate.failed', [found_ws_info_in_Uchrome(), found_ws_info_in_Achrome()])
362 var dirService = Components.classes["@mozilla.org/file/directory_service;1"].getService( Components.interfaces.nsIProperties );
363 var f_new = dirService.get( "UChrm", Components.interfaces.nsIFile );
364 var f_old = dirService.get( "AChrom", Components.interfaces.nsIFile );
365 f_old.append(myPackageDir); f_old.append("content"); f_old.append("conf");
366 if (window.confirm(offlineStrings.getFormattedString("main.settings.migrate.confirm", [f_old.path, f_new.path]))) {
367 var files = f_old.directoryEntries;
368 while (files.hasMoreElements()) {
369 var file = files.getNext();
370 var file2 = file.QueryInterface( Components.interfaces.nsILocalFile );
372 file2.moveTo( f_new, '' );
374 alert(offlineStrings.getFormattedString('main.settings.migrate.error', [file2.path, f_new.path]) + '\n');
377 location.href = location.href; // huh?
382 dump('exiting main/main.js\n');