[open-ils-commits] r1242 - conifer/branches/rel_1_6_1/xul/server/cat (dbs)

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Feb 23 14:57:16 EST 2011


Author: dbs
Date: 2011-02-23 14:57:12 -0500 (Wed, 23 Feb 2011)
New Revision: 1242

Modified:
   conifer/branches/rel_1_6_1/xul/server/cat/spine_labels.js
Log:
Should have done this from the beginning for spine labels

Copy the whole thing from rel_1_6 and adjust the defaults by hand,
stripping out the few method calls that don't exist in 1.6.1


Modified: conifer/branches/rel_1_6_1/xul/server/cat/spine_labels.js
===================================================================
--- conifer/branches/rel_1_6_1/xul/server/cat/spine_labels.js	2011-02-23 19:25:01 UTC (rev 1241)
+++ conifer/branches/rel_1_6_1/xul/server/cat/spine_labels.js	2011-02-23 19:57:12 UTC (rev 1242)
@@ -33,11 +33,18 @@
                 for (var i = 0; i < g.barcodes.length; i++) {
                     var copy = g.network.simple_request( 'FM_ACP_RETRIEVE_VIA_BARCODE.authoritative', [ g.barcodes[i] ] );
                     if (typeof copy.ilsevent != 'undefined') throw(copy);
+                    var label_prefix = '';
+                    var label_suffix = '';
                     if (!g.volumes[ copy.call_number() ]) {
                         var volume = g.network.simple_request( 'FM_ACN_RETRIEVE.authoritative', [ copy.call_number() ] );
                         if (typeof volume.ilsevent != 'undefined') throw(volume);
                         var record = g.network.simple_request('MODS_SLIM_RECORD_RETRIEVE.authoritative', [ volume.record() ]);
                         volume.record( record );
+
+                        /* Jam the prefixes and suffixes into the volume object */
+                        volume.prefix = label_prefix;
+                        volume.suffix = label_suffix;
+
                         g.volumes[ volume.id() ] = volume;
                     }
                     if (g.volumes[ copy.call_number() ].copies()) {
@@ -67,18 +74,43 @@
             alert( util.functional.map_list( g.cols, function(o) { return '%' + o.id + '%'; } ).join(" ") );
         }
 
-        function $(id) { return document.getElementById(id); }
+        function $(id) { return dojo.byId(id); }
 
         function generate(override) {
             try {
                 var idx = 0;
-                JSAN.use('util.text'); JSAN.use('util.money');
-                JSAN.use('util.widgets'); util.widgets.remove_children('panel'); var pn = $('panel'); $('preview').disabled = false;
+                JSAN.use('util.text');
+                JSAN.use('util.money');
+                JSAN.use('util.widgets');
+                var pn = $('panel');
+                $('preview').disabled = false;
+
+                /* Grab from OU settings, then fall back to hardcoded defaults */
                 var label_cfg = {};
-                label_cfg.lw = Number($('lw').value) || 8; /* spine label width */
-                label_cfg.ll = Number($('ll').value) || 9; /* spine label length */
-                label_cfg.plw = Number($('plw').value) || 28; /* pocket label width */
-                label_cfg.pll = Number($('pll').value) || 9; /* pocket label length */
+                label_cfg.spine_width = Number($('lw').value); /* spine label width */
+                if (!label_cfg.spine_width) {
+                    label_cfg.spine_width = g.data.hash.aous['cat.spine.line.width'] || 8;
+                    $('lw').value = label_cfg.spine_width;
+                }
+                label_cfg.spine_length = Number($('ll').value); /* spine label length */
+                if (!label_cfg.spine_length) {
+                    label_cfg.spine_length = g.data.hash.aous['cat.spine.line.height'] || 9;
+                    $('ll').value = label_cfg.spine_length;
+                }
+                label_cfg.spine_left_margin = Number($('lm').value); /* left margin */
+                if (!label_cfg.spine_left_margin) {
+                    label_cfg.spine_left_margin = g.data.hash.aous['cat.spine.line.margin'] || 0;
+                    $('lm').value = label_cfg.spine_left_margin;
+                }
+                label_cfg.font_size = Number( $('pt').value );  /* font size */
+                if (!label_cfg.font_size) {
+                    label_cfg.font_size = g.data.hash.aous['cat.label.font.size'] || 10;
+                    $('pt').value = label_cfg.font_size;
+                }
+                label_cfg.font_family = g.data.hash.aous['cat.label.font.family'] || 'Arial, Helvetica, sans-serif';
+                label_cfg.font_weight = g.data.hash.aous['cat.label.font.weight'] || 'bold';
+                label_cfg.pocket_width = Number($('plw').value) || 28; /* pocket label width */
+                label_cfg.pocket_length = Number($('pll').value) || 9; /* pocket label length */
 
                 if (override) {
                     var gb = $('acn_' + g.volumes[override.acn].id());
@@ -86,21 +118,20 @@
                     generate_labels(g.volumes[override.acn], gb, label_cfg, override);
                 } else {
                     util.widgets.remove_children('panel');
-
                     for (var i in g.volumes) {
-                        var volume = g.volumes[i];
-                        var vb = document.createElement('vbox'); pn.appendChild(vb); vb.setAttribute('name','template'); vb.setAttribute('acn_id',g.volumes[i].id());
+                        var vb = document.createElement('vbox'); pn.appendChild(vb);
+                        vb.setAttribute('name','template');
+                        vb.setAttribute('acn_id',g.volumes[i].id());
                         var ds = document.createElement('description'); vb.appendChild(ds);
                         ds.appendChild( document.createTextNode( g.volumes[i].label() ) );
                         var ds2 = document.createElement('description'); vb.appendChild(ds2);
-                        ds2.appendChild( document.createTextNode( g.volumes[i].copies().length + (
+                        ds2.appendChild( document.createTextNode( g.volumes[i].copies().length + ' ' + (
                             g.volumes[i].copies().length == 1 ? $("catStrings").getString('staff.cat.spine_labels.copy') : $("catStrings").getString('staff.cat.spine_labels.copies')) ) );
                         ds2.setAttribute('style','color: green');
                         var hb = document.createElement('hbox'); vb.appendChild(hb);
 
                         var gb = document.createElement('groupbox');
                         hb.appendChild(gb); 
-
                         gb.setAttribute('id','acn_' + g.volumes[i].id());
                         gb.setAttribute('style','border: solid black 2px');
 
@@ -114,7 +145,7 @@
             }
         }
 
-        function generate_labels(volume, gb, label_cfg, override) {
+        function generate_labels(volume, label_node, label_cfg, override) {
             var names;
             var callnum;
 
@@ -143,25 +174,43 @@
                 }
             }
 
+            /* Only add the prefixes and suffixes once */
+            if (!override || volume.id() != override.acn) {
+                if (volume.prefix) {
+                    callnum = volume.prefix + ' ' + callnum;
+                }
+                if (volume.suffix) {
+                    callnum += ' ' + volume.suffix;
+                }
+            }
+
             names = callnum.split(/\s+/);
             var j = 0;
-            while (j < label_cfg.ll || j < label_cfg.pll) {
-                var hb2 = document.createElement('hbox'); gb.appendChild(hb2);
+            while (j < label_cfg.spine_length || j < label_cfg.pocket_length) {
+                var hb2 = document.createElement('hbox'); label_node.appendChild(hb2);
                 
                 /* spine */
-                if (j < label_cfg.ll) {
+                if (j < label_cfg.spine_length) {
                     var tb = document.createElement('textbox'); hb2.appendChild(tb); 
                     tb.value = '';
-                    tb.setAttribute('class','plain'); tb.setAttribute('style','font-family: Arial, Helvetica, sans-serif'); tb.setAttribute('font-weight','bold');
-                    tb.setAttribute('size',label_cfg.lw+1); tb.setAttribute('maxlength',label_cfg.lw);
+                    tb.setAttribute('class','plain');
+                    tb.setAttribute('style',
+                        'font-family: ' + label_cfg.font_family
+                        + '; font-size: ' + label_cfg.font_size
+                        + '; font-weight: ' + label_cfg.font_weight
+                    );
+                    tb.setAttribute('size',label_cfg.spine_width+1);
+                    tb.setAttribute('maxlength',label_cfg.spine_width);
                     tb.setAttribute('name','spine');
                     var spine_row_id = 'acn_' + volume.id() + '_spine_' + j;
                     tb.setAttribute('id',spine_row_id);
 
-                    var name = names.shift(); if (name) {
+                    var name = names.shift();
+                    if (name) {
                         name = String( name );
+
                         /* if the name is greater than the label width... */
-                        if (name.length > label_cfg.lw) {
+                        if (name.length > label_cfg.spine_width) {
                             /* then try to split it on periods */
                             var sname = name.split(/\./);
                             if (sname.length > 1) {
@@ -171,18 +220,18 @@
                                 /* and put all but the first one back into the names array */
                                 names = sname.slice(1).concat( names );
                                 /* if the name fragment is still greater than the label width... */
-                                if (sname[0].length > label_cfg.lw) {
+                                if (sname[0].length > label_cfg.spine_width) {
                                     /* then just truncate and throw the rest back into the names array */
-                                    tb.value = sname[0].substr(0,label_cfg.lw);
-                                    names = [ sname[0].substr(label_cfg.lw) ].concat( names );
+                                    tb.value = sname[0].substr(0,label_cfg.spine_width);
+                                    names = [ sname[0].substr(label_cfg.spine_width) ].concat( names );
                                 } else {
                                     /* otherwise we're set */
                                     tb.value = sname[0];
                                 }
                             } else {
                                 /* if we can't split on periods, then just truncate and throw the rest back into the names array */
-                                tb.value = name.substr(0,label_cfg.lw);
-                                names = [ name.substr(label_cfg.lw) ].concat( names );
+                                tb.value = name.substr(0,label_cfg.spine_width);
+                                names = [ name.substr(label_cfg.spine_width) ].concat( names );
                             }
                         } else {
                             /* otherwise we're set */
@@ -193,45 +242,50 @@
                 }
 
                 /* pocket */
-                if ($('pl').checked && j < label_cfg.pll) {
+                if ($('pl').checked && j < label_cfg.pocket_length) {
                     var tb2 = document.createElement('textbox'); hb2.appendChild(tb2); 
                     tb2.value = '';
-                    tb2.setAttribute('class','plain'); tb2.setAttribute('style','font-family: Arial, Helvetica, sans-serif'); tb2.setAttribute('font-weight','bold');
-                    tb2.setAttribute('size',label_cfg.plw+1); tb2.setAttribute('maxlength',label_cfg.plw);
+                    tb2.setAttribute('class','plain');
+                    tb2.setAttribute('style',
+                        'font-family: ' + label_cfg.font_family
+                        + '; font-size: ' + label_cfg.font_size
+                        + '; font-weight: ' + label_cfg.font_weight
+                    );
+                    tb2.setAttribute('size',label_cfg.pocket_width+1); tb2.setAttribute('maxlength',label_cfg.pocket_width);
                     tb2.setAttribute('name','pocket');
-                    if ($('title').checked && $('title_line').value == j + 1 && instanceOf(g.volumes[i].record(),mvr)) {
-                        if (g.volumes[i].record().title()) {
-                            tb2.value = util.text.wrap_on_space( g.volumes[i].record().title(), label_cfg.plw )[0];
+                    if ($('title').checked && $('title_line').value == j + 1 && instanceOf(volume.record(),mvr)) {
+                        if (volume.record().title()) {
+                            tb2.value = util.text.wrap_on_space( volume.record().title(), label_cfg.pocket_width )[0];
                         } else {
                             tb2.value = '';
                         }
                     }
-                    if ($('title_r').checked && $('title_r_line').value == j + 1 && instanceOf(g.volumes[i].record(),mvr)) {
-                        if (g.volumes[i].record().title()) {
-                            tb2.value = ( ($('title_r_indent').checked ? ' ' : '') + util.text.wrap_on_space( g.volumes[i].record().title(), label_cfg.plw )[1]).substr(0,label_cfg.plw);
+                    if ($('title_r').checked && $('title_r_line').value == j + 1 && instanceOf(volume.record(),mvr)) {
+                        if (volume.record().title()) {
+                            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);
                         } else {
                             tb2.value = '';
                         }
                     }
-                    if ($('author').checked && $('author_line').value == j + 1 && instanceOf(g.volumes[i].record(),mvr)) {
-                        if (g.volumes[i].record().author()) {
-                            tb2.value = g.volumes[i].record().author().substr(0,label_cfg.plw);
+                    if ($('author').checked && $('author_line').value == j + 1 && instanceOf(volume.record(),mvr)) {
+                        if (volume.record().author()) {
+                            tb2.value = volume.record().author().substr(0,label_cfg.pocket_width);
                         } else {
                             tb2.value = '';
                         }
                     }
                     if ($('call_number').checked && $('call_number_line').value == j + 1) {
-                        tb2.value = g.volumes[i].label().substr(0,label_cfg.plw);
+                        tb2.value = volume.label().substr(0,label_cfg.pocket_width);
                     }
                     if ($('owning_lib_shortname').checked && $('owning_lib_shortname_line').value == j + 1) {
-                        var lib = g.volumes[i].owning_lib();
+                        var lib = volume.owning_lib();
                         if (!instanceOf(lib,aou)) lib = g.data.hash.aou[ lib ];
-                        tb2.value = lib.shortname().substr(0,label_cfg.plw);
+                        tb2.value = lib.shortname().substr(0,label_cfg.pocket_width);
                     }
                     if ($('owning_lib').checked && $('owning_lib_line').value == j + 1) {
-                        var lib = g.volumes[i].owning_lib();
+                        var lib = volume.owning_lib();
                         if (!instanceOf(lib,aou)) lib = g.data.hash.aou[ lib ];
-                        tb2.value = lib.name().substr(0,label_cfg.plw);
+                        tb2.value = lib.name().substr(0,label_cfg.pocket_width);
                     }
                     if ($('shelving_location').checked && $('shelving_location_line').value == j + 1) {
                         tb2.value = '%location%';
@@ -411,7 +465,6 @@
             }
         }
 
-
         function expand_macros(text,copy,volume,record) {
             var my = { 'acp' : copy, 'acn' : volume, 'mvr' : record };
             var obj = { 'data' : g.data };
@@ -431,14 +484,35 @@
         function preview(idx) {
             try {
                     netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-                    var pt = Number( $('pt').value ) || 10;  /* font size */
-                    var lm = Number($('lm').value); if (lm == NaN) lm = 11; /* left margin */
+                    var pt = Number( $('pt').value );  /* font size */
+                    if (!pt) {
+                        pt = g.data.hash.aous['cat.label.font.size'] || 10;
+                        $('pt').value = pt;
+                    }
+                    var ff = g.data.hash.aous['cat.label.font.family'] || 'Arial, Helvetica, sans-serif';
+                    var fw = g.data.hash.aous['cat.label.font.weight'] || 'bold';
+                    if (!fw) {
+                        fw = g.data.hash.aous['cat.label.font.weight'] || 'bold';
+                    }
+                    var lm = Number($('lm').value); /* left margin */
+                    if (!lm) {
+                        lm = g.data.hash.aous['cat.spine.line.margin'] || 0;
+                    }
                     var mm = Number($('mm').value); if (mm == NaN) mm = 2; /* middle margin */
-                    var lw = Number($('lw').value) || 8; var ll = Number($('ll').value) || 9; /* spine label width and length */
+                    var lw = Number($('lw').value); /* spine label width */
+                    if (!lw) {
+                        lw = g.data.hash.aous['cat.spine.line.width'] || 8;
+                        $('lw').value = lw;
+                    }
+                    var ll = Number($('ll').value); /* spine label length */
+                    if (!ll) {
+                        ll = g.data.hash.aous['cat.spine.line.height'] || 9;
+                        $('ll').value = ll;
+                    }
                     var plw = Number($('plw').value) || 28; var pll = Number($('pll').value) || 9; /* pocket label width and length */
                     var html = "<html><head>";
-                    html += "<link type='text/css' rel='stylesheet' href='/xul/server/skin/print.css'></link>"
-                    html += "<link type='text/css' rel='stylesheet' href='data:text/css,pre{font-size:" + pt + "pt;}'></link>";
+                    html += "<link type='text/css' rel='stylesheet' href='" + xulG.url_prefix('/xul/server/skin/print.css') + "'></link>"
+                    html += "<link type='text/css' rel='stylesheet' href='data:text/css,pre{font-family:" + ff + ";font-size:" + pt + "pt; font-weight: " + fw + ";}'></link>";
                     html += "<title>Spine Labels</title></head><body>\n";
                     var nl = document.getElementsByAttribute('name','template');
                     for (var i = 0; i < nl.length; i++) {
@@ -449,7 +523,7 @@
 
                         for (var j = 0; j < volume.copies().length; j++) {
                             var copy = volume.copies()[j];
-                            if (i == 0) {
+                            if (i == 0 && j == 0) {
                                 html += '<pre class="first_pre">\n';
                             } else {
                                 html += '<pre class="not_first_pre">\n';
@@ -469,36 +543,69 @@
                                 }
                                 html += '\n';
                             }
-                            html += '</pre>\n';
+                            html += '</pre hex="0C">\n';
                         }
                     }
                     html += '</body></html>';
-                    JSAN.use('util.window'); var win = new util.window();
-                    var loc = ( urls.XUL_REMOTE_BROWSER );
-                    //+ '?url=' + window.escape('about:blank') + '&show_print_button=1&alternate_print=1&no_xulG=1&title=' + window.escape('Spine Labels');
-                    var w = win.open( loc, 'spine_preview', 'chrome,resizable,width=750,height=550');
-                    w.xulG = { 
-                        'url' : 'about:blank',
-                        'show_print_button' : 1,
-                        'alternate_print' : 1,
-                        'no_xulG' : 1,
-                        'title' : $("catStrings").getString('staff.cat.spine_labels.preview.title'),
-                        'on_url_load' : function(b) { 
-                            try { 
-                                netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-                                if (typeof w.xulG.written == 'undefined') {
-                                    w.xulG.written = true;
-                                    w.g.browser.get_content().document.write(html);
-                                    w.g.browser.get_content().document.close();
-                                }
-                            } catch(E) {
-                                alert(E);
-                            }
-                        }
-                    };
+
+                    /* From https://developer.mozilla.org/en/Using_nsIXULAppInfo */
+                    var appInfo = Components.classes["@mozilla.org/xre/app-info;1"]
+                                            .getService(Components.interfaces.nsIXULAppInfo);
+                    var platformVer = appInfo.platformVersion;
+
+                    /* We need to use different print strategies for different
+                     * XUL versions, apparently
+                     */
+                    if (platformVer.substr(0, 5) == '1.9.0') {
+                        preview_xul_190(html);
+                    } else {
+                        preview_xul_192(html);
+                    }
+
+
             } catch(E) {
                 g.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.spine_labels.preview.std_unexpected_err'),E);
             }
         }
 
+        function preview_xul_190(html) {
+            JSAN.use('util.window'); var win = new util.window();
+            var loc = ( urls.XUL_REMOTE_BROWSER );
+            //+ '?url=' + window.escape('about:blank') + '&show_print_button=1&alternate_print=1&no_xulG=1&title=' + window.escape('Spine Labels');
+            var w = win.open( loc, 'spine_preview', 'chrome,resizable,width=750,height=550');
+            w.xulG = { 
+                'url' : 'about:blank',
+                'show_print_button' : 1,
+                'alternate_print' : 1,
+                'no_xulG' : 1,
+                'title' : $("catStrings").getString('staff.cat.spine_labels.preview.title'),
+                'on_url_load' : function(b) { 
+                    try { 
+                        netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+                        if (typeof w.xulG.written == 'undefined') {
+                            w.xulG.written = true;
+                            w.g.browser.get_content().document.write(html);
+                            w.g.browser.get_content().document.close();
+                        }
+                    } catch(E) {
+                        alert(E);
+                    }
+                }
+            };
+        }
 
+        function preview_xul_192(html) {
+            var loc = ( urls.XUL_BROWSER );
+            xulG.new_tab(
+                loc,
+                {
+                    'tab_name' : $("catStrings").getString('staff.cat.spine_labels.preview.title')
+                },
+                { 
+                    'url' : 'data:text/html;charset=utf-8,'+window.escape(html),
+                    'html_source' : html,
+                    'show_print_button' : 1,
+                    'no_xulG' : 1
+                }
+            );
+        }



More information about the open-ils-commits mailing list