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

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt (+30 lines)
Lines 25-41 $(document).ready(function(){ Link Here
25
      var row = $(this).attr("id");
25
      var row = $(this).attr("id");
26
      row = row.replace("row","hint");
26
      row = row.replace("row","hint");
27
      var editor = $(this).parent().find("[name='field_value']");
27
      var editor = $(this).parent().find("[name='field_value']");
28
      var regex_input = $(this).parent().find("[name='field_regex']");
28
      if ($(this).is(":checked")) {
29
      if ($(this).is(":checked")) {
29
          $(editor).prop('disabled', true);
30
          $(editor).prop('disabled', true);
30
          $("#"+row).html(_("This subfield will be deleted"));
31
          $("#"+row).html(_("This subfield will be deleted"));
32
          $(regex_input).prop('disabled', true);
31
      } else {
33
      } else {
32
          $(editor).prop('disabled', false);
34
          $(editor).prop('disabled', false);
33
          $("#"+row).html("");
35
          $("#"+row).html("");
36
          $(regex_input).prop('disabled', false);
34
      }
37
      }
35
  });
38
  });
36
    $("#mainformsubmit").on("click",function(){
39
    $("#mainformsubmit").on("click",function(){
37
        return submitBackgroundJob(this.form);
40
        return submitBackgroundJob(this.form);
38
    });
41
    });
42
  $('input[name="field_regex"]').change(function() {
43
    var id = $(this).attr('id');
44
    var editor = $(this).parent().find("[name='field_value']");
45
    var regex = $(this).parent().find("[name='regex_fields']");
46
    var disable_input = $(this).parent().find("[name='disable_input']");
47
    if ($(this).is(':checked')) {
48
      $(editor).hide();
49
      $(regex).show();
50
      $(this).parent().find('.hint').html(_("Enter a regular expression for this subflied"));
51
      $(disable_input).prop('disabled', true);
52
    } else {
53
      $(editor).show();
54
      $(regex).hide();
55
      $(this).parent().find('.hint').html(_(""));
56
      $(disable_input).prop('disabled', false);
57
    }
58
  });
39
});
59
});
40
//]]>
60
//]]>
41
</script>
61
</script>
Lines 281-292 $(document).ready(function(){ Link Here
281
                <textarea tabindex="1" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor" size="50" maxlength="255">[%- mv.value | html -%]"</textarea>
301
                <textarea tabindex="1" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor" size="50" maxlength="255">[%- mv.value | html -%]"</textarea>
282
              [%- END -%]
302
              [%- END -%]
283
303
304
              <span name="regex_fields" style="display: none;">
305
                s/<input type="text" id="[% mv.id | html %]" name="regex_search" placeholder="regex pattern" />/
306
                <input type="text" id="[% mv.id | html %]" name="regex_replace" placeholder="regex replacement" />/
307
                <input type="text" id="[% mv.id | html %]" name="regex_modifiers" placeholder="ig" size="3" />
308
              </span>
309
284
              [% UNLESS ( ite.mandatory ) %]
310
              [% UNLESS ( ite.mandatory ) %]
285
                <input type="checkbox" id="row[% ite.tag | html %][% ite.subfield | html %][% ite.random | html %]" title="Check to delete subfield [% ite.subfield | html %]" name="disable_input" value="[% ite.subfield | html %]" />
311
                <input type="checkbox" id="row[% ite.tag | html %][% ite.subfield | html %][% ite.random | html %]" title="Check to delete subfield [% ite.subfield | html %]" name="disable_input" value="[% ite.subfield | html %]" />
286
              [% ELSE %]
312
              [% ELSE %]
287
                <span class="required">Required</span>
313
                <span class="required">Required</span>
288
              [% END %]
314
              [% END %]
289
315
316
              [% IF (mv.type == 'text' || mv.type == 'textarea' ) %]
317
                <input type="checkbox" name="field_regex" id="[% ite.id | html %]" title="Use regular expression">
318
              [% END %]
319
290
              <input type="hidden" name="tag"       value="[% ite.tag | html %]" />
320
              <input type="hidden" name="tag"       value="[% ite.tag | html %]" />
291
              <input type="hidden" name="subfield"       value="[% ite.subfield | html %]" />
321
              <input type="hidden" name="subfield"       value="[% ite.subfield | html %]" />
292
              <input type="hidden" name="mandatory"       value="[% ite.mandatory | html %]" />
322
              <input type="hidden" name="mandatory"       value="[% ite.mandatory | html %]" />
(-)a/tools/batchMod.pl (-3 / +33 lines)
Lines 105-110 if ($op eq "action") { Link Here
105
    my @tags      = $input->multi_param('tag');
105
    my @tags      = $input->multi_param('tag');
106
    my @subfields = $input->multi_param('subfield');
106
    my @subfields = $input->multi_param('subfield');
107
    my @values    = $input->multi_param('field_value');
107
    my @values    = $input->multi_param('field_value');
108
    my @searches  = $input->multi_param('regex_search');
109
    my @replaces  = $input->multi_param('regex_replace');
110
    my @modifiers = $input->multi_param('regex_modifiers');
108
    my @disabled  = $input->multi_param('disable_input');
111
    my @disabled  = $input->multi_param('disable_input');
109
    # build indicator hash.
112
    # build indicator hash.
110
    my @ind_tag   = $input->multi_param('ind_tag');
113
    my @ind_tag   = $input->multi_param('ind_tag');
Lines 112-119 if ($op eq "action") { Link Here
112
115
113
    # Is there something to modify ?
116
    # Is there something to modify ?
114
    # TODO : We shall use this var to warn the user in case no modification was done to the items
117
    # TODO : We shall use this var to warn the user in case no modification was done to the items
115
    my $values_to_modify = scalar(grep {!/^$/} @values);
118
    my $values_to_modify = scalar(grep {!/^$/} @values) || scalar(grep {!/^$/} @searches);
116
    my $values_to_blank  = scalar(@disabled);
119
    my $values_to_blank  = scalar(@disabled);
120
117
    my $marcitem;
121
    my $marcitem;
118
122
119
    # Once the job is done
123
    # Once the job is done
Lines 203-210 if ($op eq "action") { Link Here
203
		} else {
207
		} else {
204
            if ($values_to_modify || $values_to_blank) {
208
            if ($values_to_modify || $values_to_blank) {
205
                my $localmarcitem = Item2Marc($itemdata);
209
                my $localmarcitem = Item2Marc($itemdata);
210
                my $modified = 0;
211
212
                for ( my $i = 0 ; $i < @tags ; $i++ ) {
213
                    my $search = $searches[$i];
214
                    next unless $search;
215
216
                    my $tag = $tags[$i];
217
                    my $subfield = $subfields[$i];
218
                    my $replace = $replaces[$i];
219
                    my $mod = $modifiers[$i];
220
221
                    my $value = $localmarcitem->field( $tag )->subfield( $subfield );
222
                    my $old_value = $value;
223
                    ## no critic (StringyEval)
224
                    eval "\$value =~ s/$search/$replace/$mod";
225
226
                    my @fields_to = $localmarcitem->field($tag);
227
                    foreach my $field_to_update ( @fields_to ) {
228
                        unless ( $old_value eq $value ) {
229
                            $modified++;
230
                            $field_to_update->update( $subfield => $value );
231
                        }
232
                    }
233
                }
206
234
207
                my $modified = UpdateMarcWith( $marcitem, $localmarcitem );
235
                $modified += UpdateMarcWith( $marcitem, $localmarcitem );
208
                if ( $modified ) {
236
                if ( $modified ) {
209
                    eval {
237
                    eval {
210
                        if ( my $item = ModItemFromMarc( $localmarcitem, $itemdata->{biblionumber}, $itemnumber ) ) {
238
                        if ( my $item = ModItemFromMarc( $localmarcitem, $itemdata->{biblionumber}, $itemnumber ) ) {
Lines 616-621 sub UpdateMarcWith { Link Here
616
    my $fieldfrom=$marcfrom->field($itemtag);
644
    my $fieldfrom=$marcfrom->field($itemtag);
617
    my @fields_to=$marcto->field($itemtag);
645
    my @fields_to=$marcto->field($itemtag);
618
    my $modified = 0;
646
    my $modified = 0;
647
648
    return $modified unless $fieldfrom;
649
619
    foreach my $subfield ( $fieldfrom->subfields() ) {
650
    foreach my $subfield ( $fieldfrom->subfields() ) {
620
        foreach my $field_to_update ( @fields_to ) {
651
        foreach my $field_to_update ( @fields_to ) {
621
            if ( $subfield->[1] ) {
652
            if ( $subfield->[1] ) {
622
- 

Return to bug 21959