]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/util/deck.js
unwrapping security wrappers :)
[Evergreen.git] / Open-ILS / xul / staff_client / chrome / content / util / deck.js
1 dump('entering util/deck.js\n');
2
3 if (typeof util == 'undefined') util = {};
4 util.deck = function (id) {
5
6         this.node = document.getElementById(id);
7
8         JSAN.use('util.error'); this.error = new util.error();
9
10         if (!this.node) {
11                 var error = 'util.deck: Could not find element ' + id;
12                 this.error.sdump('D_ERROR',error);
13                 throw(error);
14         }
15         if (this.node.nodeName != 'deck') {
16                 var error = 'util.deck: ' + id + 'is not a deck' + "\nIt's a " + this.node.nodeName;
17                 this.error.sdump('D_ERROR',error);
18                 throw(error);
19         }
20
21         return this;
22 };
23
24 util.deck.prototype = {
25
26         'find_index' : function (url) {
27                 var idx = -1;
28                 var nodes = this.node.childNodes;
29                 for (var i = 0; i < nodes.length; i++) {
30                         if (nodes[i].getAttribute('src') == url) idx = i;
31                 }
32                 return idx;
33         },
34
35         'set_iframe' : function (url,params,content_params) {
36                 this.error.sdump('D_TRACE','util.deck.set_iframe: url = ' + url);
37                 var idx = this.find_index(url);
38                 if (idx>-1) {
39                         this.node.selectedIndex = idx;
40
41                         var iframe = this.node.childNodes[idx];
42
43                         if (content_params) {
44                                 try {
45                                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
46                                         this.error.sdump('D_DECK', 'set_iframe\nurl = ' + url + '\nframe.contentWindow = ' + iframe.contentWindow + '\n' + 'content_params = ' + js2JSON(content_params) );
47                                         var cw = iframe.contentWindow; 
48                                         if (typeof iframe.contentWindow.wrappedJSObject != 'undefined') cw = iframe.contentWindow.wrappedJSObject;
49                                         cw.IAMXUL = true; cw.xulG = content_params;
50                                 } catch(E) {
51                                         this.error.sdump('D_ERROR','E: ' + E + '\n');
52                                 }
53                         }
54
55                         return iframe;
56                 } else {
57                         return this.new_iframe(url,params,content_params);
58                 }
59                 
60         },
61
62         'reset_iframe' : function (url,params,content_params) {
63                 this.remove_iframe(url);
64                 return this.new_iframe(url,params,content_params);
65         },
66
67         'new_iframe' : function (url,params,content_params) {
68                 var idx = this.find_index(url);
69                 if (idx>-1) throw('An iframe already exists in deck with url = ' + url);
70
71                 var iframe = document.createElement('iframe');
72                 iframe.setAttribute('src',url);
73                 //iframe.setAttribute('flex','1');
74                 //iframe.setAttribute('style','overflow: scroll');
75                 //iframe.setAttribute('style','border: solid thin red');
76                 this.node.appendChild( iframe );
77                 this.node.selectedIndex = this.node.childNodes.length - 1;
78                 if (content_params) {
79                         try {
80                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
81                                 this.error.sdump('D_DECK', 'new_iframe\nurl = ' + url + '\nframe.contentWindow = ' + iframe.contentWindow + '\n' + 'content_params = ' + js2JSON(content_params) );
82                                 var cw = iframe.contentWindow; 
83                                 if (typeof iframe.contentWindow.wrappedJSObject != 'undefined') cw = iframe.contentWindow.wrappedJSObject;
84                                 cw.IAMXUL = true; cw.xulG = content_params;
85                                 this.error.sdump('D_DECK', 'cw = ' + cw + ' cw.xulG = ' + js2JSON(cw.xulG) );
86                         } catch(E) {
87                                 this.error.sdump('D_ERROR','E: ' + E + '\n');
88                         }
89                 }
90                 return iframe;
91         },
92
93         'remove_iframe' : function (url) {
94                 var idx = this.find_index(url);
95                 if (idx>-1) {
96                         this.node.removeChild( this.node.childNodes[ idx ] );
97                 }
98         },
99
100         /* FIXME -- consider all the browser stuff broken.. very weird behavior in new_browser */
101
102         'set_browser' : function (url,params,content_params) {
103                 this.error.sdump('D_TRACE','util.deck.set_browser: url = ' + url);
104                 var idx = this.find_index(url);
105                 if (idx>-1) {
106                         this.node.selectedIndex = idx;
107
108                         var browser = this.node.childNodes[idx];
109
110                         if (content_params) {
111                                 /* FIXME -- we'd need to reach in and change the passthru_content_params for the browser, as well as the xulG for the content */ 
112                                 alert("we're in set_browser, content_params = true");
113                         }
114
115                         return browser;
116                 } else {
117                         return this.new_browser(url,params,content_params);
118                 }
119                 
120         },
121
122         'reset_browser' : function (url,params,content_params) {
123                 this.remove_browser(url);
124                 return this.new_browser(url,params,content_params);
125         },
126
127         'new_browser' : function (url,params,content_params) {
128                 try {
129                 alert('in new_browser.. typeof xulG == ' + typeof xulG);
130                 alert('in new_browser.. typeof content_params == ' + typeof content_params);
131                 var obj = this;
132                 var idx = this.find_index(url);
133                 if (idx>-1) throw('A browser already exists in deck with url = ' + url);
134
135                 var browser = document.createElement('browser');
136                 obj.id_incr++;
137                 browser.setAttribute('type','content');
138                 browser.setAttribute('id','frame_'+obj.id_incr);
139                 browser.setAttribute('src',url);
140                 this.node.appendChild( browser );
141                 alert('after append');
142                 this.node.selectedIndex = this.node.childNodes.length - 1;
143                         dump('creating browser with src = ' + url + '\n');
144                         alert('content_params = ' + content_params);
145                         JSAN.use('util.browser');
146                         var b = new util.browser();
147                         b.init(
148                                 {
149                                         'url' : url,
150                                         'push_xulG' : true,
151                                         'alt_print' : false,
152                                         'browser_id' : 'frame_'+obj.id_incr,
153                                         'passthru_content_params' : content_params,
154                                 }
155                         );
156                 return browser;
157                 } catch(E) {
158                         alert(E);
159                 }
160         },
161
162         'remove_browser' : function (url) {
163                 var idx = this.find_index(url);
164                 if (idx>-1) {
165                         this.node.removeChild( this.node.childNodes[ idx ] );
166                 }
167         },
168
169         'id_incr' : 0,
170 }       
171
172 dump('exiting util/deck.js\n');