]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/util/deck.js
JavaScript strictness cleanup to reduce warning noise at console
[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         '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 = ' + js2JSON(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 = ' + js2JSON(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 = ' + js2JSON(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         'set_browser' : function (url,params,content_params) {
117                 this.error.sdump('D_TRACE','util.deck.set_browser: url = ' + url);
118                 var idx = this.find_index(url);
119                 if (idx>-1) {
120                         this.node.selectedIndex = idx;
121
122                         var browser = this.node.childNodes[idx];
123
124                         if (content_params) {
125                                 /* FIXME -- we'd need to reach in and change the passthru_content_params for the browser, as well as the xulG for the content */ 
126                                 alert("we're in set_browser, content_params = true");
127                         }
128
129                         return browser;
130                 } else {
131                         return this.new_browser(url,params,content_params);
132                 }
133                 
134         },
135
136         'reset_browser' : function (url,params,content_params) {
137                 this.remove_browser(url);
138                 return this.new_browser(url,params,content_params);
139         },
140
141         'new_browser' : function (url,params,content_params) {
142                 try {
143                 alert('in new_browser.. typeof xulG == ' + typeof xulG);
144                 alert('in new_browser.. typeof content_params == ' + typeof content_params);
145                 var obj = this;
146                 var idx = this.find_index(url);
147                 if (idx>-1) throw('A browser already exists in deck with url = ' + url);
148
149                 var browser = document.createElement('browser');
150                 obj.id_incr++;
151                 browser.setAttribute('type','content');
152                 browser.setAttribute('id','frame_'+obj.id_incr);
153                 browser.setAttribute('src',url);
154                 this.node.appendChild( browser );
155                 alert('after append');
156                 this.node.selectedIndex = this.node.childNodes.length - 1;
157                         dump('creating browser with src = ' + url + '\n');
158                         alert('content_params = ' + content_params);
159                         JSAN.use('util.browser');
160                         var b = new util.browser();
161                         b.init(
162                                 {
163                                         'url' : url,
164                                         'push_xulG' : true,
165                                         'alt_print' : false,
166                                         'browser_id' : 'frame_'+obj.id_incr,
167                                         'passthru_content_params' : content_params
168                                 }
169                         );
170                 return browser;
171                 } catch(E) {
172                         alert(E);
173                 }
174         },
175
176         'remove_browser' : function (url) {
177                 var idx = this.find_index(url);
178                 if (idx>-1) {
179                         this.node.removeChild( this.node.childNodes[ idx ] );
180                 }
181         },
182
183         'id_incr' : 0
184 }       
185
186 dump('exiting util/deck.js\n');