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