clear the cache at startup
[Evergreen.git] / Open-ILS / xul / staff_client / chrome / content / main / main.js
1 dump('entering main/main.js\n');
2
3 function grant_perms(url) {
4         var perms = "UniversalXPConnect UniversalPreferencesWrite UniversalBrowserWrite UniversalPreferencesRead UniversalBrowserRead";
5         dump('Granting ' + perms + ' to ' + url + '\n');
6         var pref = Components.classes["@mozilla.org/preferences-service;1"]
7                 .getService(Components.interfaces.nsIPrefBranch);
8         if (pref) {
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);
13         }
14
15 }
16
17 function clear_the_cache() {
18         try {
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);
23         } catch(E) {
24                 dump(E+'\n');alert(E);
25         }
26 }
27
28 function main_init() {
29         dump('entering main_init()\n');
30         try {
31                 clear_the_cache();
32
33                 if (typeof JSAN == 'undefined') {
34                         throw(
35                                 "The JSAN library object is missing."
36                         );
37                 }
38                 /////////////////////////////////////////////////////////////////////////////
39
40                 JSAN.errorLevel = "die"; // none, warn, or die
41                 JSAN.addRepository('..');
42
43                 //JSAN.use('test.test'); test.test.hello_world();
44
45                 var mw = self;
46                 G =  {};
47
48                 JSAN.use('util.error');
49                 G.error = new util.error();
50                 G.error.sdump('D_ERROR','Testing');
51
52                 JSAN.use('util.window');
53                 G.window = new util.window();
54
55                 //G.window.open(urls.XUL_DEBUG_CONSOLE,'testconsole','chrome,resizable');
56
57                 JSAN.use('auth.controller');
58                 G.auth = new auth.controller( { 'window' : mw } );
59
60                 JSAN.use('OpenILS.data');
61                 G.data = new OpenILS.data()
62                 G.data.on_error = G.auth.logoff;
63                 G.data.entities = entities;
64                 G.data.stash('entities');
65
66                 JSAN.use('util.file');
67                 G.file = new util.file();
68                 try {
69                         G.file.get('ws_info');
70                         G.ws_info = G.file.get_object();
71                 } catch(E) {
72                         G.ws_info = {};
73                 }
74                 G.data.ws_info = G.ws_info; G.data.stash('ws_info');
75
76                 G.auth.on_login = function() {
77
78                         var url = G.auth.controller.view.server_prompt.value || urls.remote;
79                         if (! url.match( '^http://' ) ) url = 'http://' + url;
80
81                         G.data.server = url; G.data.stash('server'); G.data.stash_retrieve();
82
83                         grant_perms(url);
84
85                         var xulG = {
86                                 'auth' : G.auth,
87                                 'url' : url,
88                                 'window' : G.window,
89                         }
90
91                         if (G.data.ws_info && G.data.ws_info[G.auth.controller.view.server_prompt.value]) {
92                                 var deck = document.getElementById('main_deck');
93                                 var iframe = document.createElement('iframe'); deck.appendChild(iframe);
94                                 iframe.setAttribute( 'src', url + '/xul/server/main/data.xul' );
95                                 iframe.contentWindow.xulG = xulG;
96                         } else {
97                                 xulG.file = G.file;
98                                 var deck = G.auth.controller.view.ws_deck;
99                                 JSAN.use('util.widgets'); util.widgets.remove_children('ws_deck');
100                                 var iframe = document.createElement('iframe'); deck.appendChild(iframe);
101                                 iframe.setAttribute( 'src', url + '/xul/server/main/ws_info.xul' );
102                                 iframe.contentWindow.xulG = xulG;
103                                 deck.selectedIndex = deck.childNodes.length - 1;
104                         }
105                 }
106
107                 G.auth.init();
108                 // XML_HTTP_SERVER will get reset to G.auth.controller.view.server_prompt.value
109
110                 /////////////////////////////////////////////////////////////////////////////
111         } catch(E) {
112                 var error = "!! This software has encountered an error.  Please tell your friendly " +
113                         "system administrator or software developer the following:\n" + E + '\n';
114                 try { G.error.sdump('D_ERROR',error); } catch(E) { dump(error); }
115                 alert(error);
116         }
117         dump('exiting main_init()\n');
118 }
119
120 dump('exiting main/main.js\n');