View | Details | Raw Unified | Return to bug 6318
Collapse All | Expand All

(-)a/C4/Creators/Layout.pm (-1 / +2 lines)
Lines 61-66 sub _check_params { Link Here
61
    return $exit_code;
61
    return $exit_code;
62
}
62
}
63
63
64
use constant PRESET_FIELDS => [qw(title author isbn issn itemtype barcode callnumber)];
64
sub new {
65
sub new {
65
    my $invocant = shift;
66
    my $invocant = shift;
66
    my $self = '';
67
    my $self = '';
Lines 81-87 sub new { Link Here
81
            font_size       =>      3,
82
            font_size       =>      3,
82
            callnum_split   =>      0,
83
            callnum_split   =>      0,
83
            text_justify    =>      'L',
84
            text_justify    =>      'L',
84
            format_string   =>      'title, author, isbn, issn, itemtype, barcode, callnumber',
85
            format_string   =>      join(', ', @{ PRESET_FIELDS() }),
85
            @_,
86
            @_,
86
        };
87
        };
87
    }
88
    }
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-layout.tt (-15 / +13 lines)
Lines 75-99 Link Here
75
                                        <input type="radio" name="layout_choice" id="layout_choice_order" value="layout_table" /><label for="layout_choice_order">Choose Order Of Text Fields to Print</label>
75
                                        <input type="radio" name="layout_choice" id="layout_choice_order" value="layout_table" /><label for="layout_choice_order">Choose Order Of Text Fields to Print</label>
76
                                        [% END %]
76
                                        [% END %]
77
												<div id="layout_table">
77
												<div id="layout_table">
78
                                                    [% FOREACH field_tabl IN field_table %]
79
                                                    <p>
78
                                                    <p>
80
                                                        [% FOREACH text_field IN field_tabl.text_fields %]
79
                                            [% FOREACH text_field IN fields %]
81
                                                        [% IF ( text_field.field_empty ) %]
80
                                                        <select name="[% text_field.field_name %]" id="[% text_field.field_name |url %]">
82
                                                        [% ELSE %]
81
                                                            <option value=""></option>
83
                                                            <select name="[% text_field.field_name %]" id="[% text_field.field_name |url %]">
82
                                                            [% FOREACH orde IN [1..field_count] %]
84
                                                                [% FOREACH orde IN text_field.order %]
83
                                                                [% IF ( orde == text_field.order ) %]
85
                                                                [% IF ( orde.selected ) %]
84
                                                            <option value="[% orde %]" selected="1">[% orde %]</option>
86
                                                                <option value="[% orde.num %]" selected="selected">[% orde.num %]</option>
87
                                                                [% ELSE %]
85
                                                                [% ELSE %]
88
                                                                <option value="[% orde.num %]">[% orde.num %]</option>
86
                                                            <option value="[% orde %]">[% orde %]</option>
89
                                                                [% END %]
87
                                                                [% END %]
90
                                                                [% END %]
88
                                                            [% END %]
91
                                                            </select>
89
                                                        </select>&nbsp;<label for="[% text_field.field_name |url %]">[% text_field.field_label %]</label>
92
                                                            <label for="[% text_field.field_name |url %]">[% text_field.field_label %]</label>
90
93
                                                        [% END %]
91
                                                        &nbsp;&nbsp;
94
                                                        [% END %]
92
93
                                            [% END %]
95
                                                    </p>
94
                                                    </p>
96
                                                    [% END %]
97
											</div>
95
											</div>
98
                                            </li>
96
                                            </li>
99
                                            [% UNLESS ( layout_string ) %]
97
                                            [% UNLESS ( layout_string ) %]
(-)a/labels/label-edit-layout.pl (-40 / +21 lines)
Lines 23-29 use warnings; Link Here
23
23
24
use CGI;
24
use CGI;
25
use POSIX;
25
use POSIX;
26
use Text::CSV_XS;
27
26
28
use C4::Auth qw(get_template_and_user);
27
use C4::Auth qw(get_template_and_user);
29
use C4::Output qw(output_html_with_http_headers);
28
use C4::Output qw(output_html_with_http_headers);
Lines 66-105 sub _set_selected { Link Here
66
65
67
sub _select_format_string {     # generate field table based on format_string
66
sub _select_format_string {     # generate field table based on format_string
68
    my $format_string = shift;
67
    my $format_string = shift;
69
    $format_string =~ s/(?<=,) (?![A-Z][a-z][0-9])//g;  # remove spaces between fields
68
70
    my $table = [];
69
    my @text_fields = grep /\w/, split /\s*,\s/, $format_string;
71
    my $fields = [];
70
    my %tf = map {$_ => 1} @text_fields;
72
    my ($row_index, $col_index, $field_index) = (0,0,0);
71
    my @missing_fields = grep { !$tf{$_} } @{ C4::Labels::Layout->PRESET_FIELDS };
73
    my $cols = 5;       # number of columns to wrap on
72
74
    my $csv = Text::CSV_XS->new({ allow_whitespace => 1 });
73
    my $field_count = scalar(@text_fields) + scalar( @missing_fields);
75
    my $status = $csv->parse($format_string);
74
76
    my @text_fields = $csv->fields();
75
    my @fields;
77
    warn sprintf('Error parsing format_string. Parser returned: %s', $csv->error_input()) if $csv->error_input();
76
    my $field_index = 1;
78
    my $field_count = $#text_fields + 1;
77
    foreach my $f (@text_fields) {
79
    POPULATE_TABLE:
78
        push @fields, {field_name => ($f . "_tbl"), field_label => $f, order => $field_index};
80
    foreach my $text_field (@text_fields) {
81
        $$fields[$col_index] = {field_empty => 0, field_name => ($text_field . "_tbl"), field_label => $text_field, order => [{num => '', selected => 0}]};
82
        for (my $order_i = 1; $order_i <= $field_count; $order_i++) {
83
            $$fields[$col_index]{'order'}[$order_i] = {num => $order_i, selected => ($field_index == $order_i-1 ? 1 : 0)};
84
        }
85
        $col_index++;
86
        $field_index++;
79
        $field_index++;
87
        if ((($col_index > 0) && !($col_index % $cols)) || ($field_index == $field_count)) {    # wrap to new row
88
            if (($field_index == $field_count) && ($row_index > 0)) { # in this case fill out row with empty fields
89
                while ($col_index < $cols) {
90
                    $$fields[$col_index] = {field_empty => 1, field_name => '', field_label => '', order => [{num => '', selected => 0}]};
91
                    $col_index++;
92
                }
93
                $$table[$row_index] = {text_fields => $fields};
94
                last POPULATE_TABLE;
95
            }
96
            $$table[$row_index] = {text_fields => $fields};
97
            $row_index++;
98
            $fields = [];
99
            $col_index = 0;
100
        }
101
    }
80
    }
102
    return $table;
81
    foreach my $f (@missing_fields) {
82
        push @fields, {field_name => ($f . "_tbl"), field_label => $f};
83
    }
84
    return (\@fields, $field_count);
103
}
85
}
104
86
105
if ($op eq 'edit') {
87
if ($op eq 'edit') {
Lines 110-124 if ($op eq 'edit') { Link Here
110
elsif  ($op eq 'save') {
92
elsif  ($op eq 'save') {
111
    my $format_string = '';
93
    my $format_string = '';
112
    if ($layout_choice eq 'layout_table') {       # translate the field table into a format_string
94
    if ($layout_choice eq 'layout_table') {       # translate the field table into a format_string
113
        my @layout_table = ();
95
        my %layout_table;
114
        foreach my $cgi_param ($cgi->param()) {
96
        foreach my $cgi_param ($cgi->param()) {
115
            if (($cgi_param =~ m/^(.*)_tbl$/) && ($cgi->param($cgi_param))) {
97
            if (($cgi_param =~ m/^(.*)_tbl$/) && ($cgi->param($cgi_param))) {
116
                my $value = $cgi->param($cgi_param);
98
                my $value = $cgi->param($cgi_param);
117
                $layout_table[$value - 1] = $1;
99
                $layout_table{$1} = $value;
118
            }
100
            }
119
        }
101
        }
120
        @layout_table = grep {$_} @layout_table;        # this removes numerically 'skipped' fields. ie. user omits a number in sequential order
102
        $format_string = join ', ', sort { $layout_table{$a} <=> $layout_table{$b} } keys %layout_table;
121
        $format_string = join ', ', @layout_table;
122
        $cgi->param('format_string', $format_string);
103
        $cgi->param('format_string', $format_string);
123
    }
104
    }
124
    my @params = (
105
    my @params = (
Lines 152-165 my $barcode_types = _set_selected(get_barcode_types(), $layout, 'barcode_type'); Link Here
152
my $label_types = _set_selected(get_label_types(), $layout, 'printing_type');
133
my $label_types = _set_selected(get_label_types(), $layout, 'printing_type');
153
my $font_types = _set_selected(get_font_types(), $layout, 'font');
134
my $font_types = _set_selected(get_font_types(), $layout, 'font');
154
my $text_justification_types = _set_selected(get_text_justification_types(), $layout, 'text_justify');
135
my $text_justification_types = _set_selected(get_text_justification_types(), $layout, 'text_justify');
155
my $select_text_fields = _select_format_string($layout->get_attr('format_string'));
136
my ($select_text_fields, $select_text_fields_cnt) = _select_format_string($layout->get_attr('format_string'));
156
137
157
$template->param(
138
$template->param(
158
        barcode_types   => $barcode_types,
139
        barcode_types   => $barcode_types,
159
        label_types     => $label_types,
140
        label_types     => $label_types,
160
        font_types      => $font_types,
141
        font_types      => $font_types,
161
        text_justification_types    => $text_justification_types,
142
        text_justification_types    => $text_justification_types,
162
        field_table     => $select_text_fields,
143
        fields          => $select_text_fields,
144
        field_count     => $select_text_fields_cnt,
163
        layout_id       => $layout->get_attr('layout_id') > -1 ? $layout->get_attr('layout_id') : '',
145
        layout_id       => $layout->get_attr('layout_id') > -1 ? $layout->get_attr('layout_id') : '',
164
        layout_name     => $layout->get_attr('layout_name'),
146
        layout_name     => $layout->get_attr('layout_name'),
165
        guidebox        => $layout->get_attr('guidebox'),
147
        guidebox        => $layout->get_attr('guidebox'),
166
- 

Return to bug 6318