]> git.evergreen-ils.org Git - Evergreen.git/blob - Evergreen/staff_client/chrome/content/evergreen/util/win.js
more thorough registering of 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         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                 s_alert(s);
34         }
35 }
36
37 function new_window(chrome,params) {
38         var name = self.name + '_' + ++mw.G['window_name_increment'];
39         var options = 'chrome,resizable=yes,scrollbars=yes,width=800,height=600,fullscreen=yes';
40         try {
41                 if (params) {
42                         if (params['window_name']) { name = params.window_name; }
43                         if (params['window_options']) { options = params.window_options; }
44                 }
45         } catch(E) {
46         }
47         //var w = window.open(
48         var w = SafeWindowOpen(
49                 chrome,
50                 name,
51                 options
52         );
53         if (w) {
54                 if (w != self) { 
55                         w.parentWindow = self;
56                         w.mw = mw;
57                         //register_window(w); 
58                 }
59                 w.am_i_a_top_level_tab = false;
60                 if (params) {
61                         w.params = params;
62                 }
63         }
64         return w;
65 }
66
67
68 // From: Bryan White on netscape.public.mozilla.xpfe, Oct 13, 2004
69 // Message-ID: <ckjh7a$18q1@ripley.netscape.com>
70 // Modified to return window handler, and do errors differently
71 function SafeWindowOpen(url,title,features)
72 {
73         var w;
74
75    netscape.security.PrivilegeManager
76      .enablePrivilege("UniversalXPConnect");    
77    const CI = Components.interfaces;
78    const PB =
79      Components.classes["@mozilla.org/preferences-service;1"]
80      .getService(CI.nsIPrefBranch);
81
82    var blocked = false;
83    try
84    {
85      // pref 'dom.disable_open_during_load' is the main popup
86      // blocker preference
87      blocked = PB.getBoolPref("dom.disable_open_during_load");
88      if(blocked)
89        PB.setBoolPref("dom.disable_open_during_load",false);
90      w = window.open(url,title,features);
91    }
92    catch(e)
93    {
94      //alert("SafeWindowOpen error:\n\n" + e);
95      handle_error(e);
96    }
97    if(blocked)
98      PB.setBoolPref("dom.disable_open_during_load",true);
99
100         return w;
101
102
103 function register_window(w) {
104         sdump('D_WIN',arg_dump(arguments,{0:true}));
105         mw.G.win_list[w.toString()] = w;
106 }
107
108 function unregister_window(w) {
109         sdump('D_WIN',arg_dump(arguments,{0:true}));
110         try { delete mw.G.win_list[w.toString()]; } catch(E) { mw.G.win_list[w.toString()] = false; }   
111 }
112
113 function close_all_windows() {
114         sdump('D_WIN',arg_dump(arguments));
115         var w;
116         for (var i in mw.G.win_list) {
117                 sdump('D_WIN','\tconsidering ' + i + '...');
118                 if (mw.G.win_list[i] != mw) {
119                         sdump('D_WIN','closing');
120                         var w = mw.G.win_list[i];
121                         try { w.close(); } catch (E) {}
122                         //unregister_window( w );
123                 }
124                 sdump('D_WIN','\n');
125         }
126         mw.close();
127 }
128
129 function register_document(d) {
130         sdump('D_WIN',arg_dump(arguments,{0:true}));
131         mw.G.doc_list[d.toString()] = d;
132 }
133
134 function unregister_document(d) {
135         sdump('D_WIN',arg_dump(arguments,{0:true}));
136         try { delete mw.G.doc_list[d.toString()]; } catch(E) { mw.G.doc_list[d.toString()] = false; }   
137 }
138
139