]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/util/window.js
ddb8cbc5268ef856d30282b34d3625584a91012f
[working/Evergreen.git] / Open-ILS / xul / staff_client / chrome / content / util / window.js
1 dump('entering util/window.js\n');
2
3 if (typeof util == 'undefined') util = {};
4 util.window = function () {
5     JSAN.use('util.error'); this.error = new util.error(); this.win = window;
6     return this;
7 };
8
9 util.window.prototype = {
10     
11     // list of open window references, used for debugging in shell
12     'win_list' : [],    
13
14     // list of Top Level menu interface window references
15     'appshell_list' : [],    
16
17     // list of documents for debugging.  BROKEN
18     'doc_list' : [],    
19
20     // This number gets put into the title bar for Top Level menu interface windows
21     'appshell_name_increment' : function() {
22         JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
23         if (typeof data.appshell_name_increment == 'undefined') {
24             data.appshell_name_increment = 1;
25         } else {
26             data.appshell_name_increment++;
27         }
28         data.stash('appshell_name_increment');
29         return data.appshell_name_increment;
30     },
31
32     // From: Bryan White on netscape.public.mozilla.xpfe, Oct 13, 2004
33     // Message-ID: <ckjh7a$18q1@ripley.netscape.com>
34     // Modified by Jason for Evergreen
35     'SafeWindowOpen' : function (url,title,features) {
36         var w;
37
38         const CI = Components.interfaces;
39         const PB = Components.classes["@mozilla.org/preferences-service;1"].getService(CI.nsIPrefBranch);
40
41         var blocked = false;
42         try {
43             // pref 'dom.disable_open_during_load' is the main popup blocker preference
44             blocked = PB.getBoolPref("dom.disable_open_during_load");
45             if(blocked) PB.setBoolPref("dom.disable_open_during_load",false);
46             w = this.win.open(url,title,features);
47         } catch(E) {
48             this.error.sdump('D_ERROR','window.SafeWindowOpen: ' + E + '\n');
49             throw(E);
50         }
51         if(blocked) PB.setBoolPref("dom.disable_open_during_load",true);
52
53         return w;
54     },
55
56     'SafeWindowOpenDialog' : function (url,title,features) {
57         var w;
58
59         const CI = Components.interfaces;
60         const PB = Components.classes["@mozilla.org/preferences-service;1"].getService(CI.nsIPrefBranch);
61
62         var blocked = false;
63         try {
64             // pref 'dom.disable_open_during_load' is the main popup blocker preference
65             blocked = PB.getBoolPref("dom.disable_open_during_load");
66             if(blocked) PB.setBoolPref("dom.disable_open_during_load",false);
67             w = this.win.openDialog.apply(this.win,arguments);
68         } catch(E) {
69             this.error.sdump('D_ERROR','window.SafeWindowOpen: ' + E + '\n');
70             throw(E);
71         }
72         if(blocked) PB.setBoolPref("dom.disable_open_during_load",true);
73
74         return w;
75     },
76
77     'open' : function(url,title,features,my_xulG) {
78         var key;
79         if (!title) title = '_blank';
80         if (!features) features = 'chrome';
81         this.error.sdump('D_WIN', 'opening ' + url + ', ' + title + ', ' + features + ' from ' + this.win + '\n');
82         var data;
83         if (features.match(/modal/) && my_xulG) {
84             JSAN.use('OpenILS.data'); data = new OpenILS.data(); data.init({'via':'stash'});
85             if (typeof data.modal_xulG_stack == 'undefined') data.modal_xulG_stack = {}; 
86             /* FIXME - not a perfect key.. could imagine two top-level windows both opening modal windows */
87             key = url; 
88             if (typeof xulG == 'object') {
89                 if (typeof xulG.url_prefix == 'function') {
90                     key = key.replace( xulG.url_prefix('/'), '/' );    
91                 }
92             } else if (typeof url_prefix == 'function') {
93                     key = key.replace( url_prefix('/'), '/' );    
94             }
95             // oils://remote/ looks like http://server/ to files loaded off of it. That is, location.pathname ignores it.
96             // So remove it here, like we remove url_prefix.
97             key = key.replace('oils://remote/', '/');
98             if (typeof data.modal_xulG_stack[key] == 'undefined') data.modal_xulG_stack[key] = [];
99             data.modal_xulG_stack[key].push( my_xulG );
100             data.stash('modal_xulG_stack');
101             this.error.sdump('D_WIN','modal key = ' + key);
102         }
103         var w = this.SafeWindowOpen(url,title,features);
104         if (features.match(/modal/) && my_xulG) { 
105             data.init({'via':'stash'});
106             var x = data.modal_xulG_stack[key].pop();
107             data.stash('modal_xulG_stack');
108             w.focus();
109             return x;
110         } else {
111             if (my_xulG) {
112                 if (get_contentWindow(w)) {
113                     get_contentWindow(w).xulG = my_xulG;
114                 } else {
115                     w.xulG = my_xulG;
116                 }
117             }
118         }
119         /*
120         setTimeout( 
121             function() { 
122                 try { w.title = title; } catch(E) { dump('**'+E+'\n'); }
123                 try { w.document.title = title; } catch(E) { dump('**'+E+'\n'); }
124             }, 0 
125         );
126         */
127         return w;
128     },
129
130     'openDialog' : function(url,title,features,my_xulG) {
131         var key;
132         if (!title) title = '_blank';
133         if (!features) features = 'chrome'; // Note that this is a default for openDialog anyway
134         var outArgs = Array.prototype.slice.call(arguments);
135         outArgs.splice(3,1); // Remove my_xulG
136         this.error.sdump('D_WIN', 'opening ' + url + ', ' + title + ', ' + features + ' from ' + this.win + '\n');
137         var data;
138         if (features.match(/modal/) && my_xulG) {
139             JSAN.use('OpenILS.data'); data = new OpenILS.data(); data.init({'via':'stash'});
140             if (typeof data.modal_xulG_stack == 'undefined') data.modal_xulG_stack = {}; 
141             /* FIXME - not a perfect key.. could imagine two top-level windows both opening modal windows */
142             key = url; 
143             if (typeof xulG == 'object') {
144                 if (typeof xulG.url_prefix == 'function') {
145                     key = key.replace( xulG.url_prefix('/'), '/' );    
146                 }
147             } else if (typeof url_prefix == 'function') {
148                     key = key.replace( url_prefix('/'), '/' );    
149             }
150             // oils://remote/ looks like http://server/ to files loaded off of it. That is, location.pathname ignores it.
151             // So remove it here, like we remove url_prefix.
152             key = key.replace('oils://remote/', '/');
153             if (typeof data.modal_xulG_stack[key] == 'undefined') data.modal_xulG_stack[key] = [];
154             data.modal_xulG_stack[key].push( my_xulG );
155             data.stash('modal_xulG_stack');
156             this.error.sdump('D_WIN','modal key = ' + key);
157         }
158         var w = this.SafeWindowOpenDialog.apply(this, outArgs);
159         if (features.match(/modal/) && my_xulG) { 
160             data.init({'via':'stash'});
161             var x = data.modal_xulG_stack[key].pop();
162             data.stash('modal_xulG_stack');
163             w.focus();
164             return x;
165         } else {
166             if (my_xulG) {
167                 if (get_contentWindow(w)) {
168                     get_contentWindow(w).xulG = my_xulG;
169                 } else {
170                     w.xulG = my_xulG;
171                 }
172             }
173         }
174         /*
175         setTimeout( 
176             function() { 
177                 try { w.title = title; } catch(E) { dump('**'+E+'\n'); }
178                 try { w.document.title = title; } catch(E) { dump('**'+E+'\n'); }
179             }, 0 
180         );
181         */
182         return w;
183     }
184 }
185
186 dump('exiting util/window.js\n');