]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/cat/spine_labels.js
a4d4afb44f57a2c7e27c8c4fbc7f025bb2edfec5
[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             var lab_class = volume.label_class();
174             if (lab_class.id() == 3) {
175                 /* Establish a pattern where every return value should be isolated on its own line 
176                    on the spine label: subclass letters, subclass numbers, cutter numbers, trailing stuff (date) */
177                 var patt1 = /^([A-Z]{1,3})\s*(\d+(?:\.\d+)?)\s*(\.[A-Z]\d*)\s*([A-Z]\d*)?\s*(\d\d\d\d(?:-\d\d\d\d)?)?\s*(.*)$/i;
178                 var result = callnum.match(patt1);
179                 if (result) { 
180                     callnum = result.slice(1).join('\t');  
181                 } else {
182                     callnum = callnum.split(/\s+/).join('\t');
183                 } 
184
185                 /* If result is null, leave callnum alone. Can't parse this malformed call num */
186             } else {
187                 callnum = callnum.split(/\s+/).join('\t');
188             }
189
190             /* Only add the prefixes and suffixes once */
191             if (!override || volume.id() != override.acn) {
192                 if (volume.prefix()) {
193                     callnum = volume.prefix() + '\t' + callnum;
194                 }
195                 if (volume.suffix()) {
196                     callnum += '\t' + volume.suffix();
197                 }
198             }
199
200             /* At this point, the call number pieces are separated by tab characters.  This allows
201             *  some space-containing constructs like "v. 1" to appear on one line
202             */
203             callnum = callnum.replace(/\t\t/g,'\t');  /* Squeeze out empties */ 
204             names = callnum.split('\t');
205             var j = 0;
206             while (j < label_cfg.spine_length || j < label_cfg.pocket_length) {
207                 var hb2 = document.createElement('hbox'); label_node.appendChild(hb2);
208                 
209                 /* spine */
210                 if (j < label_cfg.spine_length) {
211                     var tb = document.createElement('textbox'); hb2.appendChild(tb); 
212                     tb.value = '';
213                     tb.setAttribute('class','plain');
214                     tb.setAttribute('style',
215                         'font-family: ' + label_cfg.font_family
216                         + '; font-size: ' + label_cfg.font_size
217                         + '; font-weight: ' + label_cfg.font_weight
218                     );
219                     tb.setAttribute('size',label_cfg.spine_width+1);
220                     tb.setAttribute('maxlength',label_cfg.spine_width);
221                     tb.setAttribute('name','spine');
222                     var spine_row_id = 'acn_' + volume.id() + '_spine_' + j;
223                     tb.setAttribute('id',spine_row_id);
224
225                     var name = names.shift();
226                     if (name) {
227                         name = String( name );
228
229                         /* if the name is greater than the label width... */
230                         if (name.length > label_cfg.spine_width) {
231                             /* then try to split it on periods */
232                             var sname = name.split(/\./);
233                             if (sname.length > 1) {
234                                 /* if we can, then put the periods back in on each splitted element */
235                                 if (name.match(/^\./)) sname[0] = '.' + sname[0];
236                                 for (var k = 1; k < sname.length; k++) sname[k] = '.' + sname[k];
237                                 /* and put all but the first one back into the names array */
238                                 names = sname.slice(1).concat( names );
239                                 /* if the name fragment is still greater than the label width... */
240                                 if (sname[0].length > label_cfg.spine_width) {
241                                     /* then just truncate and throw the rest back into the names array */
242                                     tb.value = sname[0].substr(0,label_cfg.spine_width);
243                                     names = [ sname[0].substr(label_cfg.spine_width) ].concat( names );
244                                 } else {
245                                     /* otherwise we're set */
246                                     tb.value = sname[0];
247                                 }
248                             } else {
249                                 /* if we can't split on periods, then just truncate and throw the rest back into the names array */
250                                 tb.value = name.substr(0,label_cfg.spine_width);
251                                 names = [ name.substr(label_cfg.spine_width) ].concat( names );
252                             }
253                         } else {
254                             /* otherwise we're set */
255                             tb.value = name;
256                         }
257                     }
258                     dojo.connect($(spine_row_id), 'onkeypress', 'spine_label_key_events');
259                 }
260
261                 /* pocket */
262                 if ($('pl').checked && j < label_cfg.pocket_length) {
263                     var tb2 = document.createElement('textbox'); hb2.appendChild(tb2); 
264                     tb2.value = '';
265                     tb2.setAttribute('class','plain');
266                     tb2.setAttribute('style',
267                         'font-family: ' + label_cfg.font_family
268                         + '; font-size: ' + label_cfg.font_size
269                         + '; font-weight: ' + label_cfg.font_weight
270                     );
271                     tb2.setAttribute('size',label_cfg.pocket_width+1); tb2.setAttribute('maxlength',label_cfg.pocket_width);
272                     tb2.setAttribute('name','pocket');
273                     if ($('title').checked && $('title_line').value == j + 1 && instanceOf(volume.record(),mvr)) {
274                         if (volume.record().title()) {
275                             tb2.value = util.text.wrap_on_space( volume.record().title(), label_cfg.pocket_width )[0];
276                         } else {
277                             tb2.value = '';
278                         }
279                     }
280                     if ($('title_r').checked && $('title_r_line').value == j + 1 && instanceOf(volume.record(),mvr)) {
281                         if (volume.record().title()) {
282                             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);
283                         } else {
284                             tb2.value = '';
285                         }
286                     }
287                     if ($('author').checked && $('author_line').value == j + 1 && instanceOf(volume.record(),mvr)) {
288                         if (volume.record().author()) {
289                             tb2.value = volume.record().author().substr(0,label_cfg.pocket_width);
290                         } else {
291                             tb2.value = '';
292                         }
293                     }
294                     if ($('call_number').checked && $('call_number_line').value == j + 1) {
295                         tb2.value = (
296                             (volume.prefix() + ' ' + volume.label() + ' ' + volume.suffix())
297                             .replace(/\s+$/,'')
298                             .replace(/^\s+/,'')
299                             .substr(0,label_cfg.pocket_width)
300                         );
301                     }
302                     if ($('owning_lib_shortname').checked && $('owning_lib_shortname_line').value == j + 1) {
303                         var lib = volume.owning_lib();
304                         if (!instanceOf(lib,aou)) lib = g.data.hash.aou[ lib ];
305                         tb2.value = lib.shortname().substr(0,label_cfg.pocket_width);
306                     }
307                     if ($('owning_lib').checked && $('owning_lib_line').value == j + 1) {
308                         var lib = volume.owning_lib();
309                         if (!instanceOf(lib,aou)) lib = g.data.hash.aou[ lib ];
310                         tb2.value = lib.name().substr(0,label_cfg.pocket_width);
311                     }
312                     if ($('shelving_location').checked && $('shelving_location_line').value == j + 1) {
313                         tb2.value = '%location%';
314                     }
315                     if ($('barcode').checked && $('barcode_line').value == j + 1) {
316                         tb2.value = '%barcode%';
317                     }
318                     if ($('custom1').checked && $('custom1_line').value == j + 1) {
319                         tb2.value = $('custom1_tb').value;
320                     }
321                     if ($('custom2').checked && $('custom2_line').value == j + 1) {
322                         tb2.value = $('custom2_tb').value;
323                     }
324                     if ($('custom3').checked && $('custom3_line').value == j + 1) {
325                         tb2.value = $('custom3_tb').value;
326                     }
327                     if ($('custom4').checked && $('custom4_line').value == j + 1) {
328                         tb2.value = $('custom4_tb').value;
329                     }
330                 }
331
332                 j++;
333             }
334         }
335
336         function spine_label_key_events (event) {
337
338             /* Current value of the inpux box */
339             var line_value = event.target.value;
340
341             /* Cursor positions */
342             var sel_start = event.target.selectionStart;
343             var sel_end = event.target.selectionEnd;
344
345             /* Identifiers for this row: "acn_ID_spine_ROW" */
346             var atts = event.target.id.split('_');
347             var row_id = {
348                 "acn": atts[1],
349                 "spine": atts[3],
350                 "prefix": 'acn_' + atts[1] + '_spine_'
351             };
352
353             switch (event.charOrCode) {
354                 case dojo.keys.ENTER : {
355                     /* Create a new row by inserting a space at the
356                      * current cursor point, then regenerating the
357                      * label
358                      */
359                     if (sel_start == sel_end) {
360                         if (sel_start == 0) {
361                             /* If the cursor is at the start of the line:
362                              * insert new line
363                              */
364                             line_value = ' ' + line_value;
365                         } else if (sel_start == line_value.length) {
366                             /* Special case if the cursor is at the end of the line:
367                              * move to next line
368                              */
369                             var next_row = $(row_id.prefix + (parseInt(row_id.spine) + 1));
370                             if (next_row) {
371                                 next_row.focus();
372                             }
373                             break;
374                         } else {
375                             line_value = line_value.substr(0, sel_start) + ' ' + line_value.substr(sel_end);
376                         }
377                     } else {
378                         line_value = line_value.substr(0, sel_start) + ' ' + line_value.substr(sel_end);
379                     }
380                     event.target.value = line_value;
381
382                     /* Recreate the label */
383                     var new_label = '';
384                     var chunk;
385                     var x = 0;
386                     while (chunk = $(row_id.prefix + x)) {
387                         if (x > 0) {
388                             new_label += ' ' + chunk.value;
389                         } else {
390                             new_label = chunk.value;
391                         }
392                         x++;
393                     }
394                     generate({"acn": row_id.acn, "label": new_label});
395                     $(row_id.prefix + row_id.spine).focus();
396                     break;
397                 }
398
399                 case dojo.keys.BACKSPACE : {
400                     /* Delete line if at the start of an input box */
401                     if (sel_start == 0 && sel_end == sel_start) {
402                         var new_label = '';
403                         var chunk;
404                         var x = 0;
405                         while (x <= (row_id.spine - 1) && (chunk = $(row_id.prefix + x))) {
406                             if (x > 0) {
407                                 new_label += ' ' + chunk.value;
408                             } else {
409                                 new_label = chunk.value;
410                             }
411                             x++;
412                         }
413
414                         if (chunk = $(row_id.prefix + x)) {
415                             new_label += chunk.value;
416                             x++;
417                         }
418
419                         while (chunk = $(row_id.prefix + x)) {
420                             new_label += ' ' + chunk.value;
421                             x++;
422                         }
423                         generate({"acn": row_id.acn, "label": new_label});
424                         $(row_id.prefix + row_id.spine).focus();
425                     }
426                     if (sel_start == 0) {
427                         /* Move to the previous row */
428                         var prev_row = $(row_id.prefix + (parseInt(row_id.spine) - 1));
429                         if (prev_row) {
430                             prev_row.focus();
431                         }
432                     }
433                     break;
434                 }
435
436                 case dojo.keys.DELETE : {
437                     /* Delete line if at the end of an input box */
438                     if (sel_start == event.target.textLength) {
439                         var new_label = '';
440                         var chunk;
441                         var x = 0;
442                         while (x <= row_id.spine && (chunk = $(row_id.prefix + x))) {
443                             if (x > 0) {
444                                 new_label += ' ' + chunk.value;
445                             } else {
446                                 new_label = chunk.value;
447                             }
448                             x++;
449                         }
450
451                         if (chunk = $(row_id.prefix + x)) {
452                             new_label += chunk.value;
453                             x++;
454                         }
455
456                         while (chunk = $(row_id.prefix + x)) {
457                             new_label += ' ' + chunk.value;
458                             x++;
459                         }
460                         generate({"acn": row_id.acn, "label": new_label});
461                         $(row_id.prefix + row_id.spine).focus();
462                     }
463                     break;
464                 }
465
466                 case dojo.keys.UP_ARROW : {
467                     /* Move to the previous row */
468                     var prev_row = $(row_id.prefix + (parseInt(row_id.spine) - 1));
469                     if (prev_row) {
470                         prev_row.focus();
471                     }
472                     break;
473                 }
474
475                 case dojo.keys.DOWN_ARROW : {
476                     /* Move to the next row */
477                     var next_row = $(row_id.prefix + (parseInt(row_id.spine) + 1));
478                     if (next_row) {
479                         next_row.focus();
480                     }
481                     break;
482                 }
483
484                 default : {
485                     break;
486                 }
487             }
488         }
489
490         function expand_macros(text,copy,volume,record) {
491             var my = { 'acp' : copy, 'acn' : volume, 'mvr' : record };
492             var obj = { 'data' : g.data };
493             for (var i in g.col_map) {
494                 var re = g.col_map[i].regex;
495                 if (text.match(re)) {
496                     try {
497                         text = text.replace(re, (typeof g.col_map[i].render == 'function' ? g.col_map[i].render(my) : eval( g.col_map[i].render ) ) );
498                     } catch(E) {
499                         g.error.sdump('D_ERROR','spine_labels.js, expand_macros() = ' + E);
500                     }
501                 }
502             }
503             return text;
504         }
505
506         function preview(idx) {
507             try {
508                     var pt = Number( $('pt').value );  /* font size */
509                     if (!pt) {
510                         pt = g.data.hash.aous['cat.label.font.size'] || 10;
511                         $('pt').value = pt;
512                     }
513                     var ff = g.data.hash.aous['cat.label.font.family'] || 'monospace';
514                     var fw = $('font_weight').value;  /* font weight */
515                     if (!fw) {
516                         fw = g.data.hash.aous['cat.label.font.weight'] || 'normal';
517                     }
518                     var lm = Number($('lm').value); /* left margin */
519                     if (!lm) {
520                         lm = g.data.hash.aous['cat.spine.line.margin'] || 0;
521                     }
522                     var mm = Number($('mm').value); if (isNaN(mm)) mm = 2; /* middle margin */
523                     var lw = Number($('lw').value); /* spine label width */
524                     if (!lw) {
525                         lw = g.data.hash.aous['cat.spine.line.width'] || 8;
526                         $('lw').value = lw;
527                     }
528                     var ll = Number($('ll').value); /* spine label length */
529                     if (!ll) {
530                         ll = g.data.hash.aous['cat.spine.line.height'] || 9;
531                         $('ll').value = ll;
532                     }
533                     var plw = Number($('plw').value) || 28; var pll = Number($('pll').value) || 9; /* pocket label width and length */
534                     var html = "<html><head>";
535                     html += "<link type='text/css' rel='stylesheet' href='" + xulG.url_prefix('/xul/server/skin/print.css') + "'></link>"
536                     html += "<link type='text/css' rel='stylesheet' href='data:text/css,pre{font-family:" + ff + ";font-size:" + pt + "pt; font-weight: " + fw + ";}'></link>";
537                     html += "<title>Spine Labels</title></head><body>\n";
538                     var nl = document.getElementsByAttribute('name','template');
539                     for (var i = 0; i < nl.length; i++) {
540                         if (typeof idx == 'undefined' || idx == null) { } else {
541                             if (idx != i) continue;
542                         }
543                         var volume = g.volumes[ nl[i].getAttribute('acn_id') ];
544
545                         for (var j = 0; j < volume.copies().length; j++) {
546                             var copy = volume.copies()[j];
547                             if (i == 0 && j == 0) {
548                                 html += '<pre class="first_pre">\n';
549                             } else {
550                                 html += '<pre class="not_first_pre">\n';
551                             }
552                             var gb = nl[i].getElementsByTagName('groupbox')[0];
553                             var nl2 = gb.getElementsByAttribute('name','spine');
554                             for (var k = 0; k < nl2.length; k++) {
555                                 for (var m = 0; m < lm; m++) html += ' ';
556                                 html += util.text.preserve_string_in_html(expand_macros( nl2[k].value, copy, volume, volume.record() ).substr(0,lw));
557                                 if ($('pl').checked) {
558                                     var sib = nl2[k].nextSibling;
559                                     if (sib) {
560                                         for (var m = 0; m < lw - nl2[k].value.length; m++) html += ' ';
561                                         for (var m = 0; m < mm; m++) html += ' ';
562                                         html += util.text.preserve_string_in_html(expand_macros( sib.value, copy, volume, volume.record() ).substr(0,plw));
563                                     }
564                                 }
565                                 html += '\n';
566                             }
567                             html += '</pre hex="0C">\n';
568                         }
569                     }
570                     html += '</body></html>';
571
572                     /* From https://developer.mozilla.org/en/Using_nsIXULAppInfo */
573                     var appInfo = Components.classes["@mozilla.org/xre/app-info;1"]
574                                             .getService(Components.interfaces.nsIXULAppInfo);
575                     var platformVer = appInfo.platformVersion;
576
577                     /* We need to use different print strategies for different
578                      * XUL versions, apparently
579                      */
580                     if (platformVer.substr(0, 5) == '1.9.0') {
581                         preview_xul_190(html);
582                     } else {
583                         preview_xul_192(html);
584                     }
585
586
587             } catch(E) {
588                 g.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.spine_labels.preview.std_unexpected_err'),E);
589             }
590         }
591
592         function preview_xul_190(html) {
593             JSAN.use('util.window'); var win = new util.window();
594             var loc = ( urls.XUL_REMOTE_BROWSER );
595             var w = win.open( loc, 'spine_preview', 'chrome,resizable,width=750,height=550');
596             w.xulG = { 
597                 'url' : 'about:blank',
598                 'url_prefix' : function (u,s) { return xulG.url_prefix(u,s); },
599                 'show_print_button' : 1,
600                 'printer_context' : 'label',
601                 'alternate_print' : 1,
602                 'no_xulG' : 1,
603                 'title' : $("catStrings").getString('staff.cat.spine_labels.preview.title'),
604                 'on_url_load' : function(b) { 
605                     try { 
606                         if (typeof w.xulG.written == 'undefined') {
607                             w.xulG.written = true;
608                             w.g.browser.get_content().document.write(html);
609                             w.g.browser.get_content().document.close();
610                         }
611                     } catch(E) {
612                         alert(E);
613                     }
614                 }
615             };
616         }
617
618         function preview_xul_192(html) {
619             var loc = ( urls.XUL_BROWSER );
620             xulG.new_tab(
621                 loc,
622                 {
623                     'tab_name' : $("catStrings").getString('staff.cat.spine_labels.preview.title')
624                 },
625                 { 
626                     'url' : 'data:text/html;charset=utf-8,' + encodeURIComponent(html),
627                     'html_source' : html,
628                     'show_print_button' : 1,
629                     'printer_context' : 'label',
630                     'no_xulG' : 1
631                 }
632             );
633         }