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

(-)a/Koha/FrameworkPlugin.pm (-1 / +4 lines)
Lines 301-307 sub _process_javascript { Link Here
301
    my $bind = '';
301
    my $bind = '';
302
    my $clickfound = 0;
302
    my $clickfound = 0;
303
    my @events = qw|click focus blur change mouseover mouseout mousedown
303
    my @events = qw|click focus blur change mouseover mouseout mousedown
304
        mouseup mousemove keydown keypress keyup|;
304
        mouseup mousemove keydown keypress keyup savecheck|;
305
    foreach my $ev ( @events ) {
305
    foreach my $ev ( @events ) {
306
        my $scan = $ev eq 'click' && $self->{oldschool}? 'clic': $ev;
306
        my $scan = $ev eq 'click' && $self->{oldschool}? 'clic': $ev;
307
        if( $script =~ /function\s+($scan\w+)\s*\(([^\)]*)\)/is ) {
307
        if( $script =~ /function\s+($scan\w+)\s*\(([^\)]*)\)/is ) {
Lines 334-339 sub _add_binding { Link Here
334
    } elsif( $fname eq 'noclick' ) { # no click: return false, no scroll
334
    } elsif( $fname eq 'noclick' ) { # no click: return false, no scroll
335
        $bind= qq|    \$("#$ctl").$ev(function () { return false; });\n|;
335
        $bind= qq|    \$("#$ctl").$ev(function () { return false; });\n|;
336
        $script='';
336
        $script='';
337
    } elsif( $fname =~ /^savecheck/i ) {
338
        $bind= qq|    \$("#$ctl").data('savecheck', '$fname');\n|;
339
        $script='';
337
    } else { # add real event handler calling the function found
340
    } else { # add real event handler calling the function found
338
        $bind=qq|    \$("#$ctl").$ev(\{id: '$id'\}, ${fname}_handler);\n|;
341
        $bind=qq|    \$("#$ctl").$ev(\{id: '$id'\}, ${fname}_handler);\n|;
339
        $script = $self->_add_handler( $ev, $fname );
342
        $script = $self->_add_handler( $ev, $fname );
(-)a/cataloguing/value_builder/EXAMPLE.pl (+11 lines)
Lines 94-99 function Click$id(event) { Link Here
94
    window.open(\"../cataloguing/plugin_launcher.pl?plugin_name=EXAMPLE.pl&index=\"+event.data.id+\"&result=\"+fieldvalue,\"tag_editor\",'width=700,height=700,toolbar=false,scrollbars=yes');
94
    window.open(\"../cataloguing/plugin_launcher.pl?plugin_name=EXAMPLE.pl&index=\"+event.data.id+\"&result=\"+fieldvalue,\"tag_editor\",'width=700,height=700,toolbar=false,scrollbars=yes');
95
    return false; // prevents scrolling
95
    return false; // prevents scrolling
96
}
96
}
97
98
/* SaveCheck-function is used to prevent saving.
99
   Note: Parameter is id of the element, not an event. */
100
function SaveCheck$id(id) {
101
    var fieldvalue=\$('#'+id).val();
102
    if (v && v != '' && v != 'abc') {
103
         return { funcname: id, msg: "Sorry, field must contain 'abc'" };
104
    }
105
    return undefined;
106
}
107
97
</script>|;
108
</script>|;
98
};
109
};
99
# NOTE: Did you see the last semicolon? This was just an assignment!
110
# NOTE: Did you see the last semicolon? This was just an assignment!
(-)a/cataloguing/value_builder/ISBN.pl (+96 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2019 KohaSuomi oy
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use C4::Context;
23
use C4::Languages;
24
25
my $builder = sub {
26
    my ( $params ) = @_;
27
    my $function_name = $params->{id};
28
29
    my $js  = <<END_OF_JS;
30
<script type="text/javascript">
31
//<![CDATA[
32
33
function CheckISBN$function_name(str) {
34
    var sum,
35
        weight,
36
        digit,
37
        check,
38
        i;
39
    str = str.replace(/[^0-9X]/gi, '');
40
    if (str.length != 10 && str.length != 13) {
41
        return false;
42
    }
43
44
    if (str.length == 13) {
45
        sum = 0;
46
        for (i = 0; i < 12; i++) {
47
            digit = parseInt(str[i]);
48
            if (i % 2 == 1) {
49
                sum += 3*digit;
50
            } else {
51
                sum += digit;
52
            }
53
        }
54
        check = (10 - (sum % 10)) % 10;
55
        return (check == str[str.length-1]);
56
    }
57
58
    if (str.length == 10) {
59
        weight = 10;
60
        sum = 0;
61
        for (i = 0; i < 9; i++) {
62
            digit = parseInt(str[i]);
63
            sum += weight*digit;
64
            weight--;
65
        }
66
        check = 11 - (sum % 11);
67
        if (check == 10) {
68
            check = 'X';
69
        }
70
        return (check == str[str.length-1].toUpperCase());
71
    }
72
}
73
74
function Blur$function_name(id) {
75
    var v = \$('#' + id).val();
76
    \$('#' + id).val(v.trim());
77
    return false;
78
}
79
80
function SaveCheck$function_name(id) {
81
    var v = \$('#' + id).val();
82
    if (v && v != '') {
83
        if (!CheckISBN$function_name(v)) {
84
            return { funcname: id, msg: _("Illegal ISBN") };
85
        }
86
    }
87
    return undefined;
88
}
89
90
//]]>
91
</script>
92
END_OF_JS
93
    return $js;
94
};
95
96
return { builder => $builder };
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt (+32 lines)
Lines 269-274 Link Here
269
        }
269
        }
270
    }
270
    }
271
271
272
    function ValuePluginParseFunctionName(funcname) {
273
        var re = /^tag_(...)_subfield_(.)_/;
274
        var found = funcname.match(re);
275
        return { field: found[1], subfield: found[2] };
276
    }
277
278
    function ValuePluginHighlightField(funcname) {
279
        document.getElementById(funcname).setAttribute('class','subfield_not_filled');
280
        document.getElementById(funcname).focus();
281
    }
282
272
    /**
283
    /**
273
     * check if mandatory subfields are written
284
     * check if mandatory subfields are written
274
     */
285
     */
Lines 294-299 Link Here
294
        [% END %]
305
        [% END %]
295
        var StrAlert = _("Can't save this record because the following field aren't filled:");
306
        var StrAlert = _("Can't save this record because the following field aren't filled:");
296
        StrAlert += "\n\n";
307
        StrAlert += "\n\n";
308
309
        /* Allow value builder plugins to perform extra checks before saving the record */
310
        $('input').each(function() {
311
            var d = $(this).data('savecheck');
312
            if (d && d != '') {
313
                var fn = window[d];
314
                if (typeof fn === 'function') {
315
                    var err = fn(this.id);
316
                    if (err) {
317
                        var val = $(this).val();
318
                        StrAlert += "\t* ";
319
                        var f = ValuePluginParseFunctionName(err.funcname);
320
                        StrAlert += _("tag %s subfield %s: %s (%s)").format(f.field, f.subfield, err.msg, val);
321
                        StrAlert += "\n";
322
                        ValuePluginHighlightField(err.funcname);
323
                        flag=1;
324
                    }
325
                }
326
            }
327
        });
328
297
        for(var i=0,len=mandatories.length; i<len ; i++){
329
        for(var i=0,len=mandatories.length; i<len ; i++){
298
            var tag=mandatories[i].substr(4,3);
330
            var tag=mandatories[i].substr(4,3);
299
            var subfield=mandatories[i].substr(17,1);
331
            var subfield=mandatories[i].substr(17,1);
(-)a/koha-tmpl/intranet-tmpl/prog/js/cataloging.js (-1 / +7 lines)
Lines 110-115 function CloneField(index, hideMarc, advancedMARCEditor) { Link Here
110
110
111
    clone.setAttribute('id',new_id); // setting a new id for the parent div
111
    clone.setAttribute('id',new_id); // setting a new id for the parent div
112
112
113
    var oinputs = original.getElementsByTagName('input');
114
    for (var i=0; i < oinputs.length; i++) {
115
        if ($(oinputs[i]).data('savecheck')) {
116
            $(clone).find("#"+oinputs[i].getAttribute('id')).data('savecheck', $(oinputs[i]).data('savecheck'));
117
        }
118
    }
119
113
    var divs = clone.getElementsByTagName('div');
120
    var divs = clone.getElementsByTagName('div');
114
121
115
    // if hide_marc, indicators are hidden fields
122
    // if hide_marc, indicators are hidden fields
116
- 

Return to bug 23925