a98cf7b70ad51e6823ffa5e7ab5c4bf7f0969c5d
[Evergreen.git] / Evergreen / staff_client / chrome / content / evergreen / util / spawn_win.js
1 function spawn_interface(d,placement,place,chrome,label,passthru_params,clone) {
2         sdump('D_SPAWN',arg_dump(arguments,{0:true,1:true,2:true,3:true,4:true,5:true}));
3         var w;
4         switch(placement) {
5                 case 'new_tab' : 
6                         mw.new_tab(d,place); 
7                         w = spawn_interface(d,'replace_tab',place,chrome,label,passthru_params,clone); break;
8
9                 case 'replace_tab' : 
10                         w = mw.replace_tab(d,place,label,chrome); break;
11
12                 case 'new_window' : 
13                         w = new_window( chrome, { 'window_name' : label } ); break;
14
15
16                 case 'replace_iframe' :
17                 case 'replace_browser' :
18                 case 'replace_editor' :
19                         var el = placement.slice(8);
20                         var container = get_widget( d, place );
21                         empty_widget( d, container );
22                         w = spawn_interface(d,'new_' + el,place,chrome,label,passthru_params,clone); 
23                         break;
24
25                 case 'new_iframe' :
26                 case 'new_browser' :
27                 case 'new_editor' :
28                         var el = placement.slice(4);
29                         var frame = d.createElement( el );
30                         frame.setAttribute('flex','1');
31                         get_widget( d, place ).appendChild( frame );
32                         w = spawn_interface(d,'set_frame',frame,chrome,label,passthru_params,clone); 
33                         break;
34
35                 case 'set_frame' :
36                         var frame = get_widget( d, place );
37                         if (clone) {
38                                 frame.contentWindow.document = mw.G.test_win.document.cloneNode(true);
39                         } else {
40                                 frame.setAttribute('src',chrome); 
41                         }
42                         w = frame.contentWindow;
43                         break;
44         }
45         w.params = passthru_params;
46         w.mw = mw;
47         if (placement == 'new_tab' || placement == 'replace_tab') w.app_shell = d;
48         return w;
49 }
50
51 /* developer utilities */
52
53 function spawn_javascript_console(d,placement,place,passthru_params,clone) {
54         var chrome = 'chrome://global/content/console.xul';
55         return spawn_interface(d,placement,place,chrome,getString('javascript_console_label'),passthru_params,clone);
56 }
57
58 function spawn_xuleditor(d,placement,place,passthru_params,clone) {
59         var chrome = 'chrome://evergreen/content/util/xuledit.xul';
60         return spawn_interface(d,placement,place,chrome,getString('xuleditor_label'),passthru_params,clone);
61 }
62
63 function spawn_javascript_shell(d,placement,place,passthru_params,clone) {
64         var chrome = 'chrome://evergreen/content/util/shell.html';
65         return spawn_interface(d,placement,place,chrome,getString('javascript_shell_label'),passthru_params,clone);
66 }
67
68 function spawn_filter_console(d,placement,place,passthru_params,clone) {
69         var chrome = 'chrome://evergreen/content/util/filter_console.xul';
70         return spawn_interface(d,placement,place,chrome,getString('filter_console_label'),passthru_params,clone);
71 }
72
73 function spawn_fieldmapper(d,placement,place,passthru_params,clone) {
74         var chrome = 'chrome://evergreen/content/util/fm_view.xul';
75         return spawn_interface(d,placement,place,chrome,getString('fieldmapper_label'),passthru_params,clone);
76 }
77
78 /* current */
79
80 function spawn_main() {
81         sdump('D_SPAWN','trying to spawn app_shell\n');
82         try {
83                 var w = new_window('chrome://evergreen/content/main/app_shell.xul', {});
84                 if (!w) { throw('window ref == null'); }
85                 try {
86                         w.params = {};
87                         return w;
88                 } catch(E) {
89                         alert('Hrmm. ' + pretty_print( js2JSON(E) ) );
90                 }
91         } catch(E) {
92                 dump(js2JSON(E)+'\n');
93         }
94 }
95
96 function spawn_checkin(d,placement,place,passthru_params,clone) {
97         var chrome = 'chrome://evergreen/content/circ/checkin.xul';
98         return spawn_interface(d,placement,place,chrome,getString('checkin_interface_label'),passthru_params,clone);
99 }
100
101 function spawn_hold_capture(d,placement,place,passthru_params,clone) {
102         var chrome = 'chrome://evergreen/content/circ/hold_capture.xul';
103         return spawn_interface(d,placement,place,chrome,getString('hold_capture_interface_label'),passthru_params,clone);
104 }
105
106 function spawn_opac_navigator(d,placement,place,passthru_params,clone) {
107         var chrome = 'chrome://evergreen/content/opac/opac.xul';
108         //var chrome = 'http://google.com/';
109         return spawn_interface(d,placement,place,chrome,getString('opac_navigator_interface_label'),passthru_params,clone);
110 }
111
112 function spawn_patron_barcode_entry(d,placement,place,passthru_params,clone) {
113         var chrome = 'chrome://evergreen/content/patron/patron_barcode_entry.xul';
114         return spawn_interface(d,placement,place,chrome,getString('patron_barcode_entry_interface_label'),passthru_params,clone);
115 }
116
117 function spawn_patron_display(d,placement,place,passthru_params,clone) {
118         var chrome = 'chrome://evergreen/content/patron/patron_display.xul';
119         return spawn_interface(d,placement,place,chrome,getString('patron_display_interface_label'),passthru_params,clone);
120 }
121
122 function spawn_patron_search(d,placement,place,passthru_params,clone) {
123         var chrome = 'chrome://evergreen/content/patron/patron_search.xul';
124         return spawn_interface(d,placement,place,chrome,getString('patron_search_interface_label'),passthru_params,clone);
125 }
126
127 function spawn_receipt_template_editor(d,placement,place,passthru_params,clone) {
128         var chrome = 'chrome://evergreen/content/circ/receipt_template_editor.xul';
129         return spawn_interface(d,placement,place,chrome,getString('receipt_template_editor_interface_label'),passthru_params,clone);
130 }
131
132 /* legacy code, may be removed or refactored */
133
134 function spawn_batch_copy_editor(d,placement,place,passthru_params,clone) {
135         var chrome = 'chrome://evergreen/content/cat/copy_edit.xul';
136         return spawn_interface(d,placement,place,chrome,getString('copies_editor_interface_label'),passthru_params,clone);
137 }
138
139 function spawn_bill_pay(d,placement,place,passthru_params,clone) {
140         var chrome = 'chrome://evergreen/content/bill/bill.xul';
141         return spawn_interface(d,placement,place,chrome,getString('bills_interface_label'),passthru_params,clone);
142 }
143
144 function spawn_copy_browser(d,placement,place,passthru_params,clone) {
145         var chrome = 'chrome://evergreen/content/cat/browse_list.xul';
146         return spawn_interface(d,placement,place,chrome,getString('copy_browser_interface_label'),passthru_params,clone);
147 }
148
149 function spawn_marc_editor(d,placement,place,passthru_params,clone) {
150         var chrome = 'chrome://evergreen/content/cat/marc.xul';
151         return spawn_interface(d,placement,place,chrome,getString('marc_editor_interface_label'),passthru_params,clone);
152 }
153
154 function spawn_oclc_import(d,placement,place,passthru_params,clone) {
155         sdump('D_SPAWN','trying to spawn_oclc_import('+js2JSON(passthru_params)+')\n');
156         // sample TCN: 03715963 
157         try {
158                 if (passthru_params.tcn.length < 6) {
159                         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. :)");
160                 }
161                 var result = user_request(
162                         'open-ils.search',
163                         'open-ils.search.z3950.import',
164                         [ mw.G.auth_ses[0], passthru_params.tcn ]
165                 )[0];
166                 if (result) {
167                         if (typeof result == 'object') {
168                                 if (result.records && result.records.length > 0) {      
169                                         passthru_params['import_tree'] = result.records[0];
170                                 } else {
171                                         throw('no records. result = ' + js2JSON(result) + '\n');
172                                 }
173                         } else {
174                                 throw('result: ' + js2JSON(result) + '\n');
175                         }
176                         spawn_marc_editor(d,placement,place,passthru_params);
177                 }
178         } catch(E) {
179                 mw.handle_error(E);
180         }
181 }
182
183 function spawn_new_marc_creation(d,placement,place,passthru_params,clone) {
184         sdump('D_SPAWN','trying to spawn_new_marc_creation('+js2JSON(passthru_params)+')\n');
185         if (! passthru_params.type) passthru_params.type = 'book';
186         try {
187                 var record = user_request(
188                         'open-ils.cat',
189                         'open-ils.cat.biblio.marc_template.retrieve',
190                         [ passthru_params.type ]
191                 )[0];
192                 passthru_params['import_tree'] = record;
193                 passthru_params['new_tree'] = true;
194                 spawn_marc_editor(d,placement,place,passthru_params);
195         } catch(E) {
196                 mw.handle_error(E);
197         }
198 }
199
200 function marc_view(app_shell,record_id) {
201         try {
202                 var html = user_request(
203                         "open-ils.search",
204                         "open-ils.search.biblio.record.html",
205                         [ record_id ]
206                 )[0];
207                 html = html.replace( /<table/, '<div id="this_div"><input id="copy_btn" type="submit" value="Copy Browser" /><input id="marc_btn" type="submit" value="MARC Editor" /></div><table' );
208                 var id = record_id;
209                 var win = new_window("data:text/html," + html);
210                 setTimeout(
211                         function() {
212                                 win.document.title = "View MARC";
213                                 win.focus();
214                                 win.document.getElementById('marc_btn').addEventListener(
215                                         'click',
216                                         function(ev) {
217                                                 spawn_marc_editor( 
218                                                         app_shell, 'new_tab', 'main_tabbox', { 
219                                                                 'find_this_id' : record_id 
220                                                         } 
221                                                 ).find_this_id = record_id;
222                                         },
223                                         false
224                                 );
225                                 win.document.getElementById('copy_btn').addEventListener(
226                                         'click',
227                                         function(ev) {
228                                                 spawn_copy_browser( 
229                                                         app_shell, 'new_tab', 'main_tabbox', { 
230                                                                 'find_this_id' : record_id 
231                                                         } 
232                                                 ).find_this_id = record_id;
233                                         },
234                                         false
235                                 );
236                         }, 0
237                 );
238         } catch(E) {
239                 handle_error(E);
240         }
241 }
242
243 function spawn_patron_edit(d,placement,place,passthru_params,clone) {
244         var chrome = 'chrome://evergreen/content/patron/patron_edit.xul';
245         return spawn_interface(d,placement,place,chrome,getString('patron_editor_interface_label'),passthru_params,clone);
246 }
247
248 function spawn_patron_register(d,placement,place,passthru_params,clone) {
249         var chrome = 'chrome://evergreen/content/patron/patron_new_legacy.xul';
250         return spawn_interface(d,placement,place,chrome,getString('patron_register_interface_label'),passthru_params,clone);
251 }
252
253 function spawn_copy_stat_cat_edit(d,placement,place,passthru_params,clone) {
254         var chrome = 'chrome://evergreen/content/stat_cat/copy_stat_cat_editor.xul';
255         return spawn_interface(d,placement,place,chrome,getString('copy_stat_cat_editor_interface'),passthru_params,clone);
256 }
257
258 function spawn_patron_stat_cat_edit(d,placement,place,passthru_params,clone) {
259         var chrome = 'chrome://evergreen/content/stat_cat/patron_stat_cat_editor.xul';
260         return spawn_interface(d,placement,place,chrome,getString('patron_stat_cat_editor_interface'),passthru_params,clone);
261 }
262
263 function spawn_survey_admin_wizard(d,placement,place,passthru_params,clone) {
264         var chrome = 'chrome://evergreen/content/survey/survey_wizard.xul';
265         return spawn_interface(d,placement,place,chrome,getString('survey_admin_interface_label'),passthru_params,clone);
266 }
267
268 function spawn_z3950_import(d,placement,place,passthru_params,clone) {
269         var chrome = 'chrome://evergreen/content/z39_50/z39_50.xul';
270         return spawn_interface(d,placement,place,chrome,getString('z39_50_import_interface_label'),passthru_params,clone);
271 }
272
273