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