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 283-288 Link Here
283
        }
283
        }
284
    }
284
    }
285
285
286
    function ValuePluginParseFunctionName(funcname) {
287
        var re = /^tag_(...)_subfield_(.)_/;
288
        var found = funcname.match(re);
289
        return { field: found[1], subfield: found[2] };
290
    }
291
292
    function ValuePluginHighlightField(funcname) {
293
        document.getElementById(funcname).setAttribute('class','subfield_not_filled');
294
        document.getElementById(funcname).focus();
295
    }
296
286
    /**
297
    /**
287
     * check if mandatory/important subfields are written
298
     * check if mandatory/important subfields are written
288
     * @param mandatory true to check for mandatories, false for importants
299
     * @param mandatory true to check for mandatories, false for importants
Lines 331-336 Link Here
331
        }
342
        }
332
343
333
        StrAlert += "\n\n";
344
        StrAlert += "\n\n";
345
346
        /* Allow value builder plugins to perform extra checks before saving the record */
347
        $('input').each(function() {
348
            var d = $(this).data('savecheck');
349
            if (d && d != '') {
350
                var fn = window[d];
351
                if (typeof fn === 'function') {
352
                    var err = fn(this.id);
353
                    if (err) {
354
                        var val = $(this).val();
355
                        StrAlert += "\t* ";
356
                        var f = ValuePluginParseFunctionName(err.funcname);
357
                        StrAlert += _("tag %s subfield %s: %s (%s)").format(f.field, f.subfield, err.msg, val);
358
                        StrAlert += "\n";
359
                        ValuePluginHighlightField(err.funcname);
360
                        flag=1;
361
                    }
362
                }
363
            }
364
        });
365
334
        for(var i=0,len=subfields.length; i<len ; i++){
366
        for(var i=0,len=subfields.length; i<len ; i++){
335
            var tag=subfields[i].substr(4,3);
367
            var tag=subfields[i].substr(4,3);
336
            var subfield=subfields[i].substr(17,1);
368
            var subfield=subfields[i].substr(17,1);
(-)a/koha-tmpl/intranet-tmpl/prog/js/cataloging.js (-1 / +7 lines)
Lines 112-117 function CloneField(index, hideMarc, advancedMARCEditor) { Link Here
112
112
113
    clone.setAttribute('id',new_id); // setting a new id for the parent li
113
    clone.setAttribute('id',new_id); // setting a new id for the parent li
114
114
115
    var oinputs = original.getElementsByTagName('input');
116
    for (var i=0; i < oinputs.length; i++) {
117
        if ($(oinputs[i]).data('savecheck')) {
118
            $(clone).find("#"+oinputs[i].getAttribute('id')).data('savecheck', $(oinputs[i]).data('savecheck'));
119
        }
120
    }
121
115
    var divs = Array.from(clone.getElementsByTagName('li')).concat(Array.from(clone.getElementsByTagName('div')));
122
    var divs = Array.from(clone.getElementsByTagName('li')).concat(Array.from(clone.getElementsByTagName('div')));
116
123
117
    // if hide_marc, indicators are hidden fields
124
    // if hide_marc, indicators are hidden fields
118
- 

Return to bug 23925