cosmetic, and display the version
[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
80                         G.data.server_unadorned = url; G.data.stash('server_unadorned'); G.data.stash_retrieve();
81
82                         if (! url.match( '^http://' ) ) url = 'http://' + url;
83
84                         G.data.server = url; G.data.stash('server'); G.data.stash_retrieve();
85
86                         grant_perms(url);
87
88                         var xulG = {
89                                 'auth' : G.auth,
90                                 'url' : url,
91                                 'window' : G.window,
92                         }
93
94                         if (G.data.ws_info && G.data.ws_info[G.auth.controller.view.server_prompt.value]) {
95                                 var deck = document.getElementById('main_deck');
96                                 var iframe = document.createElement('iframe'); deck.appendChild(iframe);
97                                 iframe.setAttribute( 'src', url + '/xul/server/main/data.xul' );
98                                 iframe.contentWindow.xulG = xulG;
99                         } else {
100                                 xulG.file = G.file;
101                                 var deck = G.auth.controller.view.ws_deck;
102                                 JSAN.use('util.widgets'); util.widgets.remove_children('ws_deck');
103                                 var iframe = document.createElement('iframe'); deck.appendChild(iframe);
104                                 iframe.setAttribute( 'src', url + '/xul/server/main/ws_info.xul' );
105                                 iframe.contentWindow.xulG = xulG;
106                                 deck.selectedIndex = deck.childNodes.length - 1;
107                         }
108                 }
109
110                 G.auth.init();
111                 // XML_HTTP_SERVER will get reset to G.auth.controller.view.server_prompt.value
112
113                 /////////////////////////////////////////////////////////////////////////////
114
115                 var x = document.getElementById('version_label');
116                 x.setAttribute('value','Build ID: ' + '/xul/server/'.split(/\//)[2]);
117
118         } catch(E) {
119                 var error = "!! This software has encountered an error.  Please tell your friendly " +
120                         "system administrator or software developer the following:\n" + E + '\n';
121                 try { G.error.sdump('D_ERROR',error); } catch(E) { dump(error); }
122                 alert(error);
123         }
124         dump('exiting main_init()\n');
125 }
126
127 dump('exiting main/main.js\n');