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