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

(-)a/Koha/Object/Mixin/AdditionalFields.pm (+47 lines)
Lines 91-96 sub set_additional_fields { Link Here
91
    }
91
    }
92
}
92
}
93
93
94
=head3 add_additional_fields
95
96
Similar to set_additional_fields, but instead of overwriting existing fields, only adds new ones
97
98
    $foo->add_additional_fields(
99
        {
100
            '2' => [
101
                'first value for field 2',
102
                'second value for field 2'
103
            ],
104
            '1' => ['first value for field 1']
105
        },
106
        'subscription'
107
    );
108
109
=cut
110
111
sub add_additional_fields {
112
    my ( $self, $new_additional_fields, $tablename ) = @_;
113
114
    my @additional_fields;
115
116
    my $table_fields = Koha::AdditionalFields->search( { tablename => $tablename } );
117
    while ( my $field = $table_fields->next ) {
118
        my $new_additional_field_values = $new_additional_fields->{ $field->id };
119
120
        if ( $new_additional_field_values && scalar @{$new_additional_field_values} ) {
121
            foreach my $value ( @{$new_additional_field_values} ) {
122
                push @additional_fields, {
123
                    id    => $field->id,
124
                    value => $value,
125
                } if $value;
126
            }
127
        } else {
128
            my $existing_additional_field_values = $self->additional_field_values->search( { field_id => $field->id } );
129
            while ( my $existing = $existing_additional_field_values->next ) {
130
                push @additional_fields, {
131
                    id    => $field->id,
132
                    value => $existing->value,
133
                } if $existing && $existing->value;
134
            }
135
        }
136
    }
137
138
    $self->set_additional_fields( \@additional_fields );
139
}
140
94
=head3 get_additional_field_values_for_template
141
=head3 get_additional_field_values_for_template
95
142
96
Returns additional field values in the format expected by the .tt file
143
Returns additional field values in the format expected by the .tt file
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/additional-fields-entry.inc (-2 / +10 lines)
Lines 20-26 Link Here
20
                    [% END %]
20
                    [% END %]
21
                [% END %]
21
                [% END %]
22
                    [% IF !field.repeatable %]
22
                    [% IF !field.repeatable %]
23
                        <option value=""></option>
23
                        [% IF batch_edit %]
24
                            <option value="">No change</option>
25
                        [% ELSE %]
26
                            <option value=""></option>
27
                        [% END %]
24
                    [% END %]
28
                    [% END %]
25
                    [% IF authorised_value_category == 'branches' %]
29
                    [% IF authorised_value_category == 'branches' %]
26
                        [% FOREACH branch IN Branches.all() %]
30
                        [% FOREACH branch IN Branches.all() %]
Lines 108-114 Link Here
108
                [% IF !text_field_value_rendered %]
112
                [% IF !text_field_value_rendered %]
109
                    <li>
113
                    <li>
110
                    <label for="additional_field_[% field.id | html %]"> [% field.name | html %]: </label>
114
                    <label for="additional_field_[% field.id | html %]"> [% field.name | html %]: </label>
111
                    <input type="text" id="additional_field_[% field.id | html %]" name="additional_field_[% field.id | html %]" />
115
                    [% IF batch_edit %]
116
                        <input type="text" id="additional_field_[% field.id | html %]" name="additional_field_[% field.id | html %]" placeholder="No change" />
117
                    [% ELSE %]
118
                        <input type="text" id="additional_field_[% field.id | html %]" name="additional_field_[% field.id | html %]" />
119
                    [% END %]
112
                    [% UNLESS search_form == 1 %]
120
                    [% UNLESS search_form == 1 %]
113
                        <a href="#" class="clear_attribute"><i class="fa fa-fw fa-trash-can"></i> Clear</a>
121
                        <a href="#" class="clear_attribute"><i class="fa fa-fw fa-trash-can"></i> Clear</a>
114
                    [% END %]
122
                    [% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-batchedit.tt (-15 / +4 lines)
Lines 1-4 Link Here
1
[% USE raw %]
1
[% USE raw %]
2
[% USE Asset %]
2
[% USE AuthorisedValues %]
3
[% USE AuthorisedValues %]
3
[% USE Branches %]
4
[% USE Branches %]
4
[% USE ItemTypes %]
5
[% USE ItemTypes %]
Lines 141-160 Link Here
141
                                    <label for="enddate">Expiration date: </label>
142
                                    <label for="enddate">Expiration date: </label>
142
                                    <input type="text" class="flatpickr" id="enddate" name="enddate" placeholder="No change"/>
143
                                    <input type="text" class="flatpickr" id="enddate" name="enddate" placeholder="No change"/>
143
                                </li>
144
                                </li>
144
                                [% FOREACH field IN additional_fields %]
145
                                [% IF available_additional_fields.count %]
145
                                    <li>
146
                                    [% INCLUDE 'additional-fields-entry.inc' available=available_additional_fields values=additional_field_values batch_edit=1 %]
146
                                        <label for="field_[% field.id | html %]">[% field.name | html %]</label>
147
                                        [% IF field.authorised_value_category %]
148
                                            <select id="field_[% field.id | html %]" name="field_[% field.id | html %]">
149
                                                <option value="">No change</option>
150
                                                [% FOREACH av IN AuthorisedValues.Get(field.authorised_value_category) %]
151
                                                    <option value="[% av.authorised_value | html %]">[% av.lib | html %]</option>
152
                                                [% END %]
153
                                            </select>
154
                                        [% ELSE %]
155
                                            <input type="text" id="field_[% field.id | html %]" name="field_[% field.id | html %]" placeholder="No change"/>
156
                                        [% END %]
157
                                    </li>
158
                                [% END %]
147
                                [% END %]
159
                            </ol>
148
                            </ol>
160
                        </fieldset>
149
                        </fieldset>
Lines 175-179 Link Here
175
        </div> <!-- /.col-sm-2.col-sm-pull-10 -->
164
        </div> <!-- /.col-sm-2.col-sm-pull-10 -->
176
    </div> <!-- /.row -->
165
    </div> <!-- /.row -->
177
166
178
167
    [% Asset.js("js/additional-fields-entry.js") | $raw %]
179
    [% INCLUDE 'intranet-bottom.inc' %]
168
    [% INCLUDE 'intranet-bottom.inc' %]
(-)a/serials/subscription-batchedit.pl (-28 / +15 lines)
Lines 49-55 foreach my $subscriptionid (@subscriptionids) { Link Here
49
    push @subscriptions, $subscription if $subscription;
49
    push @subscriptions, $subscription if $subscription;
50
}
50
}
51
51
52
my @available_additional_fields = Koha::AdditionalFields->search( { tablename => 'subscription' } )->as_list;
52
my $available_additional_fields = Koha::AdditionalFields->search( { tablename => 'subscription' } );
53
53
54
my $batchedit = $cgi->param('batchedit');
54
my $batchedit = $cgi->param('batchedit');
55
if ($batchedit) {
55
if ($batchedit) {
Lines 65-73 if ($batchedit) { Link Here
65
    );
65
    );
66
66
67
    my $field_values = {};
67
    my $field_values = {};
68
    foreach my $field (@available_additional_fields) {
68
69
        my $value = $cgi->param( 'field_' . $field->id );
69
    while ( my $available_field = $available_additional_fields->next ) {
70
        $field_values->{ $field->id } = $value;
70
        my @submitted_fields = $cgi->param( 'additional_field_' . $available_field->id );
71
72
        my @submitted_fields_array;
73
        foreach my $submitted_field (@submitted_fields) {
74
            push @submitted_fields_array, $submitted_field if $submitted_field;
75
        }
76
        $field_values->{ $available_field->id } = \@submitted_fields_array;
71
    }
77
    }
72
78
73
    foreach my $subscription (@subscriptions) {
79
    foreach my $subscription (@subscriptions) {
Lines 80-104 if ($batchedit) { Link Here
80
            }
86
            }
81
        }
87
        }
82
88
83
        my @additional_field_values;
89
        $subscription->add_additional_fields($field_values, 'subscription');
84
        foreach my $field (@available_additional_fields) {
85
            my $value = $field_values->{ $field->id };
86
            if ( defined $value and $value ne '' ) {
87
                push @additional_field_values, {
88
                    id    => $field->id,
89
                    value => $value,
90
                };
91
            } else {
92
                my $existing = $subscription->additional_field_values->search( { field_id => $field->id } )->last;
93
                if ( $existing && $existing->value ) {
94
                    push @additional_field_values, {
95
                        id    => $field->id,
96
                        value => $existing->value,
97
                    };
98
                }
99
            }
100
        }
101
        $subscription->set_additional_fields( \@additional_field_values );
102
90
103
        $subscription->store;
91
        $subscription->store;
104
    }
92
    }
Lines 109-118 if ($batchedit) { Link Here
109
}
97
}
110
98
111
$template->param(
99
$template->param(
112
    subscriptions     => \@subscriptions,
100
    subscriptions               => \@subscriptions,
113
    booksellers       => [ Koha::Acquisition::Booksellers->search->as_list ],
101
    booksellers                 => [ Koha::Acquisition::Booksellers->search->as_list ],
114
    additional_fields => \@available_additional_fields,
102
    available_additional_fields => Koha::AdditionalFields->search( { tablename => 'subscription' } ),
115
    referrer          => scalar $cgi->param('referrer'),
103
    referrer                    => scalar $cgi->param('referrer'),
116
);
104
);
117
105
118
output_html_with_http_headers $cgi, $cookie, $template->output;
106
output_html_with_http_headers $cgi, $cookie, $template->output;
119
- 

Return to bug 35044