1 dump('entering main/main.js\n');
4 function grant_perms(url) {
5 var perms = "UniversalXPConnect UniversalPreferencesWrite UniversalBrowserWrite UniversalPreferencesRead UniversalBrowserRead UniversalFileRead";
6 dump('Granting ' + perms + ' to ' + url + '\n');
7 var pref = Components.classes["@mozilla.org/preferences-service;1"]
8 .getService(Components.interfaces.nsIPrefBranch);
10 pref.setCharPref("capability.principal.codebase.p0.granted", perms);
11 pref.setCharPref("capability.principal.codebase.p0.id", url);
12 pref.setBoolPref("dom.disable_open_during_load",false);
13 pref.setBoolPref("browser.popups.showPopupBlocker",false);
18 function clear_the_cache() {
20 var cacheClass = Components.classes["@mozilla.org/network/cache-service;1"];
21 var cacheService = cacheClass.getService(Components.interfaces.nsICacheService);
22 cacheService.evictEntries(Components.interfaces.nsICache.STORE_ON_DISK);
23 cacheService.evictEntries(Components.interfaces.nsICache.STORE_IN_MEMORY);
25 dump(E+'\n');alert(E);
29 function main_init() {
30 dump('entering main_init()\n');
34 if (typeof JSAN == 'undefined') {
36 "The JSAN library object is missing."
39 /////////////////////////////////////////////////////////////////////////////
41 JSAN.errorLevel = "die"; // none, warn, or die
42 JSAN.addRepository('..');
44 //JSAN.use('test.test'); test.test.hello_world();
49 JSAN.use('util.error');
50 G.error = new util.error();
51 G.error.sdump('D_ERROR','Testing');
53 JSAN.use('util.window');
54 G.window = new util.window();
56 JSAN.use('auth.controller');
57 G.auth = new auth.controller( { 'window' : mw } );
59 JSAN.use('OpenILS.data');
60 G.data = new OpenILS.data()
61 G.data.on_error = G.auth.logoff;
63 JSAN.use('util.file');
64 G.file = new util.file();
66 G.file.get('ws_info');
67 G.ws_info = G.file.get_object(); G.file.close();
71 G.data.ws_info = G.ws_info; G.data.stash('ws_info');
73 G.auth.on_login = function() {
75 var url = G.auth.controller.view.server_prompt.value || urls.remote;
77 G.data.server_unadorned = url; G.data.stash('server_unadorned'); G.data.stash_retrieve();
79 if (! url.match( '^http://' ) ) url = 'http://' + url;
81 G.data.server = url; G.data.stash('server');
82 G.data.session = { 'key' : G.auth.session.key, 'auth' : G.auth.session.authtime }; G.data.stash('session');
83 G.data.stash_retrieve();
93 if (G.data.ws_info && G.data.ws_info[G.auth.controller.view.server_prompt.value]) {
94 JSAN.use('util.widgets');
95 var deck = document.getElementById('progress_space');
96 util.widgets.remove_children( deck );
97 var iframe = document.createElement('iframe'); deck.appendChild(iframe);
98 iframe.setAttribute( 'src', url + '/xul/server/main/data.xul' );
99 iframe.contentWindow.xulG = xulG;
102 var deck = G.auth.controller.view.ws_deck;
103 JSAN.use('util.widgets'); util.widgets.remove_children('ws_deck');
104 var iframe = document.createElement('iframe'); deck.appendChild(iframe);
105 iframe.setAttribute( 'src', url + '/xul/server/main/ws_info.xul' );
106 iframe.contentWindow.xulG = xulG;
107 deck.selectedIndex = deck.childNodes.length - 1;
111 G.auth.on_standalone = function() {
113 G.window.open(urls.XUL_STANDALONE,'Offline','chrome,resizable');
119 G.auth.on_standalone_export = function() {
121 JSAN.use('util.file'); var file = new util.file('pending_xacts');
122 if (file._file.exists()) {
123 var file2 = new util.file('');
124 var f = file2.pick_file( { 'mode' : 'save', 'title' : 'Save Transaction File As' } );
127 var r = G.error.yns_alert(
128 'Would you like to overwrite the existing file ' + f.leafName + '?',
129 'Transaction Export Warning',
133 'Check here to confirm this message'
135 if (r != 0) { file.close(); return; }
137 var e_file = new util.file(''); e_file._file = f;
138 e_file.write_content( 'truncate', file.get_content() );
140 var r = G.error.yns_alert(
141 'Your transactions have been successfully exported to file ' + f.leafName + '.\n\nWe strongly recommend that you now purge the transactions from this staff client. Would you like for us to do this?',
142 'Transaction Export Successful',
146 'Check here to confirm this message'
150 var filename = 'pending_xacts_exported_' + new Date().getTime();
151 var t_file = new util.file(filename);
152 while (t_file._file.exists()) {
153 filename = 'pending_xacts_' + new Date().getTime() + '.exported';
154 t_file = new util.file(filename);
155 if (count++>100) throw('Error purging transactions: Taking too long to find a unique filename for archival.');
157 file._file.moveTo(null,filename);
159 alert('Please note that you now have two sets of identical transactions. Unless the set you just exported is soley for archival purposes, we run the risk of duplicate transactions being processed on the server.');
162 alert('No filename chosen. Or a bug where you tried to overwrite an existing file.');
165 alert('There are no outstanding transactions to export.');
173 G.auth.on_standalone_import = function() {
175 JSAN.use('util.file'); var file = new util.file('pending_xacts');
176 if (file._file.exists()) {
177 alert('There are already outstanding transactions on this staff client. Upload these first.');
179 var file2 = new util.file('');
180 var f = file2.pick_file( { 'mode' : 'open', 'title' : 'Import Transaction File'} );
181 if (f && f.exists()) {
182 var i_file = new util.file(''); i_file._file = f;
183 file.write_content( 'truncate', i_file.get_content() );
185 var r = G.error.yns_alert(
186 'Your transactions have been successfully migrated to this staff client.\n\nWe recommend that you delete the external copy. Would you like for us to delete ' + f.leafName + '?',
187 'Transaction Import Successful',
191 'Check here to confirm this message'
204 G.auth.on_debug = function(action) {
207 G.window.open(urls.XUL_DEBUG_CONSOLE,'testconsole','chrome,resizable');
211 alert('cache cleared');
214 alert('debug the debug :D');
220 // XML_HTTP_SERVER will get reset to G.auth.controller.view.server_prompt.value
222 /////////////////////////////////////////////////////////////////////////////
224 var version = '/xul/server/'.split(/\//)[2];
225 if (version == 'server') {
226 version = 'versionless debug build';
227 document.getElementById('debug_gb').hidden = false;
229 //var x = document.getElementById('version_label');
230 //x.setAttribute('value','Build ID: ' + version);
231 var x = document.getElementById('about_btn');
232 x.setAttribute('label','About this client...');
237 G.window.open('about.html','about','chrome,resizable,width=800,height=600');
238 } catch(E) { alert(E); }
242 if ( found_ws_info_in_Achrome() ) {
243 //var hbox = x.parentNode; var b = document.createElement('button');
244 //b.setAttribute('label','Migrate legacy settings'); hbox.appendChild(b);
245 //b.addEventListener(
249 // handle_migration();
250 // } catch(E) { alert(E); }
254 if (window.confirm('This version of the staff client stores local settings in a different location than your previous installation. Should we attempt to migrate these settings?')) {
255 setTimeout( function() { handle_migration(); }, 0 );
260 var error = "!! This software has encountered an error. Please tell your friendly " +
261 "system administrator or software developer the following:\n" + E + '\n';
262 try { G.error.sdump('D_ERROR',error); } catch(E) { dump(error); }
265 dump('exiting main_init()\n');
268 function found_ws_info_in_Achrome() {
269 JSAN.use('util.file');
270 var f = new util.file();
271 var f_in_chrome = f.get('ws_info','chrome');
272 var path = f_in_chrome.exists() ? f_in_chrome.path : false;
277 function found_ws_info_in_Uchrome() {
278 JSAN.use('util.file');
279 var f = new util.file();
280 var f_in_uchrome = f.get('ws_info','uchrome');
281 var path = f_in_uchrome.exists() ? f_in_uchrome.path : false;
286 function handle_migration() {
287 if ( found_ws_info_in_Uchrome() ) {
288 alert('WARNING: Unable to migrate legacy settings. The settings and configuration files appear to exist in multiple locations.\n'
289 + 'To resolve manually, please consider:\n\t' + found_ws_info_in_Uchrome() + '\n'
290 + 'which is in the directory where we want to store settings for the current OS user, and:\n\t'
291 + found_ws_info_in_Achrome() + '\nwhich is where we used to store such information.\n'
294 var dirService = Components.classes["@mozilla.org/file/directory_service;1"].getService( Components.interfaces.nsIProperties );
295 var f_new = dirService.get( "UChrm", Components.interfaces.nsIFile );
296 var f_old = dirService.get( "AChrom", Components.interfaces.nsIFile );
297 f_old.append(myPackageDir); f_old.append("content"); f_old.append("conf");
298 if (window.confirm("Move the settings and configuration files from\n" + f_old.path + "\nto\n" + f_new.path + "?")) {
299 var files = f_old.directoryEntries;
300 while (files.hasMoreElements()) {
301 var file = files.getNext();
302 var file2 = file.QueryInterface( Components.interfaces.nsILocalFile );
304 file2.moveTo( f_new, '' );
306 alert('Error trying to move ' + file2.path + ' to directory ' + f_new.path + '\n');
309 location.href = location.href;
314 dump('exiting main/main.js\n');