|
Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
# Copyright 2025 BibLibre SARL |
| 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 <https://www.gnu.org/licenses>. |
| 19 |
|
| 20 |
use Modern::Perl; |
| 21 |
use CGI qw ( -utf8 ); |
| 22 |
|
| 23 |
use C4::Auth qw( get_template_and_user ); |
| 24 |
use C4::Output qw( output_html_with_http_headers ); |
| 25 |
use Business::ISSN qw( is_valid_checksum ); |
| 26 |
|
| 27 |
my $builder = sub { |
| 28 |
my $params = shift; |
| 29 |
my $id = $params->{id}; |
| 30 |
|
| 31 |
return qq| |
| 32 |
<script> |
| 33 |
function Blur$id(event) { |
| 34 |
field = \$('#'+event.data.id); |
| 35 |
issn = field.val(); |
| 36 |
var url = '../cataloguing/plugin_launcher.pl?plugin_name=validate_issn.pl&issn=' + issn; |
| 37 |
var req = \$.get(url); |
| 38 |
req.done(function(resp){ |
| 39 |
if ( resp != 1 ) { |
| 40 |
field.addClass("subfield_not_filled"); |
| 41 |
alert("Invalid ISSN : " + issn); |
| 42 |
return; |
| 43 |
} |
| 44 |
field.removeClass("subfield_not_filled"); |
| 45 |
}); |
| 46 |
} |
| 47 |
</script>|; |
| 48 |
}; |
| 49 |
|
| 50 |
my $launcher = sub { |
| 51 |
my $params = shift; |
| 52 |
my $cgi = $params->{cgi}; |
| 53 |
my $issn = $cgi->param('issn'); |
| 54 |
|
| 55 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
| 56 |
{ |
| 57 |
template_name => "cataloguing/value_builder/ajax.tt", |
| 58 |
query => $cgi, |
| 59 |
type => "intranet", |
| 60 |
flagsrequired => { editcatalogue => '*' }, |
| 61 |
} |
| 62 |
); |
| 63 |
my $is_valid = is_valid_checksum($issn); |
| 64 |
$template->param( return => $is_valid ); |
| 65 |
output_html_with_http_headers $cgi, $cookie, $template->output; |
| 66 |
}; |
| 67 |
|
| 68 |
return { builder => $builder, launcher => $launcher }; |