-
Notifications
You must be signed in to change notification settings - Fork 49
/
Pagerange.pm
202 lines (153 loc) · 4.29 KB
/
Pagerange.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
######################################################################
#
# EPrints::MetaField::Pagerange;
#
######################################################################
#
#
######################################################################
=pod
=head1 NAME
B<EPrints::MetaField::Pagerange> - no description
=head1 DESCRIPTION
not done
=over 4
=cut
package EPrints::MetaField::Pagerange;
use EPrints::MetaField::Text;
@ISA = qw( EPrints::MetaField::Text );
use strict;
# note that this renders pages ranges differently from
# eprints 2.2
sub render_single_value
{
my( $self, $session, $value ) = @_;
my $frag = $session->make_doc_fragment;
# If there are leading zeros it's probably electronic (so 'other')
if( $value =~ /^([1-9]\d*)$/ )
{
$frag->appendChild( $session->html_phrase( "lib/metafield/pagerange:from_page",
from => $session->make_text( $1 ),
pagerange => $session->make_text( $value ),
));
}
elsif( $value =~ m/^([1-9]\d*)-(\d+)$/ )
{
if( $1 == $2 )
{
$frag->appendChild( $session->html_phrase( "lib/metafield/pagerange:same_page",
from => $session->make_text( $1 ),
to => $session->make_text( $2 ),
pagerange => $session->make_text( $value ),
));
}
else
{
$frag->appendChild( $session->html_phrase( "lib/metafield/pagerange:range",
from => $session->make_text( $1 ),
to => $session->make_text( $2 ),
pagerange => $session->make_text( $value ),
));
}
}
else
{
$frag->appendChild( $session->html_phrase( "lib/metafield/pagerange:other",
pagerange => $session->make_text( $value )
));
}
return $frag;
}
sub get_basic_input_elements
{
my( $self, $session, $value, $basename, $staff, $obj ) = @_;
my @pages = split /-/, $value if( defined $value );
my $fromid = $basename."_from";
my $toid = $basename."_to";
my $frag = $session->make_doc_fragment;
$frag->appendChild( $session->render_noenter_input_field(
class => "ep_form_text",
name => $fromid,
id => $fromid,
value => $pages[0],
size => 6,
maxlength => 120 ) );
$frag->appendChild( $session->make_text(" ") );
$frag->appendChild( $session->html_phrase(
"lib/metafield:to" ) );
$frag->appendChild( $session->make_text(" ") );
$frag->appendChild( $session->render_noenter_input_field(
class => "ep_form_text",
name => $toid,
id => $toid,
value => $pages[1],
size => 6,
maxlength => 120 ) );
return [ [ { el=>$frag } ] ];
}
sub get_basic_input_ids
{
my( $self, $session, $basename, $staff, $obj ) = @_;
return( $basename."_from", $basename."_to" );
}
sub is_browsable
{
return( 1 );
}
sub form_value_basic
{
my( $self, $session, $basename ) = @_;
my $from = $session->param( $basename."_from" );
my $to = $session->param( $basename."_to" );
if( !defined $to || $to eq "" )
{
return( $from );
}
return( $from . "-" . $to );
}
sub ordervalue_basic
{
my( $self , $value ) = @_;
unless( EPrints::Utils::is_set( $value ) )
{
return "";
}
my( $from, $to ) = split /-/, $value;
$to = $from unless defined $to;
# remove non digits
$from =~ s/[^0-9]//g;
$to =~ s/[^0-9]//g;
# set to zero if undef
$from = 0 if $from eq "";
$to = 0 if $to eq "";
return sprintf( "%08d-%08d", $from, $to );
}
sub render_search_input
{
my( $self, $session, $searchfield ) = @_;
return $session->render_input_field(
class => "ep_form_text",
name=>$searchfield->get_form_prefix,
value=>$searchfield->get_value,
size=>9,
maxlength=>100 );
}
######################################################################
1;
=head1 COPYRIGHT
=for COPYRIGHT BEGIN
Copyright 2000-2011 University of Southampton.
=for COPYRIGHT END
=for LICENSE BEGIN
This file is part of EPrints L<http://www.eprints.org/>.
EPrints is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
EPrints is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
License along with EPrints. If not, see L<http://www.gnu.org/licenses/>.
=for LICENSE END