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