]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/cat/spine_labels.js
Monograph Parts; Unified vol/copy wizard; Call Number affixes; Instant Detail
[working/Evergreen.git] / Open-ILS / xul / staff_client / server / cat / spine_labels.js
1         function my_init() {
2             try {
3                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
4                 if (typeof JSAN == 'undefined') { throw( $("commonStrings").getString('common.jsan.missing') ); }
5                 JSAN.errorLevel = "die"; // none, warn, or die
6                 JSAN.addRepository('/xul/server/');
7                 JSAN.use('util.error'); g.error = new util.error();
8                 g.error.sdump('D_TRACE','my_init() for spine_labels.xul');
9
10                 JSAN.use('util.network'); g.network = new util.network();
11
12                 g.cgi = new CGI();
13
14                 g.barcodes = [];
15                 if (g.cgi.param('barcodes')) {
16                     g.barcodes = g.barcodes.concat( JSON2js(g.cgi.param('barcodes')) );
17                 }
18                 JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.stash_retrieve();
19                 if (g.data.temp_barcodes_for_labels) {
20                     g.barcodes = g.barcodes.concat( g.data.temp_barcodes_for_labels );
21                     g.data.temp_barcodes_for_labels = null; g.data.stash('temp_barcodes_for_labels');
22                 }
23                 if (xulG.barcodes) {
24                     g.barcodes = g.barcodes.concat( xulG.barcodes );
25                 }
26
27                 JSAN.use('circ.util');
28                 g.cols = circ.util.columns( {} );
29                 g.col_map = {};
30                 for (var i = 0; i < g.cols.length; i++) {
31                     g.col_map[ g.cols[i].id ] = { 'regex' : new RegExp('%' + g.cols[i].id + '%',"g"), 'render' : g.cols[i].render };
32                 }
33
34                 g.volumes = {};
35
36                 for (var i = 0; i < g.barcodes.length; i++) {
37                     var copy = g.network.simple_request( 'FM_ACP_RETRIEVE_VIA_BARCODE.authoritative', [ g.barcodes[i] ] );
38                     if (typeof copy.ilsevent != 'undefined') throw(copy);
39                     var label_prefix = copy.location().label_prefix() || '';
40                     var label_suffix = copy.location().label_suffix() || '';
41                     if (!g.volumes[ copy.call_number() ]) {
42                         var volume = g.network.simple_request( 'FM_ACN_RETRIEVE.authoritative', [ copy.call_number() ] );
43                         if (typeof volume.ilsevent != 'undefined') throw(volume);
44                         var record = g.network.simple_request('MODS_SLIM_RECORD_RETRIEVE.authoritative', [ volume.record() ]);
45                         volume.record( record );
46
47                         /* The volume object has native prefix and suffixes now, so affix the ones coming from copy locations */
48                         var temp_prefix = label_prefix + ' ' + (typeof volume.prefix() == 'object' ? volume.prefix().label() : volume.prefix());
49                         var temp_suffix = (typeof volume.suffix() == 'object' ? volume.suffix().label() : volume.suffix()) + ' ' + label_suffix;
50
51                         /* And assume that leading and trailing spaces can be trimmed */
52                         temp_prefix = temp_prefix.replace(/\s+$/,'').replace(/^\s+/,'');
53                         temp_suffix = temp_suffix.replace(/\s+$/,'').replace(/^\s+/,'');
54
55                         volume.prefix( temp_prefix );
56                         volume.suffix( temp_suffix );
57
58                         g.volumes[ volume.id() ] = volume;
59                     }
60                     if (g.volumes[ copy.call_number() ].copies()) {
61                         var copies = g.volumes[ copy.call_number() ].copies();
62                         copies.push( copy );
63                         g.volumes[ copy.call_number() ].copies( copies );
64                     } else {
65                         g.volumes[ copy.call_number() ].copies( [ copy ] );
66                     }
67                 }
68
69                 generate();
70
71                 if (typeof xulG != 'undefined') $('close').hidden = true;
72
73             } catch(E) {
74                 try {
75                     g.error.standard_unexpected_error_alert('/xul/server/cat/spine_labels.xul',E);
76                 } catch(F) {
77                     alert('FIXME: ' + js2JSON(E));
78                 }
79             }
80         }
81
82         function show_macros() {
83             JSAN.use('util.functional');
84             alert( util.functional.map_list( g.cols, function(o) { return '%' + o.id + '%'; } ).join(" ") );
85         }
86
87         function $(id) { return dojo.byId(id); }
88
89         function generate(override) {
90             try {
91                 var idx = 0;
92                 JSAN.use('util.text');
93                 JSAN.use('util.money');
94                 JSAN.use('util.widgets');
95                 var pn = $('panel');
96                 $('preview').disabled = false;
97
98                 /* Grab from OU settings, then fall back to hardcoded defaults */
99                 var label_cfg = {};
100                 label_cfg.spine_width = Number($('lw').value); /* spine label width */
101                 if (!label_cfg.spine_width) {
102                     label_cfg.spine_width = g.data.hash.aous['cat.spine.line.width'] || 8;
103                     $('lw').value = label_cfg.spine_width;
104                 }
105                 label_cfg.spine_length = Number($('ll').value); /* spine label length */
106                 if (!label_cfg.spine_length) {
107                     label_cfg.spine_length = g.data.hash.aous['cat.spine.line.height'] || 9;
108                     $('ll').value = label_cfg.spine_length;
109                 }
110                 label_cfg.spine_left_margin = Number($('lm').value); /* left margin */
111                 if (!label_cfg.spine_left_margin) {
112                     label_cfg.spine_left_margin = g.data.hash.aous['cat.spine.line.margin'] || 0;
113                     $('lm').value = label_cfg.spine_left_margin;
114                 }
115                 label_cfg.font_size = Number( $('pt').value );  /* font size */
116                 if (!label_cfg.font_size) {
117                     label_cfg.font_size = g.data.hash.aous['cat.label.font.size'] || 10;
118                     $('pt').value = label_cfg.font_size;
119                 }
120                 label_cfg.font_weight = $('font_weight').value;  /* font weight */
121                 if (!label_cfg.font_weight) {
122                     label_cfg.font_weight = g.data.hash.aous['cat.label.font.weight'] || 'normal';
123                     $('font_weight').value = label_cfg.font_weight;
124                 }
125                 label_cfg.font_family = g.data.hash.aous['cat.label.font.family'] || 'monospace';
126                 label_cfg.pocket_width = Number($('plw').value) || 28; /* pocket label width */
127                 label_cfg.pocket_length = Number($('pll').value) || 9; /* pocket label length */
128
129                 if (override) {
130                     var gb = $('acn_' + g.volumes[override.acn].id());
131                     util.widgets.remove_children('acn_' + g.volumes[override.acn].id());
132                     generate_labels(g.volumes[override.acn], gb, label_cfg, override);
133                 } else {
134                     util.widgets.remove_children('panel');
135                     for (var i in g.volumes) {
136                         var vb = document.createElement('vbox'); pn.appendChild(vb);
137                         vb.setAttribute('name','template');
138                         vb.setAttribute('acn_id',g.volumes[i].id());
139                         var ds = document.createElement('description'); vb.appendChild(ds);
140                         ds.appendChild( document.createTextNode( g.volumes[i].label() ) );
141                         var ds2 = document.createElement('description'); vb.appendChild(ds2);
142                         ds2.appendChild( document.createTextNode( g.volumes[i].copies().length + ' ' + (
143                             g.volumes[i].copies().length == 1 ? $("catStrings").getString('staff.cat.spine_labels.copy') : $("catStrings").getString('staff.cat.spine_labels.copies')) ) );
144                         ds2.setAttribute('style','color: green');
145                         var hb = document.createElement('hbox'); vb.appendChild(hb);
146
147                         var gb = document.createElement('groupbox');
148                         hb.appendChild(gb); 
149                         gb.setAttribute('id','acn_' + g.volumes[i].id());
150                         gb.setAttribute('style','border: solid black 2px');
151
152                         generate_labels(g.volumes[i], gb, label_cfg, override);
153
154                         idx++;
155                     }
156                 }
157             } catch(E) {
158                 g.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.spine_labels.generate.std_unexpeceted_err'),E);
159             }
160         }
161
162         function generate_labels(volume, label_node, label_cfg, override) {
163             var names;
164             var callnum;
165
166             if (override && volume.id() == override.acn) {
167                 /* If we're calling ourself, we'll have an altered label */
168                 callnum = String(override.label);
169             } else {
170                 /* take the call number and split it on whitespace */
171                 callnum = String(volume.label());
172             }
173
174             /* for LC, split between classification subclass letters and numbers */
175             var lc_class_re = /^([A-Z]{1,3})([0-9]+.*?)$/i;
176             var lc_class_match = lc_class_re.exec(callnum);
177             if (lc_class_match && lc_class_match.length > 1) {
178                 callnum = lc_class_match[1] + ' ' + lc_class_match[2];
179             }
180
181             /* for LC, split between Cutter numbers */
182             var lc_cutter_re = /^(.*)(\.[A-Z]{1}[0-9]+.*?)$/ig;
183             var lc_cutter_match = lc_cutter_re.exec(callnum);
184             if (lc_cutter_match && lc_cutter_match.length > 1) {
185                 callnum = '';
186                 for (var i = 1; i < lc_cutter_match.length; i++) {
187                     callnum += lc_cutter_match[i] + ' ';
188                 }
189             }
190
191             /* Only add the prefixes and suffixes once */
192             if (!override || volume.id() != override.acn) {
193                 if (volume.prefix()) {
194                     callnum = volume.prefix() + ' ' + callnum;
195                 }
196                 if (volume.suffix()) {
197                     callnum += ' ' + volume.suffix();
198                 }
199             }
200
201             names = callnum.split(/\s+/);
202             var j = 0;
203             while (j < label_cfg.spine_length || j < label_cfg.pocket_length) {
204                 var hb2 = document.createElement('hbox'); label_node.appendChild(hb2);
205                 
206                 /* spine */
207                 if (j < label_cfg.spine_length) {
208                     var tb = document.createElement('textbox'); hb2.appendChild(tb); 
209                     tb.value = '';
210                     tb.setAttribute('class','plain');
211                     tb.setAttribute('style',
212                         'font-family: ' + label_cfg.font_family
213                         + '; font-size: ' + label_cfg.font_size
214                         + '; font-weight: ' + label_cfg.font_weight
215                     );
216                     tb.setAttribute('size',label_cfg.spine_width+1);
217                     tb.setAttribute('maxlength',label_cfg.spine_width);
218                     tb.setAttribute('name','spine');
219                     var spine_row_id = 'acn_' + volume.id() + '_spine_' + j;
220                     tb.setAttribute('id',spine_row_id);
221
222                     var name = names.shift();
223                     if (name) {
224                         name = String( name );
225
226                         /* if the name is greater than the label width... */
227                         if (name.length > label_cfg.spine_width) {
228                             /* then try to split it on periods */
229                             var sname = name.split(/\./);
230                             if (sname.length > 1) {
231                                 /* if we can, then put the periods back in on each splitted element */
232                                 if (name.match(/^\./)) sname[0] = '.' + sname[0];
233                                 for (var k = 1; k < sname.length; k++) sname[k] = '.' + sname[k];
234                                 /* and put all but the first one back into the names array */
235                                 names = sname.slice(1).concat( names );
236                                 /* if the name fragment is still greater than the label width... */
237                                 if (sname[0].length > label_cfg.spine_width) {
238                                     /* then just truncate and throw the rest back into the names array */
239                                     tb.value = sname[0].substr(0,label_cfg.spine_width);
240                                     names = [ sname[0].substr(label_cfg.spine_width) ].concat( names );
241                                 } else {
242                                     /* otherwise we're set */
243                                     tb.value = sname[0];
244                                 }
245                             } else {
246                                 /* if we can't split on periods, then just truncate and throw the rest back into the names array */
247                                 tb.value = name.substr(0,label_cfg.spine_width);
248                                 names = [ name.substr(label_cfg.spine_width) ].concat( names );
249                             }
250                         } else {
251                             /* otherwise we're set */
252                             tb.value = name;
253                         }
254                     }
255                     dojo.connect($(spine_row_id), 'onkeypress', 'spine_label_key_events');
256                 }
257
258                 /* pocket */
259                 if ($('pl').checked && j < label_cfg.pocket_length) {
260                     var tb2 = document.createElement('textbox'); hb2.appendChild(tb2); 
261                     tb2.value = '';
262                     tb2.setAttribute('class','plain');
263                     tb2.setAttribute('style',
264                         'font-family: ' + label_cfg.font_family
265                         + '; font-size: ' + label_cfg.font_size
266                         + '; font-weight: ' + label_cfg.font_weight
267                     );
268                     tb2.setAttribute('size',label_cfg.pocket_width+1); tb2.setAttribute('maxlength',label_cfg.pocket_width);
269                     tb2.setAttribute('name','pocket');
270                     if ($('title').checked && $('title_line').value == j + 1 && instanceOf(volume.record(),mvr)) {
271                         if (volume.record().title()) {
272                             tb2.value = util.text.wrap_on_space( volume.record().title(), label_cfg.pocket_width )[0];
273                         } else {
274                             tb2.value = '';
275                         }
276                     }
277                     if ($('title_r').checked && $('title_r_line').value == j + 1 && instanceOf(volume.record(),mvr)) {
278                         if (volume.record().title()) {
279                             tb2.value = ( ($('title_r_indent').checked ? ' ' : '') + util.text.wrap_on_space( volume.record().title(), label_cfg.pocket_width )[1]).substr(0,label_cfg.pocket_width);
280                         } else {
281                             tb2.value = '';
282                         }
283                     }
284                     if ($('author').checked && $('author_line').value == j + 1 && instanceOf(volume.record(),mvr)) {
285                         if (volume.record().author()) {
286                             tb2.value = volume.record().author().substr(0,label_cfg.pocket_width);
287                         } else {
288                             tb2.value = '';
289                         }
290                     }
291                     if ($('call_number').checked && $('call_number_line').value == j + 1) {
292                         tb2.value = volume.label().substr(0,label_cfg.pocket_width);
293                     }
294                     if ($('owning_lib_shortname').checked && $('owning_lib_shortname_line').value == j + 1) {
295                         var lib = volume.owning_lib();
296                         if (!instanceOf(lib,aou)) lib = g.data.hash.aou[ lib ];
297                         tb2.value = lib.shortname().substr(0,label_cfg.pocket_width);
298                     }
299                     if ($('owning_lib').checked && $('owning_lib_line').value == j + 1) {
300                         var lib = volume.owning_lib();
301                         if (!instanceOf(lib,aou)) lib = g.data.hash.aou[ lib ];
302                         tb2.value = lib.name().substr(0,label_cfg.pocket_width);
303                     }
304                     if ($('shelving_location').checked && $('shelving_location_line').value == j + 1) {
305                         tb2.value = '%location%';
306                     }
307                     if ($('barcode').checked && $('barcode_line').value == j + 1) {
308                         tb2.value = '%barcode%';
309                     }
310                     if ($('custom1').checked && $('custom1_line').value == j + 1) {
311                         tb2.value = $('custom1_tb').value;
312                     }
313                     if ($('custom2').checked && $('custom2_line').value == j + 1) {
314                         tb2.value = $('custom2_tb').value;
315                     }
316                     if ($('custom3').checked && $('custom3_line').value == j + 1) {
317                         tb2.value = $('custom3_tb').value;
318                     }
319                     if ($('custom4').checked && $('custom4_line').value == j + 1) {
320                         tb2.value = $('custom4_tb').value;
321                     }
322                 }
323
324                 j++;
325             }
326         }
327
328         function spine_label_key_events (event) {
329
330             /* Current value of the inpux box */
331             var line_value = event.target.value;
332
333             /* Cursor positions */
334             var sel_start = event.target.selectionStart;
335             var sel_end = event.target.selectionEnd;
336
337             /* Identifiers for this row: "acn_ID_spine_ROW" */
338             var atts = event.target.id.split('_');
339             var row_id = {
340                 "acn": atts[1],
341                 "spine": atts[3],
342                 "prefix": 'acn_' + atts[1] + '_spine_'
343             };
344
345             switch (event.charOrCode) {
346                 case dojo.keys.ENTER : {
347                     /* Create a new row by inserting a space at the
348                      * current cursor point, then regenerating the
349                      * label
350                      */
351                     if (sel_start == sel_end) {
352                         if (sel_start == 0) {
353                             /* If the cursor is at the start of the line:
354                              * insert new line
355                              */
356                             line_value = ' ' + line_value;
357                         } else if (sel_start == line_value.length) {
358                             /* Special case if the cursor is at the end of the line:
359                              * move to next line
360                              */
361                             var next_row = $(row_id.prefix + (parseInt(row_id.spine) + 1));
362                             if (next_row) {
363                                 next_row.focus();
364                             }
365                             break;
366                         } else {
367                             line_value = line_value.substr(0, sel_start) + ' ' + line_value.substr(sel_end);
368                         }
369                     } else {
370                         line_value = line_value.substr(0, sel_start) + ' ' + line_value.substr(sel_end);
371                     }
372                     event.target.value = line_value;
373
374                     /* Recreate the label */
375                     var new_label = '';
376                     var chunk;
377                     var x = 0;
378                     while (chunk = $(row_id.prefix + x)) {
379                         if (x > 0) {
380                             new_label += ' ' + chunk.value;
381                         } else {
382                             new_label = chunk.value;
383                         }
384                         x++;
385                     }
386                     generate({"acn": row_id.acn, "label": new_label});
387                     $(row_id.prefix + row_id.spine).focus();
388                     break;
389                 }
390
391                 case dojo.keys.BACKSPACE : {
392                     /* Delete line if at the start of an input box */
393                     if (sel_start == 0 && sel_end == sel_start) {
394                         var new_label = '';
395                         var chunk;
396                         var x = 0;
397                         while (x <= (row_id.spine - 1) && (chunk = $(row_id.prefix + x))) {
398                             if (x > 0) {
399                                 new_label += ' ' + chunk.value;
400                             } else {
401                                 new_label = chunk.value;
402                             }
403                             x++;
404                         }
405
406                         if (chunk = $(row_id.prefix + x)) {
407                             new_label += chunk.value;
408                             x++;
409                         }
410
411                         while (chunk = $(row_id.prefix + x)) {
412                             new_label += ' ' + chunk.value;
413                             x++;
414                         }
415                         generate({"acn": row_id.acn, "label": new_label});
416                         $(row_id.prefix + row_id.spine).focus();
417                     }
418                     if (sel_start == 0) {
419                         /* Move to the previous row */
420                         var prev_row = $(row_id.prefix + (parseInt(row_id.spine) - 1));
421                         if (prev_row) {
422                             prev_row.focus();
423                         }
424                     }
425                     break;
426                 }
427
428                 case dojo.keys.DELETE : {
429                     /* Delete line if at the end of an input box */
430                     if (sel_start == event.target.textLength) {
431                         var new_label = '';
432                         var chunk;
433                         var x = 0;
434                         while (x <= row_id.spine && (chunk = $(row_id.prefix + x))) {
435                             if (x > 0) {
436                                 new_label += ' ' + chunk.value;
437                             } else {
438                                 new_label = chunk.value;
439                             }
440                             x++;
441                         }
442
443                         if (chunk = $(row_id.prefix + x)) {
444                             new_label += chunk.value;
445                             x++;
446                         }
447
448                         while (chunk = $(row_id.prefix + x)) {
449                             new_label += ' ' + chunk.value;
450                             x++;
451                         }
452                         generate({"acn": row_id.acn, "label": new_label});
453                         $(row_id.prefix + row_id.spine).focus();
454                     }
455                     break;
456                 }
457
458                 case dojo.keys.UP_ARROW : {
459                     /* Move to the previous row */
460                     var prev_row = $(row_id.prefix + (parseInt(row_id.spine) - 1));
461                     if (prev_row) {
462                         prev_row.focus();
463                     }
464                     break;
465                 }
466
467                 case dojo.keys.DOWN_ARROW : {
468                     /* Move to the next row */
469                     var next_row = $(row_id.prefix + (parseInt(row_id.spine) + 1));
470                     if (next_row) {
471                         next_row.focus();
472                     }
473                     break;
474                 }
475
476                 default : {
477                     break;
478                 }
479             }
480         }
481
482         function expand_macros(text,copy,volume,record) {
483             var my = { 'acp' : copy, 'acn' : volume, 'mvr' : record };
484             var obj = { 'data' : g.data };
485             for (var i in g.col_map) {
486                 var re = g.col_map[i].regex;
487                 if (text.match(re)) {
488                     try {
489                         text = text.replace(re, (typeof g.col_map[i].render == 'function' ? g.col_map[i].render(my) : eval( g.col_map[i].render ) ) );
490                     } catch(E) {
491                         g.error.sdump('D_ERROR','spine_labels.js, expand_macros() = ' + E);
492                     }
493                 }
494             }
495             return text;
496         }
497
498         function preview(idx) {
499             try {
500                     netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
501                     var pt = Number( $('pt').value );  /* font size */
502                     if (!pt) {
503                         pt = g.data.hash.aous['cat.label.font.size'] || 10;
504                         $('pt').value = pt;
505                     }
506                     var ff = g.data.hash.aous['cat.label.font.family'] || 'monospace';
507                     var fw = $('font_weight').value;  /* font weight */
508                     if (!fw) {
509                         fw = g.data.hash.aous['cat.label.font.weight'] || 'normal';
510                     }
511                     var lm = Number($('lm').value); /* left margin */
512                     if (!lm) {
513                         lm = g.data.hash.aous['cat.spine.line.margin'] || 0;
514                     }
515                     var mm = Number($('mm').value); if (mm == NaN) mm = 2; /* middle margin */
516                     var lw = Number($('lw').value); /* spine label width */
517                     if (!lw) {
518                         lw = g.data.hash.aous['cat.spine.line.width'] || 8;
519                         $('lw').value = lw;
520                     }
521                     var ll = Number($('ll').value); /* spine label length */
522                     if (!ll) {
523                         ll = g.data.hash.aous['cat.spine.line.height'] || 9;
524                         $('ll').value = ll;
525                     }
526                     var plw = Number($('plw').value) || 28; var pll = Number($('pll').value) || 9; /* pocket label width and length */
527                     var html = "<html><head>";
528                     html += "<link type='text/css' rel='stylesheet' href='" + xulG.url_prefix('/xul/server/skin/print.css') + "'></link>"
529                     html += "<link type='text/css' rel='stylesheet' href='data:text/css,pre{font-family:" + ff + ";font-size:" + pt + "pt; font-weight: " + fw + ";}'></link>";
530                     html += "<title>Spine Labels</title></head><body>\n";
531                     var nl = document.getElementsByAttribute('name','template');
532                     for (var i = 0; i < nl.length; i++) {
533                         if (typeof idx == 'undefined' || idx == null) { } else {
534                             if (idx != i) continue;
535                         }
536                         var volume = g.volumes[ nl[i].getAttribute('acn_id') ];
537
538                         for (var j = 0; j < volume.copies().length; j++) {
539                             var copy = volume.copies()[j];
540                             if (i == 0 && j == 0) {
541                                 html += '<pre class="first_pre">\n';
542                             } else {
543                                 html += '<pre class="not_first_pre">\n';
544                             }
545                             var gb = nl[i].getElementsByTagName('groupbox')[0];
546                             var nl2 = gb.getElementsByAttribute('name','spine');
547                             for (var k = 0; k < nl2.length; k++) {
548                                 for (var m = 0; m < lm; m++) html += ' ';
549                                 html += util.text.preserve_string_in_html(expand_macros( nl2[k].value, copy, volume, volume.record() ).substr(0,lw));
550                                 if ($('pl').checked) {
551                                     var sib = nl2[k].nextSibling;
552                                     if (sib) {
553                                         for (var m = 0; m < lw - nl2[k].value.length; m++) html += ' ';
554                                         for (var m = 0; m < mm; m++) html += ' ';
555                                         html += util.text.preserve_string_in_html(expand_macros( sib.value, copy, volume, volume.record() ).substr(0,plw));
556                                     }
557                                 }
558                                 html += '\n';
559                             }
560                             html += '</pre hex="0C">\n';
561                         }
562                     }
563                     html += '</body></html>';
564
565                     /* From https://developer.mozilla.org/en/Using_nsIXULAppInfo */
566                     var appInfo = Components.classes["@mozilla.org/xre/app-info;1"]
567                                             .getService(Components.interfaces.nsIXULAppInfo);
568                     var platformVer = appInfo.platformVersion;
569
570                     /* We need to use different print strategies for different
571                      * XUL versions, apparently
572                      */
573                     if (platformVer.substr(0, 5) == '1.9.0') {
574                         preview_xul_190(html);
575                     } else {
576                         preview_xul_192(html);
577                     }
578
579
580             } catch(E) {
581                 g.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.spine_labels.preview.std_unexpected_err'),E);
582             }
583         }
584
585         function preview_xul_190(html) {
586             JSAN.use('util.window'); var win = new util.window();
587             var loc = ( urls.XUL_REMOTE_BROWSER );
588             //+ '?url=' + window.escape('about:blank') + '&show_print_button=1&alternate_print=1&no_xulG=1&title=' + window.escape('Spine Labels');
589             var w = win.open( loc, 'spine_preview', 'chrome,resizable,width=750,height=550');
590             w.xulG = { 
591                 'url' : 'about:blank',
592                 'url_prefix' : function (u) { return xulG.url_prefix(u); },
593                 'show_print_button' : 1,
594                 'printer_context' : 'label',
595                 'alternate_print' : 1,
596                 'no_xulG' : 1,
597                 'title' : $("catStrings").getString('staff.cat.spine_labels.preview.title'),
598                 'on_url_load' : function(b) { 
599                     try { 
600                         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
601                         if (typeof w.xulG.written == 'undefined') {
602                             w.xulG.written = true;
603                             w.g.browser.get_content().document.write(html);
604                             w.g.browser.get_content().document.close();
605                         }
606                     } catch(E) {
607                         alert(E);
608                     }
609                 }
610             };
611         }
612
613         function preview_xul_192(html) {
614             var loc = ( urls.XUL_BROWSER );
615             xulG.new_tab(
616                 loc,
617                 {
618                     'tab_name' : $("catStrings").getString('staff.cat.spine_labels.preview.title')
619                 },
620                 { 
621                     'url' : 'data:text/html;charset=utf-8,'+window.escape(html),
622                     'html_source' : html,
623                     'show_print_button' : 1,
624                     'printer_context' : 'label',
625                     'no_xulG' : 1
626                 }
627             );
628         }