]> git.evergreen-ils.org Git - Evergreen.git/blob - Evergreen/staff_client/chrome/content/evergreen/util/win.js
This was me putting wrappers around the OpenSRF communication stuff. Later Bill...
[Evergreen.git] / Evergreen / staff_client / chrome / content / evergreen / util / win.js
1 dump('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         dump('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         mw.G['win_list'].push(w);
105 }
106
107 function register_patron_window(w) { }
108 function unregister_patron_window(w) { }
109
110 function close_all_windows() {
111         var w;
112         while (w = mw.G['win_list'].pop()) {
113                 w.close();
114         }
115 }
116
117 function spawn_copy_browser(tab,params) {
118         dump('trying to spawn_copy_browser('+js2JSON(params)+')\n');
119         var w;
120         var chrome = 'chrome://evergreen/content/cat/browse_list.xul';
121         if (tab) {
122                 if (tab != 'replace') { tabWindow.new_tab('main_tabbox'); }
123                 w = tabWindow.replace_tab('main_tabbox','COPIES',chrome);
124         } else {
125                 w = mw.new_window( chrome );
126         }
127         w.find_this_id = params[0];
128         w.record_columns = params;
129 }
130
131 function spawn_batch_copy_editor(tab,params) {
132         dump('trying to spawn_copy_editor(' + params + ')');
133         var w;
134         var chrome = 'chrome://evergreen/content/cat/copy_edit.xul';
135         if (tab) {
136                 if (tab != 'replace') { tabWindow.new_tab('main_tabbox'); }
137                 w = tabWindow.replace_tab('main_tabbox','COPIES EDITOR',chrome);
138         } else {
139                 w = mw.new_window( chrome );
140         }
141         w.params = params;
142 }
143
144 function spawn_marc_editor(tab,params) {
145         dump('trying to spawn_marc_editor('+js2JSON(params)+')\n');
146         var w;
147         var chrome = 'chrome://evergreen/content/cat/marc.xul';
148         if (tab) {
149                 if (tab != 'replace') { tabWindow.new_tab('main_tabbox'); }
150                 w = tabWindow.replace_tab('main_tabbox','MARC',chrome);
151         } else {
152                 w = mw.new_window( chrome );
153         }
154         w.find_this_id = params[0];
155         w.record_columns = params;
156         w.params = params;
157 }
158
159 function spawn_oclc_import(tab,params) {
160         dump('trying to spawn_marc_editor('+js2JSON(params)+')\n');
161         // sample TCN: 03715963 
162         try {
163                 if (params.tcn.length < 6) {
164                         throw("Too short.  At the moment, we're really doing a search rather than a retrieve, and it's a substring search at that.  We grab the result that matches exactly.  But sending a short query would just be mean. :)");
165                 }
166                 var result = user_request(
167                         'open-ils.search',
168                         'open-ils.search.z3950.import',
169                         [ mw.G.auth_ses[0], params.tcn ]
170                 )[0];
171                 if (typeof result == 'object') {
172                         if (result.records.length > 0) {        
173                                 params['import_tree'] = result.records[0];
174                         } else {
175                                 throw('no records. result = ' + js2JSON(result) + '\n');
176                         }
177                 } else {
178                         throw('result: ' + js2JSON(result) + '\n');
179                 }
180                 var w;
181                 var chrome = 'chrome://evergreen/content/cat/marc.xul';
182                 if (tab) {
183                         if (tab != 'replace') { tabWindow.new_tab('main_tabbox'); }
184                         w = tabWindow.replace_tab('main_tabbox','MARC',chrome);
185                 } else {
186                         w = mw.new_window( chrome );
187                 }
188                 w.params = params;
189                 w.find_this_id = -1;
190                 //w.record_columns = params;
191
192         } catch(E) {
193                 handle_error(E);
194         }
195
196 }
197
198 function spawn_bill_pay(tab,patron,params) {
199         dump('trying to spawn_bill_pay('+js2JSON(patron)+')\n');
200         dump('barcode: ' + patron.barcode() + '\n');
201         var w;
202         var chrome = 'chrome://evergreen/content/bill/bill.xul';
203         var params = { 'barcode' : patron.barcode() };
204         if (tab) {
205                 if (tab != 'replace') { tabWindow.new_tab('main_tabbox'); }
206                 w = tabWindow.replace_tab('main_tabbox','BILLS',chrome,params);
207         } else {
208                 w = mw.new_window( chrome,params );
209         }
210 }
211
212 function spawn_check_out(tab,patron,params) {
213         dump('trying to spawn_check_out('+js2JSON(patron)+')\n');
214         dump('barcode: ' + patron.barcode() + '\n');
215         var w;
216         var chrome = 'chrome://evergreen/content/circ/checkout.xul';
217         var params = { 'barcode' : patron.barcode() };
218         if (tab) {
219                 if (tab != 'replace') { tabWindow.new_tab('main_tabbox'); }
220                 w = tabWindow.replace_tab('main_tabbox','CHECK OUT',chrome,params);
221         } else {
222                 w = mw.new_window( chrome,params );
223         }
224 }
225
226 function spawn_circ_list(tab,patron,params) {
227         dump('trying to spawn_circ_list('+js2JSON(patron)+')\n');
228         dump('barcode: ' + patron.barcode() + '\n');
229         var w;
230         var chrome = 'chrome://evergreen/content/circ/circ_list.xul';
231         var params = { 'barcode' : patron.barcode() };
232         if (tab) {
233                 if (tab != 'replace') { tabWindow.new_tab('main_tabbox'); }
234                 w = tabWindow.replace_tab('main_tabbox','ITEMS OUT',chrome,params);
235         } else {
236                 w = mw.new_window( chrome,params );
237         }
238 }
239
240 function spawn_patron_edit(tab,patron,params) {
241         dump('trying to spawn_patron_edit('+js2JSON(patron)+')\n');
242         dump('barcode: ' + patron.barcode() + '\n');
243         var w;
244         var chrome = 'chrome://evergreen/content/patron/patron_edit.xul';
245         var params = { 'barcode' : patron.barcode() };
246         if (tab) {
247                 if (tab != 'replace') { tabWindow.new_tab('main_tabbox'); }
248                 w = tabWindow.replace_tab('main_tabbox','PATRON EDIT',chrome,params);
249         } else {
250                 w = mw.new_window( chrome, params );
251         }
252 }
253
254 function spawn_test() {
255         var chrome = 'chrome://evergreen/content/patron/patron_edit.xul';
256         var params = { 'barcode':'101010101010101' };
257         var w = tabWindow.replace_tab('main_tabbox','TEST',chrome,params);
258 }
259
260