]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/util/window.js
xul_param and modal xulG conversion
[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         // Windows need unique names.  This number helps.
21         'window_name_increment' :  function() {
22                 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
23                 if (typeof data.window_name_increment == 'undefined') {
24                         data.window_name_increment = 1;
25                 } else {
26                         data.window_name_increment++;
27                 }
28                 data.stash('window_name_increment');
29                 return data.window_name_increment;
30         },
31
32         // This number gets put into the title bar for Top Level menu interface windows
33         'appshell_name_increment' : function() {
34                 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
35                 if (typeof data.appshell_name_increment == 'undefined') {
36                         data.appshell_name_increment = 1;
37                 } else {
38                         data.appshell_name_increment++;
39                 }
40                 data.stash('appshell_name_increment');
41                 return data.appshell_name_increment;
42         },
43
44         // From: Bryan White on netscape.public.mozilla.xpfe, Oct 13, 2004
45         // Message-ID: <ckjh7a$18q1@ripley.netscape.com>
46         // Modified by Jason for Evergreen
47         'SafeWindowOpen' : function (url,title,features) {
48                 var w;
49
50                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
51                 netscape.security.PrivilegeManager.enablePrivilege("UniversalPreferencesRead");
52                 netscape.security.PrivilegeManager.enablePrivilege("UniversalPreferencesWrite");
53                 netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
54                 netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite");
55
56                 const CI = Components.interfaces;
57                 const PB = Components.classes["@mozilla.org/preferences-service;1"].getService(CI.nsIPrefBranch);
58
59                 var blocked = false;
60                 try {
61                         // pref 'dom.disable_open_during_load' is the main popup blocker preference
62                         blocked = PB.getBoolPref("dom.disable_open_during_load");
63                         if(blocked) PB.setBoolPref("dom.disable_open_during_load",false);
64                         w = this.win.open(url,title,features);
65                 } catch(E) {
66                         this.error.sdump('D_ERROR','window.SafeWindowOpen: ' + E + '\n');
67                         throw(E);
68                 }
69                 if(blocked) PB.setBoolPref("dom.disable_open_during_load",true);
70
71                 return w;
72         },
73
74         'open' : function(url,title,features,my_xulG) {
75                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
76                 var key;
77                 if (!title) title = 'anon' + this.window_name_increment();
78                 if (!features) features = 'chrome';
79                 this.error.sdump('D_WIN', 'opening ' + url + ', ' + title + ', ' + features + ' from ' + this.win + '\n');
80                 var data;
81                 if (features.match(/modal/) && my_xulG) {
82                         JSAN.use('OpenILS.data'); data = new OpenILS.data(); data.init({'via':'stash'});
83                         if (typeof data.modal_xulG_stack == 'undefined') data.modal_xulG_stack = {}; 
84                         /* FIXME - not a perfect key.. could imagine two top-level windows both opening modal windows */
85                         key = url; 
86                         if (typeof xulG == 'object') if (typeof xulG.url_prefix == 'function') {
87                                 key = key.replace( xulG.url_prefix('/'), '/' ); 
88                         }
89                         if (typeof data.modal_xulG_stack[key] == 'undefined') data.modal_xulG_stack[key] = [];
90                         data.modal_xulG_stack[key].push( my_xulG );
91                         data.stash('modal_xulG_stack');
92                         this.error.sdump('D_WIN','modal key = ' + key);
93                 }
94                 var w = this.SafeWindowOpen(url,title,features);
95                 if (features.match(/modal/) && my_xulG) { 
96                         var x = data.modal_xulG_stack[key].pop();
97                         data.stash('modal_xulG_stack');
98                         return x;
99                 } else {
100                         if (my_xulG) {
101                                 if (w.contentWindow) {
102                                         w.contentWindow.xulG = my_xulG;
103                                 } else {
104                                         w.xulG = my_xulG;
105                                 }
106                         }
107                 }
108                 /*
109                 setTimeout( 
110                         function() { 
111                                 try { w.title = title; } catch(E) { dump('**'+E+'\n'); }
112                                 try { w.document.title = title; } catch(E) { dump('**'+E+'\n'); }
113                         }, 0 
114                 );
115                 */
116                 return w;
117         }
118 }
119
120 dump('exiting util/window.js\n');