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 24-40 $(document).ready(function(){ Link Here
24
      var row = $(this).attr("id");
24
      var row = $(this).attr("id");
25
      row = row.replace("row","hint");
25
      row = row.replace("row","hint");
26
      var todisable = $(this).parent().find("[name='field_value'],[name='tag'],[name='subfield'],[name='mandatory']");
26
      var todisable = $(this).parent().find("[name='field_value'],[name='tag'],[name='subfield'],[name='mandatory']");
27
      var regex_input = $(this).parent().find("[name='field_regex']");
27
      if ($(this).is(":checked")) {
28
      if ($(this).is(":checked")) {
28
          $(todisable).prop('disabled', true);
29
          $(todisable).prop('disabled', true);
29
          $("#"+row).html(_("This subfield will be deleted"));
30
          $("#"+row).html(_("This subfield will be deleted"));
31
          $(regex_input).prop('disabled', true);
30
      } else {
32
      } else {
31
          $(todisable).prop('disabled', false);
33
          $(todisable).prop('disabled', false);
32
          $("#"+row).html("");
34
          $("#"+row).html("");
35
          $(regex_input).prop('disabled', false);
33
      }
36
      }
34
  });
37
  });
35
    $("#mainformsubmit").on("click",function(){
38
    $("#mainformsubmit").on("click",function(){
36
        return submitBackgroundJob(this.form);
39
        return submitBackgroundJob(this.form);
37
    });
40
    });
41
  $('input[name="field_regex"]').change(function() {
42
    var id = $(this).attr('id');
43
    var editor = $(this).parent().find("[name='field_value']");
44
    var regex = $(this).parent().find("[name='regex_fields']");
45
    var disable_input = $(this).parent().find("[name='disable_input']");
46
    if ($(this).is(':checked')) {
47
      $(editor).hide();
48
      $(regex).show();
49
      $(this).parent().find('.hint').html(_("Enter a regular expression for this subflied"));
50
      $(disable_input).prop('disabled', true);
51
    } else {
52
      $(editor).show();
53
      $(regex).hide();
54
      $(this).parent().find('.hint').html(_(""));
55
      $(disable_input).prop('disabled', false);
56
    }
57
  });
38
});
58
});
39
//]]>
59
//]]>
40
</script>
60
</script>
Lines 285-296 $(document).ready(function(){ Link Here
285
                <textarea tabindex="1" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor" size="50" maxlength="255">[%- mv.value | html -%]"</textarea>
305
                <textarea tabindex="1" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor" size="50" maxlength="255">[%- mv.value | html -%]"</textarea>
286
              [%- END -%]
306
              [%- END -%]
287
307
308
              <span name="regex_fields" style="display: none;">
309
                s/<input type="text" id="[% mv.id | html %]" name="regex_search" placeholder="regex pattern" />/
310
                <input type="text" id="[% mv.id | html %]" name="regex_replace" placeholder="regex replacement" />/
311
                <input type="text" id="[% mv.id | html %]" name="regex_modifiers" placeholder="ig" size="3" />
312
              </span>
313
288
              [% UNLESS ( ite.mandatory ) %]
314
              [% UNLESS ( ite.mandatory ) %]
289
                <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 %]" />
315
                <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 %]" />
290
              [% ELSE %]
316
              [% ELSE %]
291
                <span class="required">Required</span>
317
                <span class="required">Required</span>
292
              [% END %]
318
              [% END %]
293
319
320
              [% IF (mv.type == 'text' || mv.type == 'textarea' ) %]
321
                <input type="checkbox" name="field_regex" id="[% ite.id | html %]" title="Use regular expression">
322
              [% END %]
323
294
              <input type="hidden" name="tag"       value="[% ite.tag | html %]" />
324
              <input type="hidden" name="tag"       value="[% ite.tag | html %]" />
295
              <input type="hidden" name="subfield"       value="[% ite.subfield | html %]" />
325
              <input type="hidden" name="subfield"       value="[% ite.subfield | html %]" />
296
              <input type="hidden" name="mandatory"       value="[% ite.mandatory | html %]" />
326
              <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 211-218 if ($op eq "action") { Link Here
211
		} else {
215
		} else {
212
            if ($values_to_modify || $values_to_blank) {
216
            if ($values_to_modify || $values_to_blank) {
213
                my $localmarcitem = Item2Marc($itemdata);
217
                my $localmarcitem = Item2Marc($itemdata);
218
                my $modified = 0;
219
220
                for ( my $i = 0 ; $i < @tags ; $i++ ) {
221
                    my $search = $searches[$i];
222
                    next unless $search;
223
224
                    my $tag = $tags[$i];
225
                    my $subfield = $subfields[$i];
226
                    my $replace = $replaces[$i];
227
                    my $mod = $modifiers[$i];
228
229
                    my $value = $localmarcitem->field( $tag )->subfield( $subfield );
230
                    my $old_value = $value;
231
                    ## no critic (StringyEval)
232
                    eval "\$value =~ s/$search/$replace/$mod";
233
234
                    my @fields_to = $localmarcitem->field($tag);
235
                    foreach my $field_to_update ( @fields_to ) {
236
                        unless ( $old_value eq $value ) {
237
                            $modified++;
238
                            $field_to_update->update( $subfield => $value );
239
                        }
240
                    }
241
                }
214
242
215
                my $modified = UpdateMarcWith( $marcitem, $localmarcitem );
243
                $modified += UpdateMarcWith( $marcitem, $localmarcitem );
216
                if ( $modified ) {
244
                if ( $modified ) {
217
                    eval {
245
                    eval {
218
                        if ( my $item = ModItemFromMarc( $localmarcitem, $itemdata->{biblionumber}, $itemnumber ) ) {
246
                        if ( my $item = ModItemFromMarc( $localmarcitem, $itemdata->{biblionumber}, $itemnumber ) ) {
Lines 638-643 sub UpdateMarcWith { Link Here
638
    my $fieldfrom=$marcfrom->field($itemtag);
666
    my $fieldfrom=$marcfrom->field($itemtag);
639
    my @fields_to=$marcto->field($itemtag);
667
    my @fields_to=$marcto->field($itemtag);
640
    my $modified = 0;
668
    my $modified = 0;
669
670
    return $modified unless $fieldfrom;
671
641
    foreach my $subfield ( $fieldfrom->subfields() ) {
672
    foreach my $subfield ( $fieldfrom->subfields() ) {
642
        foreach my $field_to_update ( @fields_to ) {
673
        foreach my $field_to_update ( @fields_to ) {
643
            if ( $subfield->[1] ) {
674
            if ( $subfield->[1] ) {
644
- 

Return to bug 21959