Final cleanup of labels for 3.0

This patch adds the callnum_split and text_justify options to the templates,
fixes bad javascript to switch between 'formatstring' and fixed-field means of specifying labels content,
fixes csv output when fixed-fields specifiers are used, and adds some help text for the formatstring case.

Signed-off-by: Joshua Ferraro <jmf@liblime.com>
This commit is contained in:
Ryan Higgins 2008-08-10 05:25:55 -05:00 committed by Joshua Ferraro
parent 9d0ab08a9b
commit 29d0c646f7
8 changed files with 112 additions and 88 deletions

View file

@ -509,8 +509,8 @@ sub add_layout {
my (
$barcodetype, $title, $subtitle, $isbn, $issn,
$itemtype, $bcn, $dcn, $classif,
$subclass, $itemcallnumber, $author, $tmpl_id,
$itemtype, $bcn, $text_justify, $callnum_split,
$itemcallnumber, $author, $tmpl_id,
$printingtype, $guidebox, $startlabel, $layoutname, $formatstring
) = @_;
@ -520,15 +520,15 @@ sub add_layout {
$sth2->execute();
$query2 = "INSERT INTO labels_conf
( barcodetype, title, subtitle, isbn,issn, itemtype, barcode,
dewey, classification, subclass, itemcallnumber, author, printingtype,
text_justify, callnum_split, itemcallnumber, author, printingtype,
guidebox, startlabel, layoutname, formatstring, active )
values ( ?, ?,?, ?, ?, ?, ?, ?, ?,?, ?, ?, ?, ?, ?,?,?, 1 )";
values ( ?, ?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?,?, 1 )";
$sth2 = $dbh->prepare($query2);
$sth2->execute(
$barcodetype, $title, $subtitle, $isbn, $issn,
$itemtype, $bcn, $dcn, $classif,
$subclass, $itemcallnumber, $author, $printingtype,
$itemtype, $bcn, $text_justify, $callnum_split,
$itemcallnumber, $author, $printingtype,
$guidebox, $startlabel, $layoutname, $formatstring
);
$sth2->finish;
@ -541,8 +541,8 @@ sub save_layout {
my (
$barcodetype, $title, $subtitle, $isbn, $issn,
$itemtype, $bcn, $dcn, $classif,
$subclass, $itemcallnumber, $author, $tmpl_id,
$itemtype, $bcn, $text_justify, $callnum_split,
$itemcallnumber, $author, $tmpl_id,
$printingtype, $guidebox, $startlabel, $layoutname, $formatstring,
$layout_id
) = @_;
@ -552,14 +552,14 @@ sub save_layout {
my $dbh = C4::Context->dbh;
my $query2 = "update labels_conf set
barcodetype=?, title=?, subtitle=?, isbn=?,issn=?,
itemtype=?, barcode=?, dewey=?, classification=?,
subclass=?, itemcallnumber=?, author=?, printingtype=?,
itemtype=?, barcode=?, text_justify=?, callnum_split=?,
itemcallnumber=?, author=?, printingtype=?,
guidebox=?, startlabel=?, layoutname=?, formatstring=? where id = ?";
my $sth2 = $dbh->prepare($query2);
$sth2->execute(
$barcodetype, $title, $subtitle, $isbn, $issn,
$itemtype, $bcn, $dcn, $classif,
$subclass, $itemcallnumber, $author, $printingtype,
$itemtype, $bcn, $text_justify, $callnum_split,
$itemcallnumber, $author, $printingtype,
$guidebox, $startlabel, $layoutname, $formatstring, $layout_id
);
$sth2->finish;
@ -812,6 +812,8 @@ and return string from koha tables or MARC record.
sub GetBarcodeData {
my ( $f, $item, $record ) = @_;
my $kohatables = &_descKohaTables();
use Data::Dumper;
warn Dumper($kohatables);
my $datastring = '';
my $match_kohatable = join(
'|',
@ -821,7 +823,7 @@ sub GetBarcodeData {
@{ $kohatables->{items} }
)
);
while ($f) {
while ($f) { warn $f;
$f =~ s/^\s?//;
if ( $f =~ /^'(.*)'.*/ ) {
# single quotes indicate a static text string.
@ -834,6 +836,7 @@ sub GetBarcodeData {
}
elsif ( $f =~ /^([0-9a-z]{3})(\w)(\W?).*?/ ) {
my $marc_field = $1;
$datastring .= $record->subfield($1,$2) . $3 if($record->subfield($1,$2)) ;
foreach my $subfield ($record->field($marc_field)) {
if ( $subfield->subfield('9') eq $item->{'itemnumber'} ) {
$datastring .= $subfield->subfield($2 ) . $3;
@ -843,6 +846,7 @@ sub GetBarcodeData {
$f = $';
}
else {
warn "failed to parse label formatstring: $f";
last; # Failed to match
}
}
@ -1009,7 +1013,7 @@ sub DrawSpineText {
my $vPos = ( $y_pos + ( $label_height - $top_text_margin ) );
my @str_fields = get_text_fields($layout_id, 'codes' );
my @str_fields = get_text_fields($layout_id, 'codes' );
my $record = GetMarcBiblio($$item->{biblionumber});
# FIXME - returns all items, so you can't get data from an embedded holdings field.
# TODO - add a GetMarcBiblio1item(bibnum,itemnum) or a GetMarcItem(itemnum).
@ -1018,15 +1022,15 @@ sub DrawSpineText {
# Grab the cn_source and if that is NULL, the DefaultClassificationSource syspref
my $cn_source = ($$item->{'cn_source'} ? $$item->{'cn_source'} : C4::Context->preference('DefaultClassificationSource'));
for my $field (@str_fields) {
$field->{'code'} or warn "get_text_fields($layout_id, 'codes') element missing 'code' field";
if ($$conf_data->{'formatstring'}) {
$field->{'data'} = GetBarcodeData($field->{'code'},$$item,$record) ;
}
elsif ($field->{'code'} eq 'itemtype') {
if ($field->{'code'} eq 'itemtype') {
$field->{'data'} = C4::Context->preference('item-level_itypes') ? $$item->{'itype'} : $$item->{'itemtype'};
}
elsif ($$conf_data->{'formatstring'}) {
# if labels_conf.formatstring has a value, then it overrides the hardcoded option.
$field->{'data'} = GetBarcodeData($field->{'code'},$$item,$record) ;
}
else {
$field->{data} = $$item->{$field->{'code'}} ;
}
@ -1044,8 +1048,8 @@ sub DrawSpineText {
$str =~ s/\n//g;
$str =~ s/\r//g;
my @strings;
my @callnumber_list = ('itemcallnumber', '050a', '050b', '082a', '952o'); # Fields which hold call number data
if ((grep {$field->{code} =~ m/$_/} @callnumber_list) and ($printingtype eq 'BIB')) { # If the field contains the call number, we do some sp
my @callnumber_list = ('itemcallnumber', '050a', '050b', '082a', '952o'); # Fields which hold call number data ( 060? 090? 092? 099? )
if ((grep {$field->{code} =~ m/$_/} @callnumber_list) and ($printingtype eq 'BIB') and ($$conf_data->{'callnum_split'})) { # If the field contains the call number, we do some sp
if ($cn_source eq 'lcc') {
@strings = split_lccn($str);
@strings = split_fcn($str) if !@strings; # If it was not a true lccn, try it as a fiction call number
@ -1080,12 +1084,14 @@ sub DrawSpineText {
# loop for each string line
foreach my $str (@strings) {
my $hPos = 0;
if ( $printingtype eq 'BIB' ) { #FIXME: This is a hack and needs to be implimented as a text justification option in the template...
# some code to try and center each line on the label based on font size and string point width...
my $stringwidth = prStrWidth($str, $fontname, $fontsize);
my $whitespace = ( $label_width - ( $stringwidth + (2 * $left_text_margin) ) );
$hPos = ( ( $whitespace / 2 ) + $x_pos + $left_text_margin );
#warn "\$label_width=$label_width \$stringwidth=$stringwidth \$whitespace=$whitespace \$left_text_margin=$left_text_margin for $str\n";
my $stringwidth = prStrWidth($str, $fontname, $fontsize);
if ( $$conf_data->{'text_justify'} eq 'R' ) {
$hPos = $x_pos + $label_width - ( $left_text_margin + $stringwidth );
} elsif($$conf_data->{'text_justify'} eq 'C') {
# some code to try and center each line on the label based on font size and string point width...
my $whitespace = ( $label_width - ( $stringwidth + (2 * $left_text_margin) ) );
$hPos = ( ( $whitespace / 2 ) + $x_pos + $left_text_margin );
#warn "\$label_width=$label_width \$stringwidth=$stringwidth \$whitespace=$whitespace \$left_text_margin=$left_text_margin for $str\n";
} else {
$hPos = ( $x_pos + $left_text_margin );
}

View file

@ -370,13 +370,14 @@ div.yui-b h5 {
}
dt {
font-size : 110%;
font-weight : bold;
}
dd {
padding : .2em;
text-indent : 1.5em;
font-size : 90%;
text-indent : 2.5em;
font-weight : normal;
}
div#toolbar {

View file

@ -38,7 +38,7 @@ onclick: {fn:function(){Plugin(<!-- TMPL_VAR NAME="batch_id" -->,"<!-- TMPL_VAR
<li><a id="deletebatch" href="/cgi-bin/koha/labels/label-manager.pl?op=delete_batch&amp;batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=<!-- TMPL_VAR NAME="batch_type" -->">Delete current batch</a></li>
<!-- FIXME: should use POST to change server state, not GET -->
<li><a id="dedup" href="/cgi-bin/koha/labels/label-manager.pl?op=deduplicate&amp;batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=<!-- TMPL_VAR NAME="batch_type" -->">Remove duplicates</a></li>
<li><a id="generate" href="/cgi-bin/koha/labels/label-print-pdf.pl?batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=<!-- TMPL_VAR NAME="batch_type" -->">Generate PDF for Batch</a></li>
<li><a id="generate" href="/cgi-bin/koha/labels/label-print-pdf.pl?batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=<!-- TMPL_VAR NAME="batch_type" -->">Generate labels for Batch</a></li>
</ul></div>
<!-- TMPL_ELSIF NAME="batch_is_patroncards" -->
<div id="toolbar">
@ -80,6 +80,6 @@ onclick: {fn:function(){Plugin(<!-- TMPL_VAR NAME="batch_id" -->,"<!-- TMPL_VAR
<li><a id="deletebatch" href="/cgi-bin/koha/labels/label-manager.pl?op=delete_batch&amp;batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=<!-- TMPL_VAR NAME="batch_type" -->">Delete current batch</a></li>
<!-- FIXME: should use POST to change server state, not GET -->
<li><a id="dedup" href="/cgi-bin/koha/labels/label-manager.pl?op=deduplicate&amp;batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=<!-- TMPL_VAR NAME="batch_type" -->">Remove duplicates</a></li>
<li><a id="generate" href="/cgi-bin/koha/labels/label-print-pdf.pl?batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=<!-- TMPL_VAR NAME="batch_type" -->">Generate PDF for Batch</a></li>
<li><a id="generate" href="/cgi-bin/koha/labels/label-print-pdf.pl?batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=<!-- TMPL_VAR NAME="batch_type" -->">Generate labels for Batch</a></li>
</ul></div>
<!-- /TMPL_IF -->

View file

@ -0,0 +1,23 @@
<!-- TMPL_INCLUDE NAME="help-top.inc" -->
<h1>Label Layouts</h1>
<h3>Bibliographic Data to Print</h3>
<p>This section determines what data will appear on the labels(s). Choose one of the following two methods of entry:</p>
<ul>
<li>Choose Order of Text Fields to Print</li>
Any of the data fields listed may be included in the label by selecting a numeric value from the dropdown selections. These values determine the order in which the data will print (one data field per line).
<li>List Fields</li>
<dl>Enter a comma-separated list of fields to include on the label. You may select :
<dt>any 'koha field'</dt>
<dd>These include any of the data fields that may be mapped to your MARC frameworks. See <em>Home Administration MARC Links</em> for valid kohafields. </dd>
<dt>MARC fields</dt>
<dd>Specify MARC subfields as a 4-character tag-subfield string, e.g. 254a </dd>
<dt>Concatenation of koha & MARC fields<dt>
<dd>Enclose a whitespace-separated list of fields to concatenate on one line in double quotes. e.g. "099a 099b" or "itemcallnumber copynumber"</dd>
<dt>Static text strings</dt>
<dd>May be entered in single-quotes, e.g. 'My Short-Name_of_Library'</dd>
</dl>
</ul>
<!-- TMPL_INCLUDE name="help-bottom.inc" -->

View file

@ -1,36 +1,19 @@
<!-- TMPL_INCLUDE NAME="doc-head-open.inc" --><title>Koha &rsaquo; Tools &rsaquo; Labels</title>
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
<script>
function jscss(action,o,c1,c2)
{
// from: http://onlinetools.org/articles/unobtrusivejavascript/cssjsseparation.html
switch (action){
case 'swap':
o.className=!jscss('check',o,c1)?o.className.replace(c2,c1): o.className.replace(c1,c2);
break;
case 'add':
if(!jscss('check',o,c1)){o.className+=o.className?' '+c1:c1;}
break;
case 'remove':
var rep=o.className.match(' '+c1)?' '+c1:c1;
o.className=o.className.replace(rep,'');
break;
case 'check':
return new RegExp('\\b'+c1+'\\b').test(o.className)
break;
}
}
function chooselayoutspec(rb) {
stringspec=document.getElementById("formatstring");
if(rb.value == 'layout_string') {
stringspec.disabled=0;
jscss('remove',document.getElementById('layout_string'),'disabled','');
jscss('add',document.getElementById('layout_tx'),'disabled','');
} else {
stringspec.disabled=1;
jscss('remove',document.getElementById('layout_tx'),'disabled','');
jscss('add',document.getElementById('layout_string'),'disabled','');
}
$(document).ready(function() {
$("input[@name='layoutchoice']").change( function() { layout_method() } );
layout_method();
});
function layout_method() {
if( $("input[@name='layoutchoice']:checked").val() == 'layout_string' ) {
$('#layout_tx').hide();
$('#layout_string').show();
} else {
$('#layout_tx').show();
$('#layout_string').hide();
}
}
</script>
</head>
@ -82,8 +65,9 @@ function chooselayoutspec(rb) {
<legend>
Bibliographic Data to Print
</legend>
<input type="radio" name="layoutchoice" value="layout_tx" <!-- TMPL_UNLESS NAME="layout_string" -->checked="checked"<!-- /TMPL_UNLESS --> onclick="chooselayoutspec(this);" >Choose Order Of Text Fields to Print</input>
<fieldset id="layout_tx" <!-- TMPL_IF NAME="layout_string" -->class="disabled"<!-- /TMPL_IF -->>
<input type="radio" name="layoutchoice" value="layout_tx" <!-- TMPL_UNLESS NAME="layout_string" -->checked="checked"<!-- /TMPL_UNLESS -->" >Choose Order Of Text Fields to Print</input>
<br />
<fieldset id="layout_tx">
<table summary="fields to print">
<tr>
<td>
@ -206,13 +190,14 @@ Bibliographic Data to Print
<td>&nbsp;</td>
</tr>
</table>
<br />
</fieldset>
<br />
<input type="radio" name="layoutchoice" value="layout_string" <!-- TMPL_IF NAME="layout_string" -->checked="checked"<!-- /TMPL_IF --> onclick="chooselayoutspec(this);"> List Fields </input>
<!-- TMPL_IF NAME="layout_string" --><fieldset id="layout_string"><!-- TMPL_ELSE --><fieldset id="layout_string" class="disabled"><!-- /TMPL_IF -->
<input type="radio" name="layoutchoice" value="layout_string" <!-- TMPL_IF NAME="formatstring" -->checked="checked"<!-- /TMPL_IF -->"> List Fields </input>
<fieldset id="layout_string" class="brief">
<label for="layoutname">Data Fields</label>
<!-- TMPL_IF NAME="layout_string" --><input type="text" name="formatstring" id="formatstring" size="60" value="<!-- TMPL_VAR NAME="formatstring" -->" /><!-- TMPL_ELSE --><input type="text" name="formatstring" id="formatstring" size="60" value="<!-- TMPL_VAR NAME="formatstring" -->" disabled="disabled" /><!-- /TMPL_IF -->
<input type="text" name="formatstring" id="formatstring" size="80" value="<!-- TMPL_VAR ESCAPE='HTML' NAME="formatstring" -->" />
<div class="help">
<p>Enter a comma separated list of fields to print. You may include any <em>Koha field</em> or MARC subfield.</p>
@ -232,6 +217,27 @@ Bibliographic Data to Print
<input type="checkbox" name="guidebox" id="guidebox" value="1" />
<!-- /TMPL_IF --></li>
<li><label for="callnum_split">Split Call Numbers</label>
<!-- TMPL_IF NAME="callnum_split"-->
<input type="checkbox" name="callnum_split" id="callnum_split" value="1" checked="checked" />
<!-- TMPL_ELSE -->
<input type="checkbox" name="callnum_split" id="callnum_split" value="1" />
<!-- /TMPL_IF --></li>
<li><label for="text_justify">Text Justification</label>
<select name="text_justify">
<!-- TMPL_IF NAME="justify_L" --><option value='L' selected="selected">Left</option>
<!-- TMPL_ELSE --><option value='L'>Left</option>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="justify_C" --><option value='C' selected="selected">Center</option>
<!-- TMPL_ELSE --><option value='C'>Center</option>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="justify_R" --><option value='R' selected="selected">Right</option>
<!-- TMPL_ELSE --><option value='R'>Right</option>
<!-- /TMPL_IF -->
</select>
</li>
</ol>
</fieldset>
<fieldset class="action">

View file

@ -61,7 +61,9 @@ $template->param(
layout_id => $layout_id,
guidebox => $guidebox,
startlabel => $startlabel,
formatstring => $layout->{'formatstring'},
callnum_split => $layout->{'callnum_split'},
'justify_' . $layout->{'text_justify'} => 1,
tx_title => \@title,
tx_subtitle => \@subtitle,
tx_author => \@author,

View file

@ -29,10 +29,7 @@ my $subtitle = $query->param('tx_subtitle');
my $isbn = $query->param('tx_isbn');
my $issn = $query->param('tx_issn');
my $itemtype = $query->param('tx_itemtype');
my $dcn = $query->param('tx_dewey');
my $classif = $query->param('tx_classif');
my $itemcallnumber = $query->param('tx_itemcallnumber');
my $subclass = $query->param('tx_subclass');
my $author = $query->param('tx_author');
my $tmpl_id = $query->param('tmpl_id');
my $summary = $query->param('summary');
@ -40,6 +37,8 @@ my $startlabel = $query->param('startlabel');
my $printingtype = $query->param('printingtype');
my $guidebox = $query->param('guidebox');
my $fontsize = $query->param('fontsize');
my $callnum_split = $query->param('callnum_split');
my $text_justify = $query->param('text_justify');
my $formatstring = $query->param('formatstring');
my $batch_type = $query->param('type');
($batch_type and $batch_type eq 'patroncards') or $batch_type = 'labels';
@ -74,22 +73,11 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
}
);
#if ( $op eq 'save_conf' ) { # this early sub is depreciated, use save_layout()
# SaveConf(
# $barcodetype, $title, $isbn,
# $issn, $itemtype, $bcn, $dcn,
# $classif, $subclass, $itemcallnumber, $author,
# $tmpl_id, $printingtype, $guidebox, $startlabel, $layoutname
# );
# print $query->redirect("label-home.pl");
# exit;
#}
#elsif ( $op eq 'save_layout' ) {
if ( $op eq 'save_layout' ) {
save_layout(
$barcodetype, $title, $subtitle, $isbn,
$issn, $itemtype, $bcn, $dcn,
$classif, $subclass, $itemcallnumber, $author,
$issn, $itemtype, $bcn, $text_justify,
$callnum_split, $itemcallnumber, $author,
$tmpl_id, $printingtype, $guidebox, $startlabel, $layoutname,
, $formatstring , $layout_id
);
@ -100,8 +88,8 @@ if ( $op eq 'save_layout' ) {
elsif ( $op eq 'add_layout' ) {
add_layout(
$barcodetype, $title, $subtitle, $isbn,
$issn, $itemtype, $bcn, $dcn,
$classif, $subclass, $itemcallnumber, $author,
$issn, $itemtype, $bcn, $text_justify,
$callnum_split, $itemcallnumber, $author,
$tmpl_id, $printingtype, $guidebox, $startlabel, $layoutname,
$formatstring , $layout_id
);

View file

@ -37,9 +37,7 @@ my $csv = Text::CSV_XS->new();
my @str_fields = get_text_fields($conf_data->{'id'}, 'codes' );
for my $item (@resultsloop) {
my $record = GetMarcBiblio($item->{biblionumber});
my @datafields = ($conf_data->{'formatstring'}) ?
map { C4::Labels::GetBarcodeData($_->{'code'},$item,$record) } @str_fields
: map { $_->{'code'} } @str_fields ;
my @datafields = map { C4::Labels::GetBarcodeData($_->{'code'},$item,$record) } @str_fields ;
my $csvout ;
if($csv->combine(@datafields)) {
$csvout = $csv->string();