]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/cat/spine_labels.js
Add cointainer() and record_list() filters to QueryParser
[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             /* handle spine labels differently if using LC */
174             if (volume.label_class() == 3) {
175                 /* for LC, split between classification subclass letters and numbers */
176                 var lc_class_re = /^([A-Z]{1,3})([0-9]+.*?)$/i;
177                 var lc_class_match = lc_class_re.exec(callnum);
178                 if (lc_class_match && lc_class_match.length > 1) {
179                     callnum = lc_class_match[1] + ' ' + lc_class_match[2];
180                 }
181
182                 /* for LC, split between Cutter numbers */
183                 var lc_cutter_re = /^(.*)(\.[A-Z]{1}[0-9]+.*?)$/ig;
184                 var lc_cutter_match = lc_cutter_re.exec(callnum);
185                 if (lc_cutter_match && lc_cutter_match.length > 1) {
186                     callnum = '';
187                     for (var i = 1; i < lc_cutter_match.length; i++) {
188                         callnum += lc_cutter_match[i] + ' ';
189                     }
190                 }
191             }
192
193             /* Only add the prefixes and suffixes once */
194             if (!override || volume.id() != override.acn) {
195                 if (volume.prefix()) {
196                     callnum = volume.prefix() + ' ' + callnum;
197                 }
198                 if (volume.suffix()) {
199                     callnum += ' ' + volume.suffix();
200                 }
201             }
202
203             names = callnum.split(/\s+/);
204             var j = 0;
205             while (j < label_cfg.spine_length || j < label_cfg.pocket_length) {
206                 var hb2 = document.createElement('hbox'); label_node.appendChild(hb2);
207                 
208                 /* spine */
209                 if (j < label_cfg.spine_length) {
210                     var tb = document.createElement('textbox'); hb2.appendChild(tb); 
211                     tb.value = '';
212                     tb.setAttribute('class','plain');
213                     tb.setAttribute('style',
214                         'font-family: ' + label_cfg.font_family
215                         + '; font-size: ' + label_cfg.font_size
216                         + '; font-weight: ' + label_cfg.font_weight
217                     );
218                     tb.setAttribute('size',label_cfg.spine_width+1);
219                     tb.setAttribute('maxlength',label_cfg.spine_width);
220                     tb.setAttribute('name','spine');
221                     var spine_row_id = 'acn_' + volume.id() + '_spine_' + j;
222                     tb.setAttribute('id',spine_row_id);
223
224                     var name = names.shift();
225                     if (name) {
226                         name = String( name );
227
228                         /* if the name is greater than the label width... */
229                         if (name.length > label_cfg.spine_width) {
230                             /* then try to split it on periods */
231                             var sname = name.split(/\./);
232                             if (sname.length > 1) {
233                                 /* if we can, then put the periods back in on each splitted element */
234                                 if (name.match(/^\./)) sname[0] = '.' + sname[0];
235                                 for (var k = 1; k < sname.length; k++) sname[k] = '.' + sname[k];
236                                 /* and put all but the first one back into the names array */
237                                 names = sname.slice(1).concat( names );
238                                 /* if the name fragment is still greater than the label width... */
239                                 if (sname[0].length > label_cfg.spine_width) {
240                                     /* then just truncate and throw the rest back into the names array */
241                                     tb.value = sname[0].substr(0,label_cfg.spine_width);
242                                     names = [ sname[0].substr(label_cfg.spine_width) ].concat( names );
243                                 } else {
244                                     /* otherwise we're set */
245                                     tb.value = sname[0];
246                                 }
247                             } else {
248                                 /* if we can't split on periods, then just truncate and throw the rest back into the names array */
249                                 tb.value = name.substr(0,label_cfg.spine_width);
250                                 names = [ name.substr(label_cfg.spine_width) ].concat( names );
251                             }
252                         } else {
253                             /* otherwise we're set */
254                             tb.value = name;
255                         }
256                     }
257                     dojo.connect($(spine_row_id), 'onkeypress', 'spine_label_key_events');
258                 }
259
260                 /* pocket */
261                 if ($('pl').checked && j < label_cfg.pocket_length) {
262                     var tb2 = document.createElement('textbox'); hb2.appendChild(tb2); 
263                     tb2.value = '';
264                     tb2.setAttribute('class','plain');
265                     tb2.setAttribute('style',
266                         'font-family: ' + label_cfg.font_family
267                         + '; font-size: ' + label_cfg.font_size
268                         + '; font-weight: ' + label_cfg.font_weight
269                     );
270                     tb2.setAttribute('size',label_cfg.pocket_width+1); tb2.setAttribute('maxlength',label_cfg.pocket_width);
271                     tb2.setAttribute('name','pocket');
272                     if ($('title').checked && $('title_line').value == j + 1 && instanceOf(volume.record(),mvr)) {
273                         if (volume.record().title()) {
274                             tb2.value = util.text.wrap_on_space( volume.record().title(), label_cfg.pocket_width )[0];
275                         } else {
276                             tb2.value = '';
277                         }
278                     }
279                     if ($('title_r').checked && $('title_r_line').value == j + 1 && instanceOf(volume.record(),mvr)) {
280                         if (volume.record().title()) {
281                             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);
282                         } else {
283                             tb2.value = '';
284                         }
285                     }
286                     if ($('author').checked && $('author_line').value == j + 1 && instanceOf(volume.record(),mvr)) {
287                         if (volume.record().author()) {
288                             tb2.value = volume.record().author().substr(0,label_cfg.pocket_width);
289                         } else {
290                             tb2.value = '';
291                         }
292                     }
293                     if ($('call_number').checked && $('call_number_line').value == j + 1) {
294                         tb2.value = (
295                             (volume.prefix() + ' ' + volume.label() + ' ' + volume.suffix())
296                             .replace(/\s+$/,'')
297                             .replace(/^\s+/,'')
298                             .substr(0,label_cfg.pocket_width)
299                         );
300                     }
301                     if ($('owning_lib_shortname').checked && $('owning_lib_shortname_line').value == j + 1) {
302                         var lib = volume.owning_lib();
303                         if (!instanceOf(lib,aou)) lib = g.data.hash.aou[ lib ];
304                         tb2.value = lib.shortname().substr(0,label_cfg.pocket_width);
305                     }
306                     if ($('owning_lib').checked && $('owning_lib_line').value == j + 1) {
307                         var lib = volume.owning_lib();
308                         if (!instanceOf(lib,aou)) lib = g.data.hash.aou[ lib ];
309                         tb2.value = lib.name().substr(0,label_cfg.pocket_width);
310                     }
311                     if ($('shelving_location').checked && $('shelving_location_line').value == j + 1) {
312                         tb2.value = '%location%';
313                     }
314                     if ($('barcode').checked && $('barcode_line').value == j + 1) {
315                         tb2.value = '%barcode%';
316                     }
317                     if ($('custom1').checked && $('custom1_line').value == j + 1) {
318                         tb2.value = $('custom1_tb').value;
319                     }
320                     if ($('custom2').checked && $('custom2_line').value == j + 1) {
321                         tb2.value = $('custom2_tb').value;
322                     }
323                     if ($('custom3').checked && $('custom3_line').value == j + 1) {
324                         tb2.value = $('custom3_tb').value;
325                     }
326                     if ($('custom4').checked && $('custom4_line').value == j + 1) {
327                         tb2.value = $('custom4_tb').value;
328                     }
329                 }
330
331                 j++;
332             }
333         }
334
335         function spine_label_key_events (event) {
336
337             /* Current value of the inpux box */
338             var line_value = event.target.value;
339
340             /* Cursor positions */
341             var sel_start = event.target.selectionStart;
342             var sel_end = event.target.selectionEnd;
343
344             /* Identifiers for this row: "acn_ID_spine_ROW" */
345             var atts = event.target.id.split('_');
346             var row_id = {
347                 "acn": atts[1],
348                 "spine": atts[3],
349                 "prefix": 'acn_' + atts[1] + '_spine_'
350             };
351
352             switch (event.charOrCode) {
353                 case dojo.keys.ENTER : {
354                     /* Create a new row by inserting a space at the
355                      * current cursor point, then regenerating the
356                      * label
357                      */
358                     if (sel_start == sel_end) {
359                         if (sel_start == 0) {
360                             /* If the cursor is at the start of the line:
361                              * insert new line
362                              */
363                             line_value = ' ' + line_value;
364                         } else if (sel_start == line_value.length) {
365                             /* Special case if the cursor is at the end of the line:
366                              * move to next line
367                              */
368                             var next_row = $(row_id.prefix + (parseInt(row_id.spine) + 1));
369                             if (next_row) {
370                                 next_row.focus();
371                             }
372                             break;
373                         } else {
374                             line_value = line_value.substr(0, sel_start) + ' ' + line_value.substr(sel_end);
375                         }
376                     } else {
377                         line_value = line_value.substr(0, sel_start) + ' ' + line_value.substr(sel_end);
378                     }
379                     event.target.value = line_value;
380
381                     /* Recreate the label */
382                     var new_label = '';
383                     var chunk;
384                     var x = 0;
385                     while (chunk = $(row_id.prefix + x)) {
386                         if (x > 0) {
387                             new_label += ' ' + chunk.value;
388                         } else {
389                             new_label = chunk.value;
390                         }
391                         x++;
392                     }
393                     generate({"acn": row_id.acn, "label": new_label});
394                     $(row_id.prefix + row_id.spine).focus();
395                     break;
396                 }
397
398                 case dojo.keys.BACKSPACE : {
399                     /* Delete line if at the start of an input box */
400                     if (sel_start == 0 && sel_end == sel_start) {
401                         var new_label = '';
402                         var chunk;
403                         var x = 0;
404                         while (x <= (row_id.spine - 1) && (chunk = $(row_id.prefix + x))) {
405                             if (x > 0) {
406                                 new_label += ' ' + chunk.value;
407                             } else {
408                                 new_label = chunk.value;
409                             }
410                             x++;
411                         }
412
413                         if (chunk = $(row_id.prefix + x)) {
414                             new_label += chunk.value;
415                             x++;
416                         }
417
418                         while (chunk = $(row_id.prefix + x)) {
419                             new_label += ' ' + chunk.value;
420                             x++;
421                         }
422                         generate({"acn": row_id.acn, "label": new_label});
423                         $(row_id.prefix + row_id.spine).focus();
424                     }
425                     if (sel_start == 0) {
426                         /* Move to the previous row */
427                         var prev_row = $(row_id.prefix + (parseInt(row_id.spine) - 1));
428                         if (prev_row) {
429                             prev_row.focus();
430                         }
431                     }
432                     break;
433                 }
434
435                 case dojo.keys.DELETE : {
436                     /* Delete line if at the end of an input box */
437                     if (sel_start == event.target.textLength) {
438                         var new_label = '';
439                         var chunk;
440                         var x = 0;
441                         while (x <= row_id.spine && (chunk = $(row_id.prefix + x))) {
442                             if (x > 0) {
443                                 new_label += ' ' + chunk.value;
444                             } else {
445                                 new_label = chunk.value;
446                             }
447                             x++;
448                         }
449
450                         if (chunk = $(row_id.prefix + x)) {
451                             new_label += chunk.value;
452                             x++;
453                         }
454
455                         while (chunk = $(row_id.prefix + x)) {
456                             new_label += ' ' + chunk.value;
457                             x++;
458                         }
459                         generate({"acn": row_id.acn, "label": new_label});
460                         $(row_id.prefix + row_id.spine).focus();
461                     }
462                     break;
463                 }
464
465                 case dojo.keys.UP_ARROW : {
466                     /* Move to the previous row */
467                     var prev_row = $(row_id.prefix + (parseInt(row_id.spine) - 1));
468                     if (prev_row) {
469                         prev_row.focus();
470                     }
471                     break;
472                 }
473
474                 case dojo.keys.DOWN_ARROW : {
475                     /* Move to the next row */
476                     var next_row = $(row_id.prefix + (parseInt(row_id.spine) + 1));
477                     if (next_row) {
478                         next_row.focus();
479                     }
480                     break;
481                 }
482
483                 default : {
484                     break;
485                 }
486             }
487         }
488
489         function expand_macros(text,copy,volume,record) {
490             var my = { 'acp' : copy, 'acn' : volume, 'mvr' : record };
491             var obj = { 'data' : g.data };
492             for (var i in g.col_map) {
493                 var re = g.col_map[i].regex;
494                 if (text.match(re)) {
495                     try {
496                         text = text.replace(re, (typeof g.col_map[i].render == 'function' ? g.col_map[i].render(my) : eval( g.col_map[i].render ) ) );
497                     } catch(E) {
498                         g.error.sdump('D_ERROR','spine_labels.js, expand_macros() = ' + E);
499                     }
500                 }
501             }
502             return text;
503         }
504
505         function preview(idx) {
506             try {
507                     netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
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 (mm == NaN) 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             //+ '?url=' + window.escape('about:blank') + '&show_print_button=1&alternate_print=1&no_xulG=1&title=' + window.escape('Spine Labels');
596             var w = win.open( loc, 'spine_preview', 'chrome,resizable,width=750,height=550');
597             w.xulG = { 
598                 'url' : 'about:blank',
599                 'url_prefix' : function (u) { return xulG.url_prefix(u); },
600                 'show_print_button' : 1,
601                 'printer_context' : 'label',
602                 'alternate_print' : 1,
603                 'no_xulG' : 1,
604                 'title' : $("catStrings").getString('staff.cat.spine_labels.preview.title'),
605                 'on_url_load' : function(b) { 
606                     try { 
607                         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
608                         if (typeof w.xulG.written == 'undefined') {
609                             w.xulG.written = true;
610                             w.g.browser.get_content().document.write(html);
611                             w.g.browser.get_content().document.close();
612                         }
613                     } catch(E) {
614                         alert(E);
615                     }
616                 }
617             };
618         }
619
620         function preview_xul_192(html) {
621             var loc = ( urls.XUL_BROWSER );
622             xulG.new_tab(
623                 loc,
624                 {
625                     'tab_name' : $("catStrings").getString('staff.cat.spine_labels.preview.title')
626                 },
627                 { 
628                     'url' : 'data:text/html;charset=utf-8,'+window.escape(html),
629                     'html_source' : html,
630                     'show_print_button' : 1,
631                     'printer_context' : 'label',
632                     'no_xulG' : 1
633                 }
634             );
635         }