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

(-)a/C4/MarcModificationTemplates.pm (+9 lines)
Lines 639-644 sub ModifyRecordWithTemplate { Link Here
639
                    field_numbers => $field_numbers,
639
                    field_numbers => $field_numbers,
640
                });
640
                });
641
            }
641
            }
642
            elsif ( $action eq 'add_field' ) {
643
                add_field({
644
                    record => $record,
645
                    field => $from_field,
646
                    subfield => $from_subfield,
647
                    values => [ $field_value ],
648
                    field_numbers => $field_numbers,
649
                });
650
            }
642
            elsif ( $action eq 'update_field' ) {
651
            elsif ( $action eq 'update_field' ) {
643
                update_field({
652
                update_field({
644
                    record => $record,
653
                    record => $record,
(-)a/Koha/SimpleMARC.pm (+40 lines)
Lines 17-22 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); Link Here
17
17
18
our @EXPORT = qw(
18
our @EXPORT = qw(
19
  read_field
19
  read_field
20
  add_field
20
  update_field
21
  update_field
21
  copy_field
22
  copy_field
22
  copy_and_replace_field
23
  copy_and_replace_field
Lines 172-177 sub update_field { Link Here
172
    }
173
    }
173
}
174
}
174
175
176
=head2 add_field
177
178
  add_field({
179
      record   => $record,
180
      field    => $fieldName,
181
      subfield => $subfieldName,
182
      values   => \@values,
183
      field_numbers => $field_numbers,
184
  });
185
186
  Adds a new field/subfield with supplied value(s).
187
  This function always add a new field as opposed to 'update_field' which will
188
  either update if field exists and add if it does not.
189
190
=cut
191
192
193
sub add_field {
194
    my ( $params ) = @_;
195
    my $record = $params->{record};
196
    my $fieldName = $params->{field};
197
    my $subfieldName = $params->{subfield};
198
    my @values = @{ $params->{values} };
199
    my $field_numbers = $params->{field_numbers} // [];
200
201
    if ( ! ( $record && $fieldName ) ) { return; }
202
    if ( $fieldName > 10 ) {
203
        foreach my $value ( @values ) {
204
            my $field = MARC::Field->new( $fieldName, '', '', "$subfieldName" => $value );
205
            $record->append_fields( $field );
206
        }
207
    } else {
208
        foreach my $value ( @values ) {
209
            my $field = MARC::Field->new( $fieldName, $value );
210
            $record->append_fields( $field );
211
        }
212
    }
213
}
214
175
sub _update_field {
215
sub _update_field {
176
    my ( $params ) = @_;
216
    my ( $params ) = @_;
177
    my $record = $params->{record};
217
    my $record = $params->{record};
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/marc_modification_templates.tt (-2 / +4 lines)
Lines 116-122 Link Here
116
                                        <td>[% ActionsLoo.ordering %]</td>
116
                                        <td>[% ActionsLoo.ordering %]</td>
117
                                        <td>
117
                                        <td>
118
                                            [% IF ( ActionsLoo.action_delete_field ) %] Delete [% END %]
118
                                            [% IF ( ActionsLoo.action_delete_field ) %] Delete [% END %]
119
                                            [% IF ( ActionsLoo.action_update_field ) %] Update [% END %]
119
                                            [% IF ( ActionsLoo.action_add_field ) %] Add new [% END %]
120
                                            [% IF ( ActionsLoo.action_update_field ) %] Update existing or add new [% END %]
120
                                            [% IF ( ActionsLoo.action_move_field ) %] Move [% END %]
121
                                            [% IF ( ActionsLoo.action_move_field ) %] Move [% END %]
121
                                            [% IF ( ActionsLoo.action_copy_field ) %] Copy [% END %]
122
                                            [% IF ( ActionsLoo.action_copy_field ) %] Copy [% END %]
122
                                            [% IF ( ActionsLoo.action_copy_and_replace_field ) %] Copy and replace [% END %]
123
                                            [% IF ( ActionsLoo.action_copy_and_replace_field ) %] Copy and replace [% END %]
Lines 202-208 Link Here
202
203
203
                            <select name="action" id="action" onchange="onActionChange(this);">
204
                            <select name="action" id="action" onchange="onActionChange(this);">
204
                                <option value="delete_field">Delete</option>
205
                                <option value="delete_field">Delete</option>
205
                                <option value="update_field">Add/Update</option>
206
                                <option value="add_field">Add new</option>
207
                                <option value="update_field">Update existing or add new</option>
206
                                <option value="move_field">Move</option>
208
                                <option value="move_field">Move</option>
207
                                <option value="copy_field">Copy</option>
209
                                <option value="copy_field">Copy</option>
208
                                <option value="copy_and_replace_field">Copy and replace</option>
210
                                <option value="copy_and_replace_field">Copy and replace</option>
(-)a/koha-tmpl/intranet-tmpl/prog/js/marc_modification_templates.js (+6 lines)
Lines 105-110 function onActionChange(selectObj) { Link Here
105
            hide('to_field_block');
105
            hide('to_field_block');
106
            break;
106
            break;
107
107
108
        case 'add_field':
109
            hide('field_number_block');
110
            show('with_value_block');
111
            hide('to_field_block');
112
            break;
113
108
        case 'update_field':
114
        case 'update_field':
109
            hide('field_number_block');
115
            hide('field_number_block');
110
            show('with_value_block');
116
            show('with_value_block');
(-)a/tools/marc_modification_templates.pl (-1 / +1 lines)
Lines 116-121 my @templates = GetModificationTemplates( $template_id ); Link Here
116
my @actions = GetModificationTemplateActions( $template_id );
116
my @actions = GetModificationTemplateActions( $template_id );
117
foreach my $action ( @actions ) {
117
foreach my $action ( @actions ) {
118
  $action->{'action_delete_field'} = ( $action->{'action'} eq 'delete_field' );
118
  $action->{'action_delete_field'} = ( $action->{'action'} eq 'delete_field' );
119
  $action->{'action_add_field'} = ( $action->{'action'} eq 'add_field' );
119
  $action->{'action_update_field'} = ( $action->{'action'} eq 'update_field' );
120
  $action->{'action_update_field'} = ( $action->{'action'} eq 'update_field' );
120
  $action->{'action_move_field'} = ( $action->{'action'} eq 'move_field' );
121
  $action->{'action_move_field'} = ( $action->{'action'} eq 'move_field' );
121
  $action->{'action_copy_field'} = ( $action->{'action'} eq 'copy_field' );
122
  $action->{'action_copy_field'} = ( $action->{'action'} eq 'copy_field' );
122
- 

Return to bug 13560