From d006b21ca439937a2e1e01f2bd933974fb51c511 Mon Sep 17 00:00:00 2001 From: dbs Date: Wed, 23 Feb 2011 19:23:32 +0000 Subject: [PATCH] _really_ naive git-svn-id: svn://svn.open-ils.org/ILS-Contrib/conifer/branches/rel_1_6_1@1240 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- xul/server/cat/spine_labels.js | 296 ++++++++++++++++++++++++----------------- 1 file changed, 171 insertions(+), 125 deletions(-) diff --git a/xul/server/cat/spine_labels.js b/xul/server/cat/spine_labels.js index 16ca7c966d..209ad67953 100644 --- a/xul/server/cat/spine_labels.js +++ b/xul/server/cat/spine_labels.js @@ -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 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); - - 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 ); - } + 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 */ + + 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'); + + 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++; } - - idx++; + 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; + } } - } catch(E) { - g.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.spine_labels.generate.std_unexpeceted_err'),E); + + j++; } } -- 2.11.0