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