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