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 pick_file(mode) {
29 var nsIFilePicker = Components.interfaces.nsIFilePicker;
30 var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance( nsIFilePicker );
33 mode == 'open' ? "Import Transaction File" : "Save Transaction File As",
34 mode == 'open' ? nsIFilePicker.modeOpen : nsIFilePicker.modeSave
36 fp.appendFilters( nsIFilePicker.filterAll );
37 var fp_result = fp.show();
38 if ( ( fp_result == nsIFilePicker.returnOK || fp_result == nsIFilePicker.returnReplace ) && fp.file ) {
45 function main_init() {
46 dump('entering main_init()\n');
50 if (typeof JSAN == 'undefined') {
52 "The JSAN library object is missing."
55 /////////////////////////////////////////////////////////////////////////////
57 JSAN.errorLevel = "die"; // none, warn, or die
58 JSAN.addRepository('..');
60 //JSAN.use('test.test'); test.test.hello_world();
65 JSAN.use('util.error');
66 G.error = new util.error();
67 G.error.sdump('D_ERROR','Testing');
69 JSAN.use('util.window');
70 G.window = new util.window();
72 JSAN.use('auth.controller');
73 G.auth = new auth.controller( { 'window' : mw } );
75 JSAN.use('OpenILS.data');
76 G.data = new OpenILS.data()
77 G.data.on_error = G.auth.logoff;
78 G.data.entities = entities;
79 G.data.stash('entities');
81 JSAN.use('util.file');
82 G.file = new util.file();
84 G.file.get('ws_info');
85 G.ws_info = G.file.get_object(); G.file.close();
89 G.data.ws_info = G.ws_info; G.data.stash('ws_info');
91 G.auth.on_login = function() {
93 var url = G.auth.controller.view.server_prompt.value || urls.remote;
95 G.data.server_unadorned = url; G.data.stash('server_unadorned'); G.data.stash_retrieve();
97 if (! url.match( '^http://' ) ) url = 'http://' + url;
99 G.data.server = url; G.data.stash('server');
100 G.data.session = { 'key' : G.auth.session.key, 'auth' : G.auth.session.authtime }; G.data.stash('session');
101 G.data.stash_retrieve();
111 if (G.data.ws_info && G.data.ws_info[G.auth.controller.view.server_prompt.value]) {
112 JSAN.use('util.widgets');
113 var deck = document.getElementById('progress_space');
114 util.widgets.remove_children( deck );
115 var iframe = document.createElement('iframe'); deck.appendChild(iframe);
116 iframe.setAttribute( 'src', url + '/xul/server/main/data.xul' );
117 iframe.contentWindow.xulG = xulG;
120 var deck = G.auth.controller.view.ws_deck;
121 JSAN.use('util.widgets'); util.widgets.remove_children('ws_deck');
122 var iframe = document.createElement('iframe'); deck.appendChild(iframe);
123 iframe.setAttribute( 'src', url + '/xul/server/main/ws_info.xul' );
124 iframe.contentWindow.xulG = xulG;
125 deck.selectedIndex = deck.childNodes.length - 1;
129 G.auth.on_standalone = function() {
131 G.window.open(urls.XUL_STANDALONE,'Offline','chrome,resizable');
137 G.auth.on_standalone_export = function() {
139 JSAN.use('util.file'); var file = new util.file('pending_xacts');
140 if (file._file.exists()) {
141 var f = pick_file('save');
144 var r = G.error.yns_alert(
145 'Would you like to overwrite the existing file ' + f.leafName + '?',
146 'Transaction Export Warning',
150 'Check here to confirm this message'
152 if (r != 0) { file.close(); return; }
154 var e_file = new util.file(''); e_file._file = f;
155 e_file.write_content( 'truncate', file.get_content() );
157 var r = G.error.yns_alert(
158 '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?',
159 'Transaction Export Successful',
163 'Check here to confirm this message'
167 var filename = 'pending_xacts_exported_' + new Date().getTime();
168 var t_file = new util.file(filename);
169 while (t_file._file.exists()) {
170 filename = 'pending_xacts_' + new Date().getTime() + '.exported';
171 t_file = new util.file(filename);
172 if (count++>100) throw('Error purging transactions: Taking too long to find a unique filename for archival.');
174 file._file.moveTo(null,filename);
176 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.');
179 alert('No filename chosen. Or a bug where you tried to overwrite an existing file.');
182 alert('There are no outstanding transactions to export.');
190 G.auth.on_standalone_import = function() {
192 JSAN.use('util.file'); var file = new util.file('pending_xacts');
193 if (file._file.exists()) {
194 alert('There are already outstanding transactions on this staff client. Upload these first.');
196 var f = pick_file('open');
197 if (f && f.exists()) {
198 var i_file = new util.file(''); i_file._file = f;
199 file.write_content( 'truncate', i_file.get_content() );
201 var r = G.error.yns_alert(
202 '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 + '?',
203 'Transaction Import Successful',
207 'Check here to confirm this message'
220 G.auth.on_debug = function(action) {
223 G.window.open(urls.XUL_DEBUG_CONSOLE,'testconsole','chrome,resizable');
227 alert('cache cleared');
230 alert('debug the debug :D');
236 // XML_HTTP_SERVER will get reset to G.auth.controller.view.server_prompt.value
238 /////////////////////////////////////////////////////////////////////////////
240 var version = '/xul/server/'.split(/\//)[2];
241 if (version == 'server') {
242 version = 'versionless debug build';
243 document.getElementById('debug_gb').hidden = false;
245 //var x = document.getElementById('version_label');
246 //x.setAttribute('value','Build ID: ' + version);
247 var x = document.getElementById('about_btn');
248 x.setAttribute('label','About this client...');
253 G.window.open('about.html','about','chrome,resizable,width=800,height=600');
254 } catch(E) { alert(E); }
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 dump('exiting main/main.js\n');