[open-ils-commits] r1240 - 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:23:36 EST 2011


Author: dbs
Date: 2011-02-23 14:23:32 -0500 (Wed, 23 Feb 2011)
New Revision: 1240

Modified:
   conifer/branches/rel_1_6_1/xul/server/cat/spine_labels.js
Log:
_really_ naive


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:08:33 UTC (rev 1239)
+++ conifer/branches/rel_1_6_1/xul/server/cat/spine_labels.js	2011-02-23 19:23:32 UTC (rev 1240)
@@ -69,145 +69,191 @@
 
         function $(id) { return document.getElementById(id); }
 
-        function generate() {
+        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;
-                var lw = Number($('lw').value) || 8; /* spine label width */
-                var ll = Number($('ll').value) || 9; /* spine label length */
-                var plw = Number($('plw').value) || 28; /* pocket label width */
-                var pll = Number($('pll').value) || 9; /* pocket label length */
-                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 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 + (
-                        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 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 */
 
-                    var gb = document.createElement('groupbox'); hb.appendChild(gb); 
-                    /* take the call number and split it on whitespace */
-                    var names = String(g.volumes[i].label()).split(/\s+/);
-                    var j = 0;
-                    while (j < ll || j < pll) {
-                        var hb2 = document.createElement('hbox'); gb.appendChild(hb2);
-                        
-                        /* spine */
-                        if (j < ll) {
-                            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',lw+1); tb.setAttribute('maxlength',lw);
-                            tb.setAttribute('name','spine');
-                            var spine_row_id = 'acn_' + volume.id() + '_spine_' + j;
-                            tb.setAttribute('id',spine_row_id);
+                if (override) {
+                    var gb = $('acn_' + g.volumes[override.acn].id());
+                    util.widgets.remove_children('acn_' + g.volumes[override.acn].id());
+                    generate_labels(g.volumes[override.acn], gb, label_cfg, override);
+                } else {
+                    util.widgets.remove_children('panel');
 
-                            var name = names.shift(); if (name) {
-                                name = String( name );
-                                /* if the name is greater than the label width... */
-                                if (name.length > lw) {
-                                    /* then try to split it on periods */
-                                    var sname = name.split(/\./);
-                                    if (sname.length > 1) {
-                                        /* if we can, then put the periods back in on each splitted element */
-                                        if (name.match(/^\./)) sname[0] = '.' + sname[0];
-                                        for (var k = 1; k < sname.length; k++) sname[k] = '.' + sname[k];
-                                        /* 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 > lw) {
-                                            /* then just truncate and throw the rest back into the names array */
-                                            tb.value = sname[0].substr(0,lw);
-                                            names = [ sname[0].substr(lw) ].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,lw);
-                                        names = [ name.substr(lw) ].concat( names );
-                                    }
+                    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 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 + (
+                            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');
+
+                        generate_labels(g.volumes[i], gb, label_cfg, override);
+
+                        idx++;
+                    }
+                }
+            } catch(E) {
+                g.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.spine_labels.generate.std_unexpeceted_err'),E);
+            }
+        }
+
+        function generate_labels(volume, label_node, label_cfg, override) {
+            var names;
+            var callnum;
+
+            if (override && volume.id() == override.acn) {
+                /* If we're calling ourself, we'll have an altered label */
+                callnum = String(override.label);
+            } else {
+                /* take the call number and split it on whitespace */
+                callnum = String(volume.label());
+            }
+
+            /* for LC, split between classification subclass letters and numbers */
+            var lc_class_re = /^([A-Z]{1,3})([0-9]+.*?)$/i;
+            var lc_class_match = lc_class_re.exec(callnum);
+            if (lc_class_match && lc_class_match.length > 1) {
+                callnum = lc_class_match[1] + ' ' + lc_class_match[2];
+            }
+
+            /* for LC, split between Cutter numbers */
+            var lc_cutter_re = /^(.*)(\.[A-Z]{1}[0-9]+.*?)$/ig;
+            var lc_cutter_match = lc_cutter_re.exec(callnum);
+            if (lc_cutter_match && lc_cutter_match.length > 1) {
+                callnum = '';
+                for (var i = 1; i < lc_cutter_match.length; i++) {
+                    callnum += lc_cutter_match[i] + ' ';
+                }
+            }
+
+            names = callnum.split(/\s+/);
+            var j = 0;
+            while (j < label_cfg.ll || j < label_cfg.pll) {
+                var hb2 = document.createElement('hbox'); gb.appendChild(hb2);
+                
+                /* spine */
+                if (j < label_cfg.ll) {
+                    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('name','spine');
+                    var spine_row_id = 'acn_' + volume.id() + '_spine_' + j;
+                    tb.setAttribute('id',spine_row_id);
+
+                    var name = names.shift(); if (name) {
+                        name = String( name );
+                        /* if the name is greater than the label width... */
+                        if (name.length > label_cfg.lw) {
+                            /* then try to split it on periods */
+                            var sname = name.split(/\./);
+                            if (sname.length > 1) {
+                                /* if we can, then put the periods back in on each splitted element */
+                                if (name.match(/^\./)) sname[0] = '.' + sname[0];
+                                for (var k = 1; k < sname.length; k++) sname[k] = '.' + sname[k];
+                                /* 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) {
+                                    /* 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 );
                                 } else {
                                     /* otherwise we're set */
-                                    tb.value = name;
+                                    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 );
                             }
-                            dojo.connect($(spine_row_id), 'onkeypress', 'spine_label_key_events');
+                        } else {
+                            /* otherwise we're set */
+                            tb.value = name;
                         }
+                    }
+                    dojo.connect($(spine_row_id), 'onkeypress', 'spine_label_key_events');
+                }
 
-                        /* pocket */
-                        if ($('pl').checked && j < pll) {
-                            var tb2 = document.createElement('textbox'); hb2.appendChild(tb2); 
+                /* pocket */
+                if ($('pl').checked && j < label_cfg.pll) {
+                    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('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];
+                        } else {
                             tb2.value = '';
-							tb2.setAttribute('class','plain'); tb2.setAttribute('style','font-family: Arial, Helvetica, sans-serif'); tb2.setAttribute('font-weight','bold');
-                            tb2.setAttribute('size',plw+1); tb2.setAttribute('maxlength',plw);
-                            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(), plw )[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(), plw )[1]).substr(0,plw);
-                                } 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,plw);
-                                } else {
-                                    tb2.value = '';
-                                }
-                            }
-                            if ($('call_number').checked && $('call_number_line').value == j + 1) {
-                                tb2.value = g.volumes[i].label().substr(0,plw);
-                            }
-                            if ($('owning_lib_shortname').checked && $('owning_lib_shortname_line').value == j + 1) {
-                                var lib = g.volumes[i].owning_lib();
-                                if (!instanceOf(lib,aou)) lib = g.data.hash.aou[ lib ];
-                                tb2.value = lib.shortname().substr(0,plw);
-                            }
-                            if ($('owning_lib').checked && $('owning_lib_line').value == j + 1) {
-                                var lib = g.volumes[i].owning_lib();
-                                if (!instanceOf(lib,aou)) lib = g.data.hash.aou[ lib ];
-                                tb2.value = lib.name().substr(0,plw);
-                            }
-                            if ($('shelving_location').checked && $('shelving_location_line').value == j + 1) {
-                                tb2.value = '%location%';
-                            }
-                            if ($('barcode').checked && $('barcode_line').value == j + 1) {
-                                tb2.value = '%barcode%';
-                            }
-                            if ($('custom1').checked && $('custom1_line').value == j + 1) {
-                                tb2.value = $('custom1_tb').value;
-                            }
-                            if ($('custom2').checked && $('custom2_line').value == j + 1) {
-                                tb2.value = $('custom2_tb').value;
-                            }
-                            if ($('custom3').checked && $('custom3_line').value == j + 1) {
-                                tb2.value = $('custom3_tb').value;
-                            }
-                            if ($('custom4').checked && $('custom4_line').value == j + 1) {
-                                tb2.value = $('custom4_tb').value;
-                            }
                         }
-
-                        j++;
                     }
+                    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);
+                        } 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);
+                        } else {
+                            tb2.value = '';
+                        }
+                    }
+                    if ($('call_number').checked && $('call_number_line').value == j + 1) {
+                        tb2.value = g.volumes[i].label().substr(0,label_cfg.plw);
+                    }
+                    if ($('owning_lib_shortname').checked && $('owning_lib_shortname_line').value == j + 1) {
+                        var lib = g.volumes[i].owning_lib();
+                        if (!instanceOf(lib,aou)) lib = g.data.hash.aou[ lib ];
+                        tb2.value = lib.shortname().substr(0,label_cfg.plw);
+                    }
+                    if ($('owning_lib').checked && $('owning_lib_line').value == j + 1) {
+                        var lib = g.volumes[i].owning_lib();
+                        if (!instanceOf(lib,aou)) lib = g.data.hash.aou[ lib ];
+                        tb2.value = lib.name().substr(0,label_cfg.plw);
+                    }
+                    if ($('shelving_location').checked && $('shelving_location_line').value == j + 1) {
+                        tb2.value = '%location%';
+                    }
+                    if ($('barcode').checked && $('barcode_line').value == j + 1) {
+                        tb2.value = '%barcode%';
+                    }
+                    if ($('custom1').checked && $('custom1_line').value == j + 1) {
+                        tb2.value = $('custom1_tb').value;
+                    }
+                    if ($('custom2').checked && $('custom2_line').value == j + 1) {
+                        tb2.value = $('custom2_tb').value;
+                    }
+                    if ($('custom3').checked && $('custom3_line').value == j + 1) {
+                        tb2.value = $('custom3_tb').value;
+                    }
+                    if ($('custom4').checked && $('custom4_line').value == j + 1) {
+                        tb2.value = $('custom4_tb').value;
+                    }
+                }
 
-                    idx++;
-                }
-            } catch(E) {
-                g.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.spine_labels.generate.std_unexpeceted_err'),E);
+                j++;
             }
         }
 



More information about the open-ils-commits mailing list