first cut and bill details
[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') {
48                 w.app_shell = d;
49         } else {
50                 if (typeof app_shell != 'undefined') w.app_shell = app_shell;
51         }
52         return w;
53 }
54
55 /* developer utilities */
56
57 function spawn_javascript_console(d,placement,place,passthru_params,clone) {
58         var chrome = 'chrome://global/content/console.xul';
59         return spawn_interface(d,placement,place,chrome,getString('javascript_console_label'),passthru_params,clone);
60 }
61
62 function spawn_xuleditor(d,placement,place,passthru_params,clone) {
63         var chrome = 'chrome://evergreen/content/util/xuledit.xul';
64         return spawn_interface(d,placement,place,chrome,getString('xuleditor_label'),passthru_params,clone);
65 }
66
67 function spawn_javascript_shell(d,placement,place,passthru_params,clone) {
68         var chrome = 'chrome://evergreen/content/util/shell.html';
69         return spawn_interface(d,placement,place,chrome,getString('javascript_shell_label'),passthru_params,clone);
70 }
71
72 function spawn_filter_console(d,placement,place,passthru_params,clone) {
73         var chrome = 'chrome://evergreen/content/util/filter_console.xul';
74         return spawn_interface(d,placement,place,chrome,getString('filter_console_label'),passthru_params,clone);
75 }
76
77 function spawn_fieldmapper(d,placement,place,passthru_params,clone) {
78         var chrome = 'chrome://evergreen/content/util/fm_view.xul';
79         return spawn_interface(d,placement,place,chrome,getString('fieldmapper_label'),passthru_params,clone);
80 }
81
82 /* current */
83
84 function spawn_main() {
85         sdump('D_SPAWN','trying to spawn app_shell\n');
86         try {
87                 var w = new_window('chrome://evergreen/content/main/app_shell.xul', {});
88                 if (!w) { throw('window ref == null'); }
89                 try {
90                         w.params = {};
91                         return w;
92                 } catch(E) {
93                         alert('Hrmm. ' + pretty_print( js2JSON(E) ) );
94                 }
95         } catch(E) {
96                 dump(js2JSON(E)+'\n');
97         }
98 }
99
100 function spawn_checkin(d,placement,place,passthru_params,clone) {
101         var chrome = 'chrome://evergreen/content/circ/checkin.xul';
102         return spawn_interface(d,placement,place,chrome,getString('checkin_interface_label'),passthru_params,clone);
103 }
104
105 function spawn_record_details(d,placement,place,passthru_params,clone) {
106         var chrome = 'chrome://evergreen/content/cat/details.xul';
107         return spawn_interface(d,placement,place,chrome,'DETAILS',passthru_params,clone);
108 }
109
110 function spawn_hold_capture(d,placement,place,passthru_params,clone) {
111         var chrome = 'chrome://evergreen/content/circ/hold_capture.xul';
112         return spawn_interface(d,placement,place,chrome,getString('hold_capture_interface_label'),passthru_params,clone);
113 }
114
115 function spawn_opac_navigator(d,placement,place,passthru_params,clone) {
116         var chrome = 'chrome://evergreen/content/opac/opac.xul';
117         //var chrome = 'http://google.com/';
118         return spawn_interface(d,placement,place,chrome,getString('opac_navigator_interface_label'),passthru_params,clone);
119 }
120
121 function spawn_patron_barcode_entry(d,placement,place,passthru_params,clone) {
122         var chrome = 'chrome://evergreen/content/patron/patron_barcode_entry.xul';
123         return spawn_interface(d,placement,place,chrome,getString('patron_barcode_entry_interface_label'),passthru_params,clone);
124 }
125
126 function spawn_patron_display(d,placement,place,passthru_params,clone) {
127         var chrome = 'chrome://evergreen/content/patron/patron_display.xul';
128         return spawn_interface(d,placement,place,chrome,getString('patron_display_interface_label'),passthru_params,clone);
129 }
130
131 function spawn_patron_search(d,placement,place,passthru_params,clone) {
132         var chrome = 'chrome://evergreen/content/patron/patron_search.xul';
133         return spawn_interface(d,placement,place,chrome,getString('patron_search_interface_label'),passthru_params,clone);
134 }
135
136 function spawn_receipt_template_editor(d,placement,place,passthru_params,clone) {
137         var chrome = 'chrome://evergreen/content/circ/receipt_template_editor.xul';
138         return spawn_interface(d,placement,place,chrome,getString('receipt_template_editor_interface_label'),passthru_params,clone);
139 }
140
141 function spawn_spine_label_wizard(d,placement,place,passthru_params,clone) {
142         var chrome = 'chrome://evergreen/content/cat/spine_label_wizard.xul';
143         return spawn_interface(d,placement,place,chrome,getString('spine_label_wizard'),passthru_params,clone);
144 }
145
146 /* legacy code, may be removed or refactored */
147
148 function spawn_batch_copy_editor(d,placement,place,passthru_params,clone) {
149         var chrome = 'chrome://evergreen/content/cat/copy_edit.xul';
150         return spawn_interface(d,placement,place,chrome,getString('copies_editor_interface_label'),passthru_params,clone);
151 }
152
153 function spawn_patron_bill_wizard(d,placement,place,passthru_params,clone) {
154         var chrome = 'chrome://evergreen/content/patron/patron_bill_wizard.xul';
155         return spawn_interface(d,placement,place,chrome,getString('bills_wizard_label'),passthru_params,clone);
156 }
157
158 function spawn_patron_bill_details(d,placement,place,passthru_params,clone) {
159         var chrome = 'chrome://evergreen/content/patron/patron_bill_details.xul';
160         return spawn_interface(d,placement,place,chrome,getString('bill_details_label'),passthru_params,clone);
161 }
162
163 function spawn_copy_browser(d,placement,place,passthru_params,clone) {
164         var chrome = 'chrome://evergreen/content/cat/browse_list.xul';
165         return spawn_interface(d,placement,place,chrome,getString('copy_browser_interface_label'),passthru_params,clone);
166 }
167
168 function spawn_brief_view(d,placement,place,passthru_params,clone) {
169         var chrome = 'chrome://evergreen/content/cat/brief.xul';
170         return spawn_interface(d,placement,place,chrome,'BRIEF VIEW',passthru_params,clone);
171 }
172
173 function spawn_marc_editor(d,placement,place,passthru_params,clone) {
174         var chrome = 'chrome://evergreen/content/cat/marc.xul';
175         return spawn_interface(d,placement,place,chrome,getString('marc_editor_interface_label'),passthru_params,clone);
176 }
177
178 function spawn_oclc_import(d,placement,place,passthru_params,clone) {
179         sdump('D_SPAWN','trying to spawn_oclc_import('+js2JSON(passthru_params)+')\n');
180         // sample TCN: 03715963 
181         try {
182                 if (passthru_params.tcn.length < 6) {
183                         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. :)");
184                 }
185                 var result = user_request(
186                         'open-ils.search',
187                         'open-ils.search.z3950.import',
188                         [ mw.G.auth_ses[0], passthru_params.tcn ]
189                 )[0];
190                 if (result) {
191                         if (typeof result == 'object') {
192                                 if (result.records && result.records.length > 0) {      
193                                         passthru_params['import_tree'] = result.records[0];
194                                 } else {
195                                         throw('no records. result = ' + js2JSON(result) + '\n');
196                                 }
197                         } else {
198                                 throw('result: ' + js2JSON(result) + '\n');
199                         }
200                         spawn_marc_editor(d,placement,place,passthru_params);
201                 }
202         } catch(E) {
203                 mw.handle_error(E);
204         }
205 }
206
207 function spawn_new_marc_creation(d,placement,place,passthru_params,clone) {
208         sdump('D_SPAWN','trying to spawn_new_marc_creation('+js2JSON(passthru_params)+')\n');
209         if (! passthru_params.type) passthru_params.type = 'book';
210         try {
211                 var record = user_request(
212                         'open-ils.cat',
213                         'open-ils.cat.biblio.marc_template.retrieve',
214                         [ passthru_params.type ]
215                 )[0];
216                 passthru_params['import_tree'] = record;
217                 passthru_params['new_tree'] = true;
218                 spawn_marc_editor(d,placement,place,passthru_params);
219         } catch(E) {
220                 mw.handle_error(E);
221         }
222 }
223
224 function marc_view(app_shell,record_id) {
225         try {
226                 var html = user_request(
227                         "open-ils.search",
228                         "open-ils.search.biblio.record.html",
229                         [ record_id ]
230                 )[0];
231                 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' );
232                 var id = record_id;
233                 var win = new_window("data:text/html," + html);
234                 setTimeout(
235                         function() {
236                                 win.document.title = "View MARC";
237                                 win.focus();
238                                 win.document.getElementById('marc_btn').addEventListener(
239                                         'click',
240                                         function(ev) {
241                                                 spawn_marc_editor( 
242                                                         app_shell, 'new_tab', 'main_tabbox', { 
243                                                                 'find_this_id' : record_id 
244                                                         } 
245                                                 ).find_this_id = record_id;
246                                         },
247                                         false
248                                 );
249                                 win.document.getElementById('copy_btn').addEventListener(
250                                         'click',
251                                         function(ev) {
252                                                 spawn_copy_browser( 
253                                                         app_shell, 'new_tab', 'main_tabbox', { 
254                                                                 'find_this_id' : record_id 
255                                                         } 
256                                                 ).find_this_id = record_id;
257                                         },
258                                         false
259                                 );
260                         }, 0
261                 );
262         } catch(E) {
263                 handle_error(E);
264         }
265 }
266
267 function spawn_patron_edit(d,placement,place,passthru_params,clone) {
268         var chrome = 'chrome://evergreen/content/patron/patron_edit.xul';
269         return spawn_interface(d,placement,place,chrome,getString('patron_editor_interface_label'),passthru_params,clone);
270 }
271
272 function spawn_patron_register(d,placement,place,passthru_params,clone) {
273         var chrome = 'chrome://evergreen/content/patron/patron_new_legacy.xul';
274         return spawn_interface(d,placement,place,chrome,getString('patron_register_interface_label'),passthru_params,clone);
275 }
276
277 function spawn_copy_stat_cat_edit(d,placement,place,passthru_params,clone) {
278         var chrome = 'chrome://evergreen/content/stat_cat/copy_stat_cat_editor.xul';
279         return spawn_interface(d,placement,place,chrome,getString('copy_stat_cat_editor_interface'),passthru_params,clone);
280 }
281
282 function spawn_patron_stat_cat_edit(d,placement,place,passthru_params,clone) {
283         var chrome = 'chrome://evergreen/content/stat_cat/patron_stat_cat_editor.xul';
284         return spawn_interface(d,placement,place,chrome,getString('patron_stat_cat_editor_interface'),passthru_params,clone);
285 }
286
287 function spawn_survey_admin_wizard(d,placement,place,passthru_params,clone) {
288         var chrome = 'chrome://evergreen/content/survey/survey_wizard.xul';
289         return spawn_interface(d,placement,place,chrome,getString('survey_admin_interface_label'),passthru_params,clone);
290 }
291
292 function spawn_z3950_import(d,placement,place,passthru_params,clone) {
293         var chrome = 'chrome://evergreen/content/z39_50/z39_50.xul';
294         return spawn_interface(d,placement,place,chrome,getString('z39_50_import_interface_label'),passthru_params,clone);
295 }
296
297