1 dump('entering main/main.js\n');
3 function grant_perms(url) {
4 var perms = "UniversalXPConnect UniversalPreferencesWrite UniversalBrowserWrite UniversalPreferencesRead UniversalBrowserRead UniversalFileRead";
5 dump('Granting ' + perms + ' to ' + url + '\n');
6 var pref = Components.classes["@mozilla.org/preferences-service;1"]
7 .getService(Components.interfaces.nsIPrefBranch);
9 pref.setCharPref("capability.principal.codebase.p0.granted", perms);
10 pref.setCharPref("capability.principal.codebase.p0.id", url);
11 pref.setBoolPref("dom.disable_open_during_load",false);
12 pref.setBoolPref("browser.popups.showPopupBlocker",false);
17 function clear_the_cache() {
19 var cacheClass = Components.classes["@mozilla.org/network/cache-service;1"];
20 var cacheService = cacheClass.getService(Components.interfaces.nsICacheService);
21 cacheService.evictEntries(Components.interfaces.nsICache.STORE_ON_DISK);
22 cacheService.evictEntries(Components.interfaces.nsICache.STORE_IN_MEMORY);
24 dump(E+'\n');alert(E);
28 function main_init() {
29 dump('entering main_init()\n');
33 if (typeof JSAN == 'undefined') {
35 "The JSAN library object is missing."
38 /////////////////////////////////////////////////////////////////////////////
40 JSAN.errorLevel = "die"; // none, warn, or die
41 JSAN.addRepository('..');
43 //JSAN.use('test.test'); test.test.hello_world();
48 JSAN.use('util.error');
49 G.error = new util.error();
50 G.error.sdump('D_ERROR','Testing');
52 JSAN.use('util.window');
53 G.window = new util.window();
55 JSAN.use('auth.controller');
56 G.auth = new auth.controller( { 'window' : mw } );
58 JSAN.use('OpenILS.data');
59 G.data = new OpenILS.data()
60 G.data.on_error = G.auth.logoff;
61 G.data.entities = entities;
62 G.data.stash('entities');
64 JSAN.use('util.file');
65 G.file = new util.file();
67 G.file.get('ws_info');
68 G.ws_info = G.file.get_object(); G.file.close();
72 G.data.ws_info = G.ws_info; G.data.stash('ws_info');
74 G.auth.on_login = function() {
76 var url = G.auth.controller.view.server_prompt.value || urls.remote;
78 G.data.server_unadorned = url; G.data.stash('server_unadorned'); G.data.stash_retrieve();
80 if (! url.match( '^http://' ) ) url = 'http://' + url;
82 G.data.server = url; G.data.stash('server');
83 G.data.session = { 'key' : G.auth.session.key, 'auth' : G.auth.session.authtime }; G.data.stash('session');
84 G.data.stash_retrieve();
94 if (G.data.ws_info && G.data.ws_info[G.auth.controller.view.server_prompt.value]) {
95 JSAN.use('util.widgets');
96 var deck = document.getElementById('progress_space');
97 util.widgets.remove_children( deck );
98 var iframe = document.createElement('iframe'); deck.appendChild(iframe);
99 iframe.setAttribute( 'src', url + '/xul/server/main/data.xul' );
100 iframe.contentWindow.xulG = xulG;
103 var deck = G.auth.controller.view.ws_deck;
104 JSAN.use('util.widgets'); util.widgets.remove_children('ws_deck');
105 var iframe = document.createElement('iframe'); deck.appendChild(iframe);
106 iframe.setAttribute( 'src', url + '/xul/server/main/ws_info.xul' );
107 iframe.contentWindow.xulG = xulG;
108 deck.selectedIndex = deck.childNodes.length - 1;
112 G.auth.on_standalone = function() {
114 G.window.open(urls.XUL_STANDALONE,'Offline','chrome,resizable');
120 G.auth.on_standalone_export = function() {
122 JSAN.use('util.file'); var file = new util.file('pending_xacts');
123 if (file._file.exists()) {
124 var file2 = new util.file('');
125 var f = file2.pick_file( { 'mode' : 'save', 'title' : 'Save Transaction File As' } );
128 var r = G.error.yns_alert(
129 'Would you like to overwrite the existing file ' + f.leafName + '?',
130 'Transaction Export Warning',
134 'Check here to confirm this message'
136 if (r != 0) { file.close(); return; }
138 var e_file = new util.file(''); e_file._file = f;
139 e_file.write_content( 'truncate', file.get_content() );
141 var r = G.error.yns_alert(
142 '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?',
143 'Transaction Export Successful',
147 'Check here to confirm this message'
151 var filename = 'pending_xacts_exported_' + new Date().getTime();
152 var t_file = new util.file(filename);
153 while (t_file._file.exists()) {
154 filename = 'pending_xacts_' + new Date().getTime() + '.exported';
155 t_file = new util.file(filename);
156 if (count++>100) throw('Error purging transactions: Taking too long to find a unique filename for archival.');
158 file._file.moveTo(null,filename);
160 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.');
163 alert('No filename chosen. Or a bug where you tried to overwrite an existing file.');
166 alert('There are no outstanding transactions to export.');
174 G.auth.on_standalone_import = function() {
176 JSAN.use('util.file'); var file = new util.file('pending_xacts');
177 if (file._file.exists()) {
178 alert('There are already outstanding transactions on this staff client. Upload these first.');
180 var file2 = new util.file('');
181 var f = file2.pick_file( { 'mode' : 'open', 'title' : 'Import Transaction File'} );
182 if (f && f.exists()) {
183 var i_file = new util.file(''); i_file._file = f;
184 file.write_content( 'truncate', i_file.get_content() );
186 var r = G.error.yns_alert(
187 '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 + '?',
188 'Transaction Import Successful',
192 'Check here to confirm this message'
205 G.auth.on_debug = function(action) {
208 G.window.open(urls.XUL_DEBUG_CONSOLE,'testconsole','chrome,resizable');
212 alert('cache cleared');
215 alert('debug the debug :D');
221 // XML_HTTP_SERVER will get reset to G.auth.controller.view.server_prompt.value
223 /////////////////////////////////////////////////////////////////////////////
225 var version = '/xul/server/'.split(/\//)[2];
226 if (version == 'server') {
227 version = 'versionless debug build';
228 document.getElementById('debug_gb').hidden = false;
230 //var x = document.getElementById('version_label');
231 //x.setAttribute('value','Build ID: ' + version);
232 var x = document.getElementById('about_btn');
233 x.setAttribute('label','About this client...');
238 G.window.open('about.html','about','chrome,resizable,width=800,height=600');
239 } catch(E) { alert(E); }
243 if ( found_ws_info_in_Achrome() ) {
244 //var hbox = x.parentNode; var b = document.createElement('button');
245 //b.setAttribute('label','Migrate legacy settings'); hbox.appendChild(b);
246 //b.addEventListener(
250 // handle_migration();
251 // } catch(E) { alert(E); }
255 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?')) {
256 setTimeout( function() { handle_migration(); }, 0 );
261 var error = "!! This software has encountered an error. Please tell your friendly " +
262 "system administrator or software developer the following:\n" + E + '\n';
263 try { G.error.sdump('D_ERROR',error); } catch(E) { dump(error); }
266 dump('exiting main_init()\n');
269 function found_ws_info_in_Achrome() {
270 JSAN.use('util.file');
271 var f = new util.file();
272 var f_in_chrome = f.get('ws_info','chrome');
273 var path = f_in_chrome.exists() ? f_in_chrome.path : false;
278 function found_ws_info_in_Uchrome() {
279 JSAN.use('util.file');
280 var f = new util.file();
281 var f_in_uchrome = f.get('ws_info','uchrome');
282 var path = f_in_uchrome.exists() ? f_in_uchrome.path : false;
287 function handle_migration() {
288 if ( found_ws_info_in_Uchrome() ) {
289 alert('WARNING: Unable to migrate legacy settings. The settings and configuration files appear to exist in multiple locations.\n'
290 + 'To resolve manually, please consider:\n\t' + found_ws_info_in_Uchrome() + '\n'
291 + 'which is in the directory where we want to store settings for the current OS user, and:\n\t'
292 + found_ws_info_in_Achrome() + '\nwhich is where we used to store such information.\n'
295 var dirService = Components.classes["@mozilla.org/file/directory_service;1"].getService( Components.interfaces.nsIProperties );
296 var f_new = dirService.get( "UChrm", Components.interfaces.nsIFile );
297 var f_old = dirService.get( "AChrom", Components.interfaces.nsIFile );
298 f_old.append(myPackageDir); f_old.append("content"); f_old.append("conf");
299 if (window.confirm("Move the settings and configuration files from\n" + f_old.path + "\nto\n" + f_new.path + "?")) {
300 var files = f_old.directoryEntries;
301 while (files.hasMoreElements()) {
302 var file = files.getNext();
303 var file2 = file.QueryInterface( Components.interfaces.nsILocalFile );
305 file2.moveTo( f_new, '' );
307 alert('Error trying to move ' + file2.path + ' to directory ' + f_new.path + '\n');
310 location.href = location.href;
315 dump('exiting main/main.js\n');