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

(-)a/C4/MarcModificationTemplates.pm (+8 lines)
Lines 32-37 use Koha::SimpleMARC qw( Link Here
32
    move_field
32
    move_field
33
    update_field
33
    update_field
34
);
34
);
35
use Koha::Biblios;
35
use Koha::MoreUtils;
36
use Koha::MoreUtils;
36
use Koha::DateUtils qw( dt_from_string );
37
use Koha::DateUtils qw( dt_from_string );
37
38
Lines 698-703 sub ModifyRecordWithTemplate { Link Here
698
                    field_numbers => $field_numbers,
699
                    field_numbers => $field_numbers,
699
                });
700
                });
700
            }
701
            }
702
            elsif ( $action eq 'set_record_source' ) {
703
                my $biblionumber = $record->subfield('999', 'c');
704
                return unless $biblionumber;
705
                my $biblio = Koha::Biblios->find($biblionumber);
706
                return unless $biblio;
707
                $biblio->metadata->set({record_source_id => $field_value})->store;
708
            }
701
        }
709
        }
702
    }
710
    }
703
711
(-)a/installer/data/mysql/atomicupdate/bug_36975.pl (+13 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
return {
4
    bug_number  => "36975",
5
    description => "Add set_record_source action to marc_modification_templates_action table",
6
    up          => sub {
7
        my ($args) = @_;
8
        my ( $dbh, $out ) = @$args{qw(dbh out)};
9
10
        $dbh->do(q{ALTER TABLE `marc_modification_template_actions` MODIFY COLUMN `action` enum('delete_field', 'add_field', 'update_field', 'move_field', 'copy_field', 'copy_and_replace_field', 'set_record_source') NOT NULL AFTER `ordering`;});
11
        say $out "Added new action type 'set_record_source'";
12
    },
13
};
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/marc_modification_templates.tt (-4 / +23 lines)
Lines 162-167 Link Here
162
162
163
                                            <td>[% ActionsLoo.ordering | html %]</td>
163
                                            <td>[% ActionsLoo.ordering | html %]</td>
164
                                            <td>
164
                                            <td>
165
                                            [% IF ( ActionsLoo.action_set_record_source ) %]
166
                                               <span>Set record source</span>
167
                                               <span>with value</span>
168
                                                   [% FOREACH source IN RecordSources %]
169
                                                      [% IF ( source.record_source_id == ActionsLoo.field_value ) %]
170
                                                         <em>[% source.name | html %]</em>
171
                                                      [% END %]
172
                                                   [% END %]
173
                                            [% ELSE %]
165
                                                [% IF ( ActionsLoo.action_delete_field ) %] <span>Delete</span> [% END %]
174
                                                [% IF ( ActionsLoo.action_delete_field ) %] <span>Delete</span> [% END %]
166
                                                [% IF ( ActionsLoo.action_add_field ) %] <span>Add new</span> [% END %]
175
                                                [% IF ( ActionsLoo.action_add_field ) %] <span>Add new</span> [% END %]
167
                                                [% IF ( ActionsLoo.action_update_field ) %] <span>Update existing or add new</span> [% END %]
176
                                                [% IF ( ActionsLoo.action_update_field ) %] <span>Update existing or add new</span> [% END %]
Lines 174-182 Link Here
174
                                                        <span>1st</span>
183
                                                        <span>1st</span>
175
                                                    [% END %]
184
                                                    [% END %]
176
                                                [% END %]
185
                                                [% END %]
177
186
                                                
178
                                                <span>field</span>
187
                                                <span>field</span>
179
188
                                                
180
                                                [% ActionsLoo.from_field | html %][% IF ( ActionsLoo.from_subfield.length ) %]$[% ActionsLoo.from_subfield | html %][% END %]
189
                                                [% ActionsLoo.from_field | html %][% IF ( ActionsLoo.from_subfield.length ) %]$[% ActionsLoo.from_subfield | html %][% END %]
181
190
182
                                                [% IF ( ActionsLoo.field_value ) %]
191
                                                [% IF ( ActionsLoo.field_value ) %]
Lines 190-196 Link Here
190
                                                        <span>using RegEx</span> s<strong>/[% ActionsLoo.to_regex_search | html %]/[% ActionsLoo.to_regex_replace | html %]/[% ActionsLoo.to_regex_modifiers | html %]</strong>
199
                                                        <span>using RegEx</span> s<strong>/[% ActionsLoo.to_regex_search | html %]/[% ActionsLoo.to_regex_replace | html %]/[% ActionsLoo.to_regex_modifiers | html %]</strong>
191
                                                    [% END %]
200
                                                    [% END %]
192
                                                [% END %]
201
                                                [% END %]
193
202
                                            [% END %]
194
                                                [% IF ( ActionsLoo.conditional ) %]
203
                                                [% IF ( ActionsLoo.conditional ) %]
195
                                                    [% IF ( ActionsLoo.conditional_if ) %] <span>if</span> [% END %]
204
                                                    [% IF ( ActionsLoo.conditional_if ) %] <span>if</span> [% END %]
196
                                                    [% IF ( ActionsLoo.conditional_unless ) %] <span>unless</span> [% END %]
205
                                                    [% IF ( ActionsLoo.conditional_unless ) %] <span>unless</span> [% END %]
Lines 244-249 Link Here
244
                                    <option value="move_field">Move</option>
253
                                    <option value="move_field">Move</option>
245
                                    <option value="copy_field">Copy</option>
254
                                    <option value="copy_field">Copy</option>
246
                                    <option value="copy_and_replace_field">Copy and replace</option>
255
                                    <option value="copy_and_replace_field">Copy and replace</option>
256
				    <option value="set_record_source">Set record source</option>
247
                                </select>
257
                                </select>
248
258
249
                                <span id="field_number_block">
259
                                <span id="field_number_block">
Lines 252-263 Link Here
252
                                        <option value="1">1st</option>
262
                                        <option value="1">1st</option>
253
                                    </select>
263
                                    </select>
254
                                </span>
264
                                </span>
255
265
				<span id="from_field_block">
256
                                field(s) <input type="text" name="from_field" id="from_field" size="3" maxlength="3" /> <input type="text" name="from_subfield" id="from_subfield" size="1" maxlength="1" title="let blank for the entire field" />
266
                                field(s) <input type="text" name="from_field" id="from_field" size="3" maxlength="3" /> <input type="text" name="from_subfield" id="from_subfield" size="1" maxlength="1" title="let blank for the entire field" />
267
				</span>
257
268
258
                                <span name="with_value_block" id="with_value_block" style="display:none;">
269
                                <span name="with_value_block" id="with_value_block" style="display:none;">
259
                                    with value <input type="text" name="field_value" id="field_value" />
270
                                    with value <input type="text" name="field_value" id="field_value" />
260
                                </span>
271
                                </span>
272
                                <span name="source_selector" id="source_selector" style="display:none;">
273
                                    <select id="record_source_id" name="record_source_id">
274
                                        <option value=''>No specified source</option>
275
                                        [% FOREACH source IN RecordSources %]
276
                                            <option value=[% source.record_source_id %]>[% source.name %]</option>
277
                                        [% END %]
278
                                    </select>
279
                                </span>
261
280
262
                                <span name="to_field_block" id="to_field_block" style="display:none;">
281
                                <span name="to_field_block" id="to_field_block" style="display:none;">
263
                                    to field <input type="text" name="to_field" id="to_field" size="3" maxlength="3" /> <input type="text" name="to_subfield" id="to_subfield" size="1" maxlength="1" title="let blank for the entire field" />
282
                                    to field <input type="text" name="to_field" id="to_field" size="3" maxlength="3" /> <input type="text" name="to_subfield" id="to_subfield" size="1" maxlength="1" title="let blank for the entire field" />
(-)a/koha-tmpl/intranet-tmpl/prog/js/marc_modification_templates.js (-1 / +9 lines)
Lines 38-44 $(document).ready(function() { Link Here
38
                return false;
38
                return false;
39
            }
39
            }
40
        }
40
        }
41
        if ( $("#from_field").val().length <= 0 ) {
41
        if ( action != 'set_record_source' && $("#from_field").val().length <= 0 ) {
42
            alert( __("The source field should be filled.") );
42
            alert( __("The source field should be filled.") );
43
            return false;
43
            return false;
44
        }
44
        }
Lines 172-177 function onActionChange(selectObj) { Link Here
172
            show('to_field_block');
172
            show('to_field_block');
173
            break;
173
            break;
174
174
175
        case 'set_record_source':
176
            hide('field_number_block');
177
            hide('from_field_block');
178
            hide('to_field_block');
179
            hide('with_value_block');
180
            show('source_selector');
181
            break;
182
175
    }
183
    }
176
}
184
}
177
185
(-)a/tools/marc_modification_templates.pl (-6 / +9 lines)
Lines 19-25 Link Here
19
use Modern::Perl;
19
use Modern::Perl;
20
20
21
use CGI qw ( -utf8 );
21
use CGI qw ( -utf8 );
22
22
use Koha::RecordSources;
23
use C4::Auth qw( get_template_and_user );
23
use C4::Auth qw( get_template_and_user );
24
use C4::Output qw( output_html_with_http_headers );
24
use C4::Output qw( output_html_with_http_headers );
25
use C4::MarcModificationTemplates qw(
25
use C4::MarcModificationTemplates qw(
Lines 75-82 if ( $op eq "cud-create_template" ) { Link Here
75
  my $conditional_value = $cgi->param('conditional_value');
75
  my $conditional_value = $cgi->param('conditional_value');
76
  my $conditional_regex = ( $cgi->param('conditional_regex') eq 'on' ) ? 1 : 0;
76
  my $conditional_regex = ( $cgi->param('conditional_regex') eq 'on' ) ? 1 : 0;
77
  my $description = $cgi->param('description');
77
  my $description = $cgi->param('description');
78
78
  $field_value = $cgi->param('record_source_id')
79
    if ($from_field) {
79
    if ($action eq 'set_record_source');
80
   
81
    if ($from_field or $action eq 'set_record_source') {
80
        unless ($mmta_id) {
82
        unless ($mmta_id) {
81
            AddModificationTemplateAction(
83
            AddModificationTemplateAction(
82
                $template_id,            $action,
84
                $template_id,            $action,
Lines 127-133 foreach my $action ( @actions ) { Link Here
127
  $action->{'action_move_field'} = ( $action->{'action'} eq 'move_field' );
129
  $action->{'action_move_field'} = ( $action->{'action'} eq 'move_field' );
128
  $action->{'action_copy_field'} = ( $action->{'action'} eq 'copy_field' );
130
  $action->{'action_copy_field'} = ( $action->{'action'} eq 'copy_field' );
129
  $action->{'action_copy_and_replace_field'} = ( $action->{'action'} eq 'copy_and_replace_field' );
131
  $action->{'action_copy_and_replace_field'} = ( $action->{'action'} eq 'copy_and_replace_field' );
130
132
  $action->{'action_set_record_source'} = ( $action->{'action'} eq 'set_record_source' );
131
  if( defined $action->{'conditional'} ){
133
  if( defined $action->{'conditional'} ){
132
      $action->{'conditional_if'} = ( $action->{'conditional'} eq 'if' );
134
      $action->{'conditional_if'} = ( $action->{'conditional'} eq 'if' );
133
      $action->{'conditional_unless'} = ( $action->{'conditional'} eq 'unless' );
135
      $action->{'conditional_unless'} = ( $action->{'conditional'} eq 'unless' );
Lines 141-150 foreach my $action ( @actions ) { Link Here
141
  }
143
  }
142
}
144
}
143
145
146
my $record_sources = Koha::RecordSources->search();
147
144
$template->param(
148
$template->param(
145
  TemplatesLoop => \@templates,
149
  TemplatesLoop => \@templates,
146
  ActionsLoop => \@actions,
150
  ActionsLoop => \@actions,
147
151
  RecordSources => $record_sources,
148
  template_id => $template_id,
152
  template_id => $template_id,
149
);
153
);
150
154
151
- 

Return to bug 36975