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 JSAN.use('util.widgets');
112 var deck = document.getElementById('progress_space');
113 util.widgets.remove_children( deck );
114 var iframe = document.createElement('iframe'); deck.appendChild(iframe);
115 iframe.setAttribute( 'src', url + '/xul/server/main/data.xul' );
116 iframe.contentWindow.xulG = xulG;
119 var deck = G.auth.controller.view.ws_deck;
120 JSAN.use('util.widgets'); util.widgets.remove_children('ws_deck');
121 var iframe = document.createElement('iframe'); deck.appendChild(iframe);
122 iframe.setAttribute( 'src', url + '/xul/server/main/ws_info.xul' );
123 iframe.contentWindow.xulG = xulG;
124 deck.selectedIndex = deck.childNodes.length - 1;
128 G.auth.on_standalone = function() {
130 G.window.open(urls.XUL_STANDALONE,'Offline','chrome,resizable');
136 G.auth.on_standalone_export = function() {
138 JSAN.use('util.file'); var file = new util.file('pending_xacts');
139 if (file._file.exists()) {
140 var f = pick_file('save');
143 var r = G.error.yns_alert(
144 'Would you like to overwrite the existing file ' + f.leafName + '?',
145 'Transaction Export Warning',
149 'Check here to confirm this message'
151 if (r != 0) { file.close(); return; }
153 var e_file = new util.file(''); e_file._file = f;
154 e_file.write_content( 'truncate', file.get_content() );
156 var r = G.error.yns_alert(
157 '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?',
158 'Transaction Export Successful',
162 'Check here to confirm this message'
166 var filename = 'pending_xacts_exported_' + new Date().getTime();
167 var t_file = new util.file(filename);
168 while (t_file._file.exists()) {
169 filename = 'pending_xacts_' + new Date().getTime() + '.exported';
170 t_file = new util.file(filename);
171 if (count++>100) throw('Error purging transactions: Taking too long to find a unique filename for archival.');
173 file._file.moveTo(null,filename);
175 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.');
178 alert('No filename chosen. Or a bug where you tried to overwrite an existing file.');
181 alert('There are no outstanding transactions to export.');
189 G.auth.on_standalone_import = function() {
191 JSAN.use('util.file'); var file = new util.file('pending_xacts');
192 if (file._file.exists()) {
193 alert('There are already outstanding transactions on this staff client. Upload these first.');
195 var f = pick_file('open');
196 if (f && f.exists()) {
197 var i_file = new util.file(''); i_file._file = f;
198 file.write_content( 'truncate', i_file.get_content() );
200 var r = G.error.yns_alert(
201 '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 + '?',
202 'Transaction Import Successful',
206 'Check here to confirm this message'
219 G.auth.on_debug = function(action) {
222 G.window.open(urls.XUL_DEBUG_CONSOLE,'testconsole','chrome,resizable');
226 alert('cache cleared');
229 alert('debug the debug :D');
235 // XML_HTTP_SERVER will get reset to G.auth.controller.view.server_prompt.value
237 /////////////////////////////////////////////////////////////////////////////
239 var version = '/xul/server/'.split(/\//)[2];
240 if (version == 'server') {
241 version = 'versionless debug build';
242 document.getElementById('debug_gb').hidden = false;
244 //var x = document.getElementById('version_label');
245 //x.setAttribute('value','Build ID: ' + version);
246 var x = document.getElementById('about_btn');
247 x.setAttribute('label','About this client...');
252 G.window.open('about.html','about','chrome,resizable,width=800,height=600');
253 } catch(E) { alert(E); }
259 var error = "!! This software has encountered an error. Please tell your friendly " +
260 "system administrator or software developer the following:\n" + E + '\n';
261 try { G.error.sdump('D_ERROR',error); } catch(E) { dump(error); }
264 dump('exiting main_init()\n');
267 dump('exiting main/main.js\n');