ebdd1c32e9c385634451a1a877e328f1cabfa6d0
[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_record_details(d,placement,place,passthru_params,clone) {
102         var chrome = 'chrome://evergreen/content/cat/details.xul';
103         return spawn_interface(d,placement,place,chrome,'DETAILS',passthru_params,clone);
104 }
105
106 function spawn_hold_capture(d,placement,place,passthru_params,clone) {
107         var chrome = 'chrome://evergreen/content/circ/hold_capture.xul';
108         return spawn_interface(d,placement,place,chrome,getString('hold_capture_interface_label'),passthru_params,clone);
109 }
110
111 function spawn_opac_navigator(d,placement,place,passthru_params,clone) {
112         var chrome = 'chrome://evergreen/content/opac/opac.xul';
113         //var chrome = 'http://google.com/';
114         return spawn_interface(d,placement,place,chrome,getString('opac_navigator_interface_label'),passthru_params,clone);
115 }
116
117 function spawn_patron_barcode_entry(d,placement,place,passthru_params,clone) {
118         var chrome = 'chrome://evergreen/content/patron/patron_barcode_entry.xul';
119         return spawn_interface(d,placement,place,chrome,getString('patron_barcode_entry_interface_label'),passthru_params,clone);
120 }
121
122 function spawn_patron_display(d,placement,place,passthru_params,clone) {
123         var chrome = 'chrome://evergreen/content/patron/patron_display.xul';
124         return spawn_interface(d,placement,place,chrome,getString('patron_display_interface_label'),passthru_params,clone);
125 }
126
127 function spawn_patron_search(d,placement,place,passthru_params,clone) {
128         var chrome = 'chrome://evergreen/content/patron/patron_search.xul';
129         return spawn_interface(d,placement,place,chrome,getString('patron_search_interface_label'),passthru_params,clone);
130 }
131
132 function spawn_receipt_template_editor(d,placement,place,passthru_params,clone) {
133         var chrome = 'chrome://evergreen/content/circ/receipt_template_editor.xul';
134         return spawn_interface(d,placement,place,chrome,getString('receipt_template_editor_interface_label'),passthru_params,clone);
135 }
136
137 /* legacy code, may be removed or refactored */
138
139 function spawn_batch_copy_editor(d,placement,place,passthru_params,clone) {
140         var chrome = 'chrome://evergreen/content/cat/copy_edit.xul';
141         return spawn_interface(d,placement,place,chrome,getString('copies_editor_interface_label'),passthru_params,clone);
142 }
143
144 function spawn_bill_pay(d,placement,place,passthru_params,clone) {
145         var chrome = 'chrome://evergreen/content/bill/bill.xul';
146         return spawn_interface(d,placement,place,chrome,getString('bills_interface_label'),passthru_params,clone);
147 }
148
149 function spawn_copy_browser(d,placement,place,passthru_params,clone) {
150         var chrome = 'chrome://evergreen/content/cat/browse_list.xul';
151         return spawn_interface(d,placement,place,chrome,getString('copy_browser_interface_label'),passthru_params,clone);
152 }
153
154 function spawn_marc_editor(d,placement,place,passthru_params,clone) {
155         var chrome = 'chrome://evergreen/content/cat/marc.xul';
156         return spawn_interface(d,placement,place,chrome,getString('marc_editor_interface_label'),passthru_params,clone);
157 }
158
159 function spawn_oclc_import(d,placement,place,passthru_params,clone) {
160         sdump('D_SPAWN','trying to spawn_oclc_import('+js2JSON(passthru_params)+')\n');
161         // sample TCN: 03715963 
162         try {
163                 if (passthru_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], passthru_params.tcn ]
170                 )[0];
171                 if (result) {
172                         if (typeof result == 'object') {
173                                 if (result.records && result.records.length > 0) {      
174                                         passthru_params['import_tree'] = result.records[0];
175                                 } else {
176                                         throw('no records. result = ' + js2JSON(result) + '\n');
177                                 }
178                         } else {
179                                 throw('result: ' + js2JSON(result) + '\n');
180                         }
181                         spawn_marc_editor(d,placement,place,passthru_params);
182                 }
183         } catch(E) {
184                 mw.handle_error(E);
185         }
186 }
187
188 function spawn_new_marc_creation(d,placement,place,passthru_params,clone) {
189         sdump('D_SPAWN','trying to spawn_new_marc_creation('+js2JSON(passthru_params)+')\n');
190         if (! passthru_params.type) passthru_params.type = 'book';
191         try {
192                 var record = user_request(
193                         'open-ils.cat',
194                         'open-ils.cat.biblio.marc_template.retrieve',
195                         [ passthru_params.type ]
196                 )[0];
197                 passthru_params['import_tree'] = record;
198                 passthru_params['new_tree'] = true;
199                 spawn_marc_editor(d,placement,place,passthru_params);
200         } catch(E) {
201                 mw.handle_error(E);
202         }
203 }
204
205 function marc_view(app_shell,record_id) {
206         try {
207                 var html = user_request(
208                         "open-ils.search",
209                         "open-ils.search.biblio.record.html",
210                         [ record_id ]
211                 )[0];
212                 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' );
213                 var id = record_id;
214                 var win = new_window("data:text/html," + html);
215                 setTimeout(
216                         function() {
217                                 win.document.title = "View MARC";
218                                 win.focus();
219                                 win.document.getElementById('marc_btn').addEventListener(
220                                         'click',
221                                         function(ev) {
222                                                 spawn_marc_editor( 
223                                                         app_shell, 'new_tab', 'main_tabbox', { 
224                                                                 'find_this_id' : record_id 
225                                                         } 
226                                                 ).find_this_id = record_id;
227                                         },
228                                         false
229                                 );
230                                 win.document.getElementById('copy_btn').addEventListener(
231                                         'click',
232                                         function(ev) {
233                                                 spawn_copy_browser( 
234                                                         app_shell, 'new_tab', 'main_tabbox', { 
235                                                                 'find_this_id' : record_id 
236                                                         } 
237                                                 ).find_this_id = record_id;
238                                         },
239                                         false
240                                 );
241                         }, 0
242                 );
243         } catch(E) {
244                 handle_error(E);
245         }
246 }
247
248 function spawn_patron_edit(d,placement,place,passthru_params,clone) {
249         var chrome = 'chrome://evergreen/content/patron/patron_edit.xul';
250         return spawn_interface(d,placement,place,chrome,getString('patron_editor_interface_label'),passthru_params,clone);
251 }
252
253 function spawn_patron_register(d,placement,place,passthru_params,clone) {
254         var chrome = 'chrome://evergreen/content/patron/patron_new_legacy.xul';
255         return spawn_interface(d,placement,place,chrome,getString('patron_register_interface_label'),passthru_params,clone);
256 }
257
258 function spawn_copy_stat_cat_edit(d,placement,place,passthru_params,clone) {
259         var chrome = 'chrome://evergreen/content/stat_cat/copy_stat_cat_editor.xul';
260         return spawn_interface(d,placement,place,chrome,getString('copy_stat_cat_editor_interface'),passthru_params,clone);
261 }
262
263 function spawn_patron_stat_cat_edit(d,placement,place,passthru_params,clone) {
264         var chrome = 'chrome://evergreen/content/stat_cat/patron_stat_cat_editor.xul';
265         return spawn_interface(d,placement,place,chrome,getString('patron_stat_cat_editor_interface'),passthru_params,clone);
266 }
267
268 function spawn_survey_admin_wizard(d,placement,place,passthru_params,clone) {
269         var chrome = 'chrome://evergreen/content/survey/survey_wizard.xul';
270         return spawn_interface(d,placement,place,chrome,getString('survey_admin_interface_label'),passthru_params,clone);
271 }
272
273 function spawn_z3950_import(d,placement,place,passthru_params,clone) {
274         var chrome = 'chrome://evergreen/content/z39_50/z39_50.xul';
275         return spawn_interface(d,placement,place,chrome,getString('z39_50_import_interface_label'),passthru_params,clone);
276 }
277
278