]> git.evergreen-ils.org Git - Evergreen.git/blob - Evergreen/staff_client/chrome/content/evergreen/util/spawn_win.js
toward spine labels
[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; else w.app_shell = app_shell;
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 function spawn_spine_label_wizard(d,placement,place,passthru_params,clone) {
138         var chrome = 'chrome://evergreen/content/cat/spine_label_wizard.xul';
139         return spawn_interface(d,placement,place,chrome,getString('spine_label_wizard'),passthru_params,clone);
140 }
141
142 /* legacy code, may be removed or refactored */
143
144 function spawn_batch_copy_editor(d,placement,place,passthru_params,clone) {
145         var chrome = 'chrome://evergreen/content/cat/copy_edit.xul';
146         return spawn_interface(d,placement,place,chrome,getString('copies_editor_interface_label'),passthru_params,clone);
147 }
148
149 function spawn_bill_pay(d,placement,place,passthru_params,clone) {
150         var chrome = 'chrome://evergreen/content/bill/bill.xul';
151         return spawn_interface(d,placement,place,chrome,getString('bills_interface_label'),passthru_params,clone);
152 }
153
154 function spawn_copy_browser(d,placement,place,passthru_params,clone) {
155         var chrome = 'chrome://evergreen/content/cat/browse_list.xul';
156         return spawn_interface(d,placement,place,chrome,getString('copy_browser_interface_label'),passthru_params,clone);
157 }
158
159 function spawn_brief_view(d,placement,place,passthru_params,clone) {
160         var chrome = 'chrome://evergreen/content/cat/brief.xul';
161         return spawn_interface(d,placement,place,chrome,'BRIEF VIEW',passthru_params,clone);
162 }
163
164 function spawn_marc_editor(d,placement,place,passthru_params,clone) {
165         var chrome = 'chrome://evergreen/content/cat/marc.xul';
166         return spawn_interface(d,placement,place,chrome,getString('marc_editor_interface_label'),passthru_params,clone);
167 }
168
169 function spawn_oclc_import(d,placement,place,passthru_params,clone) {
170         sdump('D_SPAWN','trying to spawn_oclc_import('+js2JSON(passthru_params)+')\n');
171         // sample TCN: 03715963 
172         try {
173                 if (passthru_params.tcn.length < 6) {
174                         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. :)");
175                 }
176                 var result = user_request(
177                         'open-ils.search',
178                         'open-ils.search.z3950.import',
179                         [ mw.G.auth_ses[0], passthru_params.tcn ]
180                 )[0];
181                 if (result) {
182                         if (typeof result == 'object') {
183                                 if (result.records && result.records.length > 0) {      
184                                         passthru_params['import_tree'] = result.records[0];
185                                 } else {
186                                         throw('no records. result = ' + js2JSON(result) + '\n');
187                                 }
188                         } else {
189                                 throw('result: ' + js2JSON(result) + '\n');
190                         }
191                         spawn_marc_editor(d,placement,place,passthru_params);
192                 }
193         } catch(E) {
194                 mw.handle_error(E);
195         }
196 }
197
198 function spawn_new_marc_creation(d,placement,place,passthru_params,clone) {
199         sdump('D_SPAWN','trying to spawn_new_marc_creation('+js2JSON(passthru_params)+')\n');
200         if (! passthru_params.type) passthru_params.type = 'book';
201         try {
202                 var record = user_request(
203                         'open-ils.cat',
204                         'open-ils.cat.biblio.marc_template.retrieve',
205                         [ passthru_params.type ]
206                 )[0];
207                 passthru_params['import_tree'] = record;
208                 passthru_params['new_tree'] = true;
209                 spawn_marc_editor(d,placement,place,passthru_params);
210         } catch(E) {
211                 mw.handle_error(E);
212         }
213 }
214
215 function marc_view(app_shell,record_id) {
216         try {
217                 var html = user_request(
218                         "open-ils.search",
219                         "open-ils.search.biblio.record.html",
220                         [ record_id ]
221                 )[0];
222                 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' );
223                 var id = record_id;
224                 var win = new_window("data:text/html," + html);
225                 setTimeout(
226                         function() {
227                                 win.document.title = "View MARC";
228                                 win.focus();
229                                 win.document.getElementById('marc_btn').addEventListener(
230                                         'click',
231                                         function(ev) {
232                                                 spawn_marc_editor( 
233                                                         app_shell, 'new_tab', 'main_tabbox', { 
234                                                                 'find_this_id' : record_id 
235                                                         } 
236                                                 ).find_this_id = record_id;
237                                         },
238                                         false
239                                 );
240                                 win.document.getElementById('copy_btn').addEventListener(
241                                         'click',
242                                         function(ev) {
243                                                 spawn_copy_browser( 
244                                                         app_shell, 'new_tab', 'main_tabbox', { 
245                                                                 'find_this_id' : record_id 
246                                                         } 
247                                                 ).find_this_id = record_id;
248                                         },
249                                         false
250                                 );
251                         }, 0
252                 );
253         } catch(E) {
254                 handle_error(E);
255         }
256 }
257
258 function spawn_patron_edit(d,placement,place,passthru_params,clone) {
259         var chrome = 'chrome://evergreen/content/patron/patron_edit.xul';
260         return spawn_interface(d,placement,place,chrome,getString('patron_editor_interface_label'),passthru_params,clone);
261 }
262
263 function spawn_patron_register(d,placement,place,passthru_params,clone) {
264         var chrome = 'chrome://evergreen/content/patron/patron_new_legacy.xul';
265         return spawn_interface(d,placement,place,chrome,getString('patron_register_interface_label'),passthru_params,clone);
266 }
267
268 function spawn_copy_stat_cat_edit(d,placement,place,passthru_params,clone) {
269         var chrome = 'chrome://evergreen/content/stat_cat/copy_stat_cat_editor.xul';
270         return spawn_interface(d,placement,place,chrome,getString('copy_stat_cat_editor_interface'),passthru_params,clone);
271 }
272
273 function spawn_patron_stat_cat_edit(d,placement,place,passthru_params,clone) {
274         var chrome = 'chrome://evergreen/content/stat_cat/patron_stat_cat_editor.xul';
275         return spawn_interface(d,placement,place,chrome,getString('patron_stat_cat_editor_interface'),passthru_params,clone);
276 }
277
278 function spawn_survey_admin_wizard(d,placement,place,passthru_params,clone) {
279         var chrome = 'chrome://evergreen/content/survey/survey_wizard.xul';
280         return spawn_interface(d,placement,place,chrome,getString('survey_admin_interface_label'),passthru_params,clone);
281 }
282
283 function spawn_z3950_import(d,placement,place,passthru_params,clone) {
284         var chrome = 'chrome://evergreen/content/z39_50/z39_50.xul';
285         return spawn_interface(d,placement,place,chrome,getString('z39_50_import_interface_label'),passthru_params,clone);
286 }
287
288