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 if ( fp.show( ) == nsIFilePicker.returnOK && fp.file ) {
44 function main_init() {
45 dump('entering main_init()\n');
49 if (typeof JSAN == 'undefined') {
51 "The JSAN library object is missing."
54 /////////////////////////////////////////////////////////////////////////////
56 JSAN.errorLevel = "die"; // none, warn, or die
57 JSAN.addRepository('..');
59 //JSAN.use('test.test'); test.test.hello_world();
64 JSAN.use('util.error');
65 G.error = new util.error();
66 G.error.sdump('D_ERROR','Testing');
68 JSAN.use('util.window');
69 G.window = new util.window();
71 JSAN.use('auth.controller');
72 G.auth = new auth.controller( { 'window' : mw } );
74 JSAN.use('OpenILS.data');
75 G.data = new OpenILS.data()
76 G.data.on_error = G.auth.logoff;
77 G.data.entities = entities;
78 G.data.stash('entities');
80 JSAN.use('util.file');
81 G.file = new util.file();
83 G.file.get('ws_info');
84 G.ws_info = G.file.get_object(); G.file.close();
88 G.data.ws_info = G.ws_info; G.data.stash('ws_info');
90 G.auth.on_login = function() {
92 var url = G.auth.controller.view.server_prompt.value || urls.remote;
94 G.data.server_unadorned = url; G.data.stash('server_unadorned'); G.data.stash_retrieve();
96 if (! url.match( '^http://' ) ) url = 'http://' + url;
98 G.data.server = url; G.data.stash('server');
99 G.data.session = { 'key' : G.auth.session.key, 'auth' : G.auth.session.authtime }; G.data.stash('session');
100 G.data.stash_retrieve();
110 if (G.data.ws_info && G.data.ws_info[G.auth.controller.view.server_prompt.value]) {
111 var deck = document.getElementById('main_deck');
112 var iframe = document.createElement('iframe'); deck.appendChild(iframe);
113 iframe.setAttribute( 'src', url + '/xul/server/main/data.xul' );
114 iframe.contentWindow.xulG = xulG;
117 var deck = G.auth.controller.view.ws_deck;
118 JSAN.use('util.widgets'); util.widgets.remove_children('ws_deck');
119 var iframe = document.createElement('iframe'); deck.appendChild(iframe);
120 iframe.setAttribute( 'src', url + '/xul/server/main/ws_info.xul' );
121 iframe.contentWindow.xulG = xulG;
122 deck.selectedIndex = deck.childNodes.length - 1;
126 G.auth.on_standalone = function() {
128 G.window.open(urls.XUL_STANDALONE,'Offline','chrome,resizable');
134 G.auth.on_standalone_export = function() {
136 JSAN.use('util.file'); var file = new util.file('pending_xacts');
137 if (file._file.exists()) {
138 var f = pick_file('save');
141 var r = G.error.yns_alert(
142 'Would you like to overwrite the existing file ' + f.leafName + '?',
143 'Transaction Export Warning',
147 'Check here to confirm this message'
149 if (r != 0) { file.close(); return; }
151 var e_file = new util.file(''); e_file._file = f;
152 e_file.write_content( 'truncate', file.get_content() );
154 var r = G.error.yns_alert(
155 '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?',
156 'Transaction Export Successful',
160 'Check here to confirm this message'
164 var filename = 'pending_xacts_exported_' + new Date().getTime();
165 var t_file = new util.file(filename);
166 while (t_file._file.exists()) {
167 filename = 'pending_xacts_' + new Date().getTime() + '.exported';
168 t_file = new util.file(filename);
169 if (count++>100) throw('Error purging transactions: Taking too long to find a unique filename for archival.');
171 file._file.moveTo(null,filename);
173 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.');
176 alert('No filename chosen. Or a bug where you tried to overwrite an existing file.');
179 alert('There are no outstanding transactions to export.');
187 G.auth.on_standalone_import = function() {
189 JSAN.use('util.file'); var file = new util.file('pending_xacts');
190 if (file._file.exists()) {
191 alert('There are already outstanding transactions on this staff client. Upload these first.');
193 var f = pick_file('open');
194 if (f && f.exists()) {
195 var i_file = new util.file(''); i_file._file = f;
196 file.write_content( 'truncate', i_file.get_content() );
198 var r = G.error.yns_alert(
199 '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 + '?',
200 'Transaction Import Successful',
204 'Check here to confirm this message'
217 G.auth.on_debug = function(action) {
220 G.window.open(urls.XUL_DEBUG_CONSOLE,'testconsole','chrome,resizable');
224 alert('cache cleared');
227 alert('debug the debug :D');
233 // XML_HTTP_SERVER will get reset to G.auth.controller.view.server_prompt.value
235 /////////////////////////////////////////////////////////////////////////////
237 var x = document.getElementById('version_label');
238 var version = '/xul/server/'.split(/\//)[2];
239 if (version == 'server') {
240 version = 'versionless debug build';
241 document.getElementById('debug_gb').hidden = false;
243 x.setAttribute('value','Build ID: ' + version);
246 var error = "!! This software has encountered an error. Please tell your friendly " +
247 "system administrator or software developer the following:\n" + E + '\n';
248 try { G.error.sdump('D_ERROR',error); } catch(E) { dump(error); }
251 dump('exiting main_init()\n');
254 dump('exiting main/main.js\n');