From 29d0c646f706001408e5332e69c70559675a38bf Mon Sep 17 00:00:00 2001 From: Ryan Higgins Date: Sun, 10 Aug 2008 05:25:55 -0500 Subject: [PATCH] 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 --- C4/Labels.pm | 60 ++++++++------- .../prog/en/css/staff-global.css | 5 +- .../includes/tools-labels-batches-toolbar.inc | 4 +- .../help/labels/label-edit-layout.tmpl | 23 ++++++ .../en/modules/labels/label-edit-layout.tmpl | 76 ++++++++++--------- labels/label-edit-layout.pl | 4 +- labels/label-manager.pl | 24 ++---- labels/label-print-csv.pl | 4 +- 8 files changed, 112 insertions(+), 88 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/help/labels/label-edit-layout.tmpl diff --git a/C4/Labels.pm b/C4/Labels.pm index 050ee5dc4d..db0d2747b9 100644 --- a/C4/Labels.pm +++ b/C4/Labels.pm @@ -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 ); } diff --git a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css index 3dd136b286..3f825dc2bc 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css +++ b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css @@ -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 { diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-labels-batches-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/tools-labels-batches-toolbar.inc index 394d5a93e3..e560c2d508 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-labels-batches-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/tools-labels-batches-toolbar.inc @@ -38,7 +38,7 @@ onclick: {fn:function(){Plugin(,"&type=">Delete current batch
  • &type=">Remove duplicates
  • -
  • &type=">Generate PDF for Batch
  • +
  • &type=">Generate labels for Batch
  • @@ -80,6 +80,6 @@ onclick: {fn:function(){Plugin(,"&type=">Delete current batch
  • &type=">Remove duplicates
  • -
  • &type=">Generate PDF for Batch
  • +
  • &type=">Generate labels for Batch
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/help/labels/label-edit-layout.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/help/labels/label-edit-layout.tmpl new file mode 100644 index 0000000000..ebe5bc3f3e --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/help/labels/label-edit-layout.tmpl @@ -0,0 +1,23 @@ + + +

    Label Layouts

    + +

    Bibliographic Data to Print

    +

    This section determines what data will appear on the labels(s). Choose one of the following two methods of entry:

    + + + diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-layout.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-layout.tmpl index e0bea3d4cf..f3a178a548 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-layout.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-layout.tmpl @@ -1,36 +1,19 @@ Koha › Tools › Labels @@ -82,8 +65,9 @@ function chooselayoutspec(rb) { Bibliographic Data to Print -checked="checked" onclick="chooselayoutspec(this);" >Choose Order Of Text Fields to Print -
    class="disabled"> +checked="checked"" >Choose Order Of Text Fields to Print +
    +
    @@ -206,13 +190,14 @@ Bibliographic Data to Print  
    +

    -checked="checked" onclick="chooselayoutspec(this);"> List Fields -
    +checked="checked""> List Fields +
    -" />" disabled="disabled" /> +" />

    Enter a comma separated list of fields to print. You may include any Koha field or MARC subfield.

    @@ -232,6 +217,27 @@ Bibliographic Data to Print +
  • + + + + +
  • + +
  • + +
  • +
    diff --git a/labels/label-edit-layout.pl b/labels/label-edit-layout.pl index 299cd407ad..17ecd7244e 100755 --- a/labels/label-edit-layout.pl +++ b/labels/label-edit-layout.pl @@ -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, diff --git a/labels/label-manager.pl b/labels/label-manager.pl index 64f48db0e7..08432caa8c 100755 --- a/labels/label-manager.pl +++ b/labels/label-manager.pl @@ -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 ); diff --git a/labels/label-print-csv.pl b/labels/label-print-csv.pl index 36c9903e54..be29afa5a5 100755 --- a/labels/label-print-csv.pl +++ b/labels/label-print-csv.pl @@ -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(); -- 2.20.1