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