not inserting bogus bookbag
[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 main_init() {
18         dump('entering main_init()\n');
19         try {
20                 if (typeof JSAN == 'undefined') {
21                         throw(
22                                 "The JSAN library object is missing."
23                         );
24                 }
25                 /////////////////////////////////////////////////////////////////////////////
26
27                 JSAN.errorLevel = "die"; // none, warn, or die
28                 JSAN.addRepository('..');
29
30                 //JSAN.use('test.test'); test.test.hello_world();
31
32                 var mw = self;
33                 G =  {};
34
35                 JSAN.use('util.error');
36                 G.error = new util.error();
37                 G.error.sdump('D_ERROR','Testing');
38
39                 JSAN.use('util.window');
40                 G.window = new util.window();
41
42                 //G.window.open(urls.XUL_DEBUG_CONSOLE,'testconsole','chrome,resizable');
43
44                 JSAN.use('auth.controller');
45                 G.auth = new auth.controller( { 'window' : mw } );
46
47                 JSAN.use('OpenILS.data');
48                 G.data = new OpenILS.data()
49                 G.data.on_error = G.auth.logoff;
50                 G.data.entities = entities;
51                 G.data.stash('entities');
52
53                 JSAN.use('util.file');
54                 G.file = new util.file();
55                 try {
56                         G.file.get('ws_info');
57                         G.ws_info = G.file.get_object();
58                 } catch(E) {
59                         G.ws_info = {};
60                 }
61                 G.data.ws_info = G.ws_info; G.data.stash('ws_info');
62
63                 G.auth.on_login = function() {
64
65                         var url = G.auth.controller.view.server_prompt.value || urls.remote;
66                         if (! url.match( '^http://' ) ) url = 'http://' + url;
67
68                         G.data.server = url; G.data.stash('server'); G.data.stash_retrieve();
69
70                         grant_perms(url);
71
72                         var xulG = {
73                                 'auth' : G.auth,
74                                 'url' : url,
75                                 'window' : G.window,
76                         }
77
78                         if (G.data.ws_info && G.data.ws_info[G.auth.controller.view.server_prompt.value]) {
79                                 var deck = document.getElementById('main_deck');
80                                 var iframe = document.createElement('iframe'); deck.appendChild(iframe);
81                                 iframe.setAttribute( 'src', url + '/xul/server/main/data.xul' );
82                                 iframe.contentWindow.xulG = xulG;
83                         } else {
84                                 xulG.file = G.file;
85                                 var deck = G.auth.controller.view.ws_deck;
86                                 JSAN.use('util.widgets'); util.widgets.remove_children('ws_deck');
87                                 var iframe = document.createElement('iframe'); deck.appendChild(iframe);
88                                 iframe.setAttribute( 'src', url + '/xul/server/main/ws_info.xul' );
89                                 iframe.contentWindow.xulG = xulG;
90                                 deck.selectedIndex = deck.childNodes.length - 1;
91                         }
92                 }
93
94                 G.auth.init();
95                 // XML_HTTP_SERVER will get reset to G.auth.controller.view.server_prompt.value
96
97                 /////////////////////////////////////////////////////////////////////////////
98         } catch(E) {
99                 var error = "!! This software has encountered an error.  Please tell your friendly " +
100                         "system administrator or software developer the following:\n" + E + '\n';
101                 try { G.error.sdump('D_ERROR',error); } catch(E) { dump(error); }
102                 alert(error);
103         }
104         dump('exiting main_init()\n');
105 }
106
107 dump('exiting main/main.js\n');