Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
2 |
|
3 |
|
4 |
# Copyright 2010 Frédérick Capovilla - Libéo |
5 |
# |
6 |
# This file is part of Koha. |
7 |
# |
8 |
# Koha is free software; you can redistribute it and/or modify it under the |
9 |
# terms of the GNU General Public License as published by the Free Software |
10 |
# Foundation; |
11 |
# |
12 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
13 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
14 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
15 |
# |
16 |
# You should have received a copy of the GNU General Public License along |
17 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
18 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
19 |
|
20 |
use strict; |
21 |
use warnings; |
22 |
no warnings 'redefine'; # otherwise loading up multiple plugins fills the log with subroutine redefine warnings |
23 |
|
24 |
use C4::Context; |
25 |
use Regexp::Common qw( URI ); |
26 |
|
27 |
|
28 |
=head1 DESCRIPTION |
29 |
|
30 |
plugin_javascript : the javascript function called when the user enters the subfield. |
31 |
contain 3 javascript functions : |
32 |
* one called when the field is entered (OnFocus). Named FocusXXX |
33 |
* one called when the field is leaved (onBlur). Named BlurXXX |
34 |
* one called when the ... link is clicked (<a href="javascript:function">) named ClicXXX |
35 |
|
36 |
returns : |
37 |
* XXX |
38 |
* a variable containing the 3 scripts. |
39 |
the 3 scripts are inserted after the <input> in the html code |
40 |
|
41 |
=cut |
42 |
|
43 |
sub plugin_javascript { |
44 |
my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_; |
45 |
my $function_name = $field_number; |
46 |
my @split_field_name = split(/_/, $field_number); |
47 |
my $field_name = $split_field_name[1] . '$' . $split_field_name[3]; |
48 |
my $regex = $RE{URI}; |
49 |
$regex =~ s/\//\\\//g; |
50 |
|
51 |
my $res = <<END_OF_JS; |
52 |
<script type="text/javascript"> |
53 |
//<![CDATA[ |
54 |
|
55 |
function isUrl(s) { |
56 |
var regexp = /$regex/; |
57 |
return regexp.test(s); |
58 |
} |
59 |
|
60 |
function Blur$function_name(index) { |
61 |
var fieldValue = document.getElementById("$field_number").value; |
62 |
if(fieldValue != '') { |
63 |
if(!isUrl(fieldValue)) { |
64 |
invalid_url_alert('$field_name'); |
65 |
} |
66 |
} |
67 |
return 0; |
68 |
} |
69 |
|
70 |
function Focus$function_name(subfield_managed) { |
71 |
// Do Nothing |
72 |
} |
73 |
|
74 |
function Clic$function_name(subfield_managed) { |
75 |
// Do Nothing |
76 |
} |
77 |
//]]> |
78 |
</script> |
79 |
END_OF_JS |
80 |
return ($function_name,$res); |
81 |
} |
82 |
|
83 |
=head1 DESCRIPTION |
84 |
|
85 |
plugin : the true value_builded. The screen that is open in the popup window. |
86 |
|
87 |
=cut |
88 |
|
89 |
sub plugin { |
90 |
return ""; |
91 |
} |
92 |
|
93 |
1; |