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