]> git.evergreen-ils.org Git - Evergreen.git/blob - Evergreen/staff_client/chrome/content/evergreen/util/win.js
close all windows but mw
[Evergreen.git] / Evergreen / staff_client / chrome / content / evergreen / util / win.js
1 sdump('D_WIN','Loading win.js\n');
2
3 function s_alert(s) {
4         // alert() replacement, intended to stop barcode scanners from "scanning through" the dialog
5
6         // get a reference to the prompt service component.
7         var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
8                 .getService(Components.interfaces.nsIPromptService);
9
10         // set the buttons that will appear on the dialog. It should be
11         // a set of constants multiplied by button position constants. In this case,
12         // three buttons appear, Save, Cancel and a custom button.
13         //var flags=promptService.BUTTON_TITLE_OK * promptService.BUTTON_POS_0 +
14         //      promptService.BUTTON_TITLE_CANCEL * promptService.BUTTON_POS_1 +
15         //      promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_2;
16         var flags = promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_0;
17
18         // display the dialog box. The flags set above are passed
19         // as the fourth argument. The next three arguments are custom labels used for
20         // the buttons, which are used if BUTTON_TITLE_IS_STRING is assigned to a
21         // particular button. The last two arguments are for an optional check box.
22         var check = {};
23         sdump('D_WIN','s_alert: ' + s);
24         var rv = promptService.confirmEx(window,"ALERT",
25                 s,
26                 flags, 
27                 "Enter", null, null, 
28                 "Check this box to confirm this message", 
29                 check
30         );
31         if (!check.value) {
32                 snd_bad();
33                 return s_alert(s);
34         }
35         return rv;
36 }
37
38 function yns_alert(s,title,b1,b2,b3,c) {
39         // alert() replacement, intended to stop barcode scanners from "scanning through" the dialog
40
41         // get a reference to the prompt service component.
42         var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
43                 .getService(Components.interfaces.nsIPromptService);
44
45         // set the buttons that will appear on the dialog. It should be
46         // a set of constants multiplied by button position constants. In this case,
47         // three buttons appear, Save, Cancel and a custom button.
48         //var flags=promptService.BUTTON_TITLE_OK * promptService.BUTTON_POS_0 +
49         //      promptService.BUTTON_TITLE_CANCEL * promptService.BUTTON_POS_1 +
50         //      promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_2;
51         var flags = promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_0 +
52                 promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_1 +
53                 promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_2; 
54
55         // display the dialog box. The flags set above are passed
56         // as the fourth argument. The next three arguments are custom labels used for
57         // the buttons, which are used if BUTTON_TITLE_IS_STRING is assigned to a
58         // particular button. The last two arguments are for an optional check box.
59         var check = {};
60         sdump('D_WIN','yns_alert: ' + s);
61         var rv = promptService.confirmEx(window,title, s, flags, b1, b2, b3, c, check);
62         if (c && !check.value) {
63                 snd_bad();
64                 return yns_alert(s,title,b1,b2,b3,c);
65         }
66         return rv;
67 }
68
69 function new_window(chrome,params) {
70         var name = self.name + '_' + ++mw.G['window_name_increment'];
71         var options = 'chrome,resizable=yes,scrollbars=yes,width=800,height=600,fullscreen=yes';
72         try {
73                 if (params) {
74                         if (params['window_name']) { name = params.window_name; }
75                         if (params['window_options']) { options = params.window_options; }
76                 }
77         } catch(E) {
78         }
79         //var w = window.open(
80         var w = SafeWindowOpen(
81                 chrome,
82                 name,
83                 options
84         );
85         if (w) {
86                 if (w != self) { 
87                         w.parentWindow = self;
88                         w.mw = mw;
89                         //register_window(w); 
90                 }
91                 w.am_i_a_top_level_tab = false;
92                 if (params) {
93                         w.params = params;
94                 }
95         }
96         return w;
97 }
98
99
100 // From: Bryan White on netscape.public.mozilla.xpfe, Oct 13, 2004
101 // Message-ID: <ckjh7a$18q1@ripley.netscape.com>
102 // Modified to return window handler, and do errors differently
103 function SafeWindowOpen(url,title,features)
104 {
105         var w;
106
107    netscape.security.PrivilegeManager
108      .enablePrivilege("UniversalXPConnect");    
109    const CI = Components.interfaces;
110    const PB =
111      Components.classes["@mozilla.org/preferences-service;1"]
112      .getService(CI.nsIPrefBranch);
113
114    var blocked = false;
115    try
116    {
117      // pref 'dom.disable_open_during_load' is the main popup
118      // blocker preference
119      blocked = PB.getBoolPref("dom.disable_open_during_load");
120      if(blocked)
121        PB.setBoolPref("dom.disable_open_during_load",false);
122      w = window.open(url,title,features);
123    }
124    catch(e)
125    {
126      //alert("SafeWindowOpen error:\n\n" + e);
127      handle_error(e);
128    }
129    if(blocked)
130      PB.setBoolPref("dom.disable_open_during_load",true);
131
132         return w;
133
134
135 function register_AppShell(w) {
136         sdump('D_WIN',arg_dump(arguments,{0:true}));
137         mw.G.appshell_list.push(w);
138 }
139
140 function unregister_AppShell(w) {
141         sdump('D_WIN',arg_dump(arguments,{0:true}));
142         mw.G.appshell_list = filter_list( mw.G.appshell_list, function(e){return(e!=w);} );
143 }
144
145 function register_window(w) {
146         sdump('D_WIN',arg_dump(arguments,{0:true}));
147         mw.G.win_list.push(w);
148         mw.G.last_win = w;
149         sdump('D_TRACE_EXIT',arg_dump(arguments));
150 }
151
152 function unregister_window(w) {
153         sdump('D_WIN',arg_dump(arguments,{0:true}));
154         mw.G.win_list = filter_list( mw.G.win_list, function(e){return(e!=w);} );
155         mw.G.last_win = mw.G.win_list[ mw.G.win_list.length - 1 ];
156         sdump('D_TRACE_EXIT',arg_dump(arguments));
157 }
158
159 function close_all_windows() {
160         sdump('D_WIN',arg_dump(arguments));
161         var w;
162         for (var i in mw.G.appshell_list) {
163                 sdump('D_WIN','\tconsidering ' + i + '...');
164                 if (mw.G.appshell_list[i] != mw) {
165                         sdump('D_WIN','closing');
166                         var w = mw.G.appshell_list[i];
167                         try { w.close(); } catch (E) {}
168                 }
169                 sdump('D_WIN','\n');
170         }
171         sdump('D_TRACE_EXIT',arg_dump(arguments));
172 }
173
174 function register_document(d) {
175         sdump('D_WIN',arg_dump(arguments,{0:true}));
176         mw.G.doc_list[d.toString()] = d;
177         mw.G.last_doc = d;
178 }
179
180 function unregister_document(d) {
181         sdump('D_WIN',arg_dump(arguments,{0:true}));
182         try { delete mw.G.doc_list[d.toString()]; } catch(E) { mw.G.doc_list[d.toString()] = false; }   
183 }
184
185