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

(-)a/Koha/UI/Form/Builder/Item.pm (+7 lines)
Lines 403-408 sub generate_subfield_form { Link Here
403
            value => $value,
403
            value => $value,
404
        };
404
        };
405
    }
405
    }
406
    elsif ( $subfield->{kohafield} =~ /items\.(replacementprice)/ ) {
407
        $subfield_data{marc_value} = {
408
            type => 'replacementprice',
409
            id => $subfield_data{id},
410
            value => $value
411
        };
412
    }
406
    else {
413
    else {
407
        # it's a standard field
414
        # it's a standard field
408
        $subfield_data{marc_value} = {
415
        $subfield_data{marc_value} = {
(-)a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss (-20 lines)
Lines 4895-4918 div .suggestion_note { Link Here
4895
            display: block;
4895
            display: block;
4896
        }
4896
        }
4897
    }
4897
    }
4898
}
4899
4900
#cat_additem .replacementprice_error_message {
4901
  color: red;
4902
  margin-left: 20vw;
4903
}
4904
4905
#tools_batchMod-edit .replacementprice_error_message {
4906
    color: red;
4907
    margin-left: 24.5vw;
4908
}
4909
4910
.replacementprice_error_message.hidden {
4911
    display: none;
4912
}
4913
4914
@media (max-width: 1000px) {
4915
  .replacementprice_error_message {
4916
    margin-left: 23.5vw;
4917
  }
4918
}
4898
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc (-3 / +2 lines)
Lines 170-175 Link Here
170
                         <input type="text" id="[% mv.id | html %]" name="[% kohafield | html %]" class="input_marceditor [% kohafield | html %] flatpickr" value="[% mv.value | html %]" class="flatpickr" data-flatpickr-set-to-today="true" />
170
                         <input type="text" id="[% mv.id | html %]" name="[% kohafield | html %]" class="input_marceditor [% kohafield | html %] flatpickr" value="[% mv.value | html %]" class="flatpickr" data-flatpickr-set-to-today="true" />
171
                    [% ELSIF ( mv.type == 'datetime_field' ) %]
171
                    [% ELSIF ( mv.type == 'datetime_field' ) %]
172
                         <input type="text" id="[% mv.id | html %]" name="[% kohafield | html %]" class="input_marceditor [% kohafield | html %] flatpickr" value="[% mv.value | html %]" data-flatpickr-enable-time="true" data-flatpickr-set-to-today="true" />
172
                         <input type="text" id="[% mv.id | html %]" name="[% kohafield | html %]" class="input_marceditor [% kohafield | html %] flatpickr" value="[% mv.value | html %]" data-flatpickr-enable-time="true" data-flatpickr-set-to-today="true" />
173
                    [% ELSIF ( mv.type == 'replacementprice' ) %]
174
                        <input class="decimal valid input_marceditor [% kohafield | html %]" type="text" id="[% mv.id | html %]" name="[% kohafield | html %]" value="[% mv.value | html %]" maxlength="[%- mv.maxlength | html -%]" aria-invalid="false" />
173
                    [% END %]
175
                    [% END %]
174
176
175
                    [% IF subfield.kohafield == 'items.more_subfields_xml' %]
177
                    [% IF subfield.kohafield == 'items.more_subfields_xml' %]
Lines 217-225 Link Here
217
219
218
                </div>
220
                </div>
219
221
220
                [% IF subfield.subfield == 'v' %]
221
                    <span class="replacementprice_error_message hidden"> Only numbers and periods are allowed (for example, 10.99).</span>
222
                [% END %]
223
            </li>
222
            </li>
224
        [% END %]
223
        [% END %]
225
    </ol>
224
    </ol>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt (-1 / +1 lines)
Lines 200-206 Link Here
200
    <div class="col-md-10 order-md-2 order-sm-1">
200
    <div class="col-md-10 order-md-2 order-sm-1">
201
201
202
<div id="cataloguing_additem_newitem" class="item_edit_form page-section">
202
<div id="cataloguing_additem_newitem" class="item_edit_form page-section">
203
    <form id="f" method="post" action="/cgi-bin/koha/cataloguing/additem.pl?biblionumber=[% biblio.biblionumber | html %]" name="f">
203
    <form id="f" method="post" action="/cgi-bin/koha/cataloguing/additem.pl?biblionumber=[% biblio.biblionumber | html %]" name="f" class="validated">
204
        [% INCLUDE 'csrf-token.inc' %]
204
        [% INCLUDE 'csrf-token.inc' %]
205
    <input type="hidden" name="op" value="[% op | html %]" />
205
    <input type="hidden" name="op" value="[% op | html %]" />
206
    [% IF (popup) %]
206
    [% IF (popup) %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt (-1 / +1 lines)
Lines 156-162 Link Here
156
        [% END # /IF notfounditemnumbers.size %]
156
        [% END # /IF notfounditemnumbers.size %]
157
157
158
158
159
        <form name="f" action="batchMod.pl" method="post">
159
        <form name="f" action="batchMod.pl" method="post" class="validated">
160
            [% INCLUDE 'csrf-token.inc' %]
160
            [% INCLUDE 'csrf-token.inc' %]
161
            <input type="hidden" name="op" value="[% op | html %]" />
161
            <input type="hidden" name="op" value="[% op | html %]" />
162
            <input type="hidden" name="searchid" value="[% searchid | html %]" />
162
            <input type="hidden" name="searchid" value="[% searchid | html %]" />
(-)a/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js (-19 lines)
Lines 4-28 var browser = KOHA.browser(searchid, parseInt(biblionumber, 10)); Link Here
4
browser.show();
4
browser.show();
5
5
6
$(document).ready(function(){
6
$(document).ready(function(){
7
    $("#cataloguing_additem_newitem form").on("submit", function (e) {
8
        var replacementprice = $("input[name='items.replacementprice']").val();
9
        if (!/^[0-9.]+$/.test(replacementprice)) {
10
            e.preventDefault();
11
            return false;
12
        }
13
        return true;
14
    });
15
16
    $("input[name='items.replacementprice']").on("input", function () {
17
        var value = $(this).val();
18
        var isValid = /^[0-9.]*$/.test(value);
19
20
        if (!isValid) {
21
            $('.replacementprice_error_message').removeClass('hidden');
22
        } else {
23
            $('.replacementprice_error_message').addClass('hidden');
24
        }
25
    });
26
7
27
    // Remove the onclick event defined in browser.js,
8
    // Remove the onclick event defined in browser.js,
28
    // otherwise the deletion confirmation will not work correctly
9
    // otherwise the deletion confirmation will not work correctly
(-)a/koha-tmpl/intranet-tmpl/prog/js/pages/batchMod.js (-19 lines)
Lines 118-142 function hideAllColumns() { Link Here
118
}
118
}
119
119
120
$(document).ready(function () {
120
$(document).ready(function () {
121
    $('form[action="batchMod.pl"]').on("submit", function (e) {
122
        var replacementprice = $("input[name='items.replacementprice']").val();
123
        if (!/^[0-9.]+$/.test(replacementprice)) {
124
            e.preventDefault();
125
            return false;
126
        }
127
        return true;
128
    });
129
130
    $("input[name='items.replacementprice']").on("input", function () {
131
        var value = $(this).val();
132
        var isValid = /^[0-9.]*$/.test(value);
133
134
        if (!isValid) {
135
            $('.replacementprice_error_message').removeClass('hidden');
136
        } else {
137
            $('.replacementprice_error_message').addClass('hidden');
138
        }
139
    });
140
121
141
    var items_table = KohaTable("itemst", {
122
    var items_table = KohaTable("itemst", {
142
        "columnDefs":  [
123
        "columnDefs":  [
(-)a/t/db_dependent/Koha/UI/Form/Builder/Item.t (-2 / +45 lines)
Lines 16-22 Link Here
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
use Test::More tests => 10;
19
use Test::More tests => 11;
20
use Test::MockModule;
20
use Test::MockModule;
21
use Data::Dumper qw( Dumper );
21
use Data::Dumper qw( Dumper );
22
use utf8;
22
use utf8;
Lines 456-458 sub setup_mss { Link Here
456
        }
456
        }
457
    )->update( { display_order => \['FLOOR( 1 + RAND( ) * 10 )'] } );
457
    )->update( { display_order => \['FLOOR( 1 + RAND( ) * 10 )'] } );
458
}
458
}
459
- 
459
460
subtest 'replacementprice handling' => sub {
461
    plan tests => 3;
462
463
    my $subfield = {
464
        kohafield => 'items.replacementprice',
465
        id        => 'tag_952_subfield_v_12345',
466
        value     => '123.45',
467
    };
468
469
    my $expected_marc_value = {
470
        type  => 'replacementprice',
471
        id    => 'tag_952_subfield_v_12345',
472
        value => '123.45',
473
    };
474
475
    my $item = Koha::Item->new();
476
477
    my %subfield_data;
478
    if ( $subfield->{kohafield} =~ /items\.(replacementprice)/ ) {
479
        $subfield_data{marc_value} = {
480
            type  => 'replacementprice',
481
            id    => $subfield->{id},
482
            value => $subfield->{value},
483
        };
484
    }
485
486
    ok(
487
        exists $subfield_data{marc_value},
488
        "Subfield data contains 'marc_value' key"
489
    );
490
491
    is(
492
        $subfield_data{marc_value}->{type},
493
        $expected_marc_value->{type},
494
        "Subfield 'type' is correctly set to 'replacementprice'"
495
    );
496
497
    is_deeply(
498
        $subfield_data{marc_value},
499
        $expected_marc_value,
500
        'Subfield data is processed correctly for replacementprice'
501
    );
502
};

Return to bug 38839