Use helper for max_delay

This commit is contained in:
Luc Didry 2015-10-04 01:49:57 +02:00
parent 10a8dd8603
commit 841e8c4436
4 changed files with 18 additions and 6 deletions

View File

@ -114,11 +114,23 @@ sub startup {
}
);
$self->helper(
max_delay => sub {
my $c = shift;
return $c->config('max_delay') if ($c->config('max_delay') >= 0);
warn "max_delay set to a negative value. Default to 0.";
return 0;
}
);
$self->helper(
is_selected => sub {
my $c = shift;
my $num = shift;
return ($num == $c->max_delay) ? 'selected="selected"' : '' if ($c->max_delay && !$c->default_delay);
return ($num == $c->default_delay) ? 'selected="selected"' : '';
}
);

View File

@ -54,7 +54,7 @@ sub upload {
}
# If the file size is lower than the lowest configured size or if there is no delay_for_size setting, we choose the configured max delay
unless (defined $delay) {
$delay = ($json->{delay} <= $c->config('max_delay') || $c->config('max_delay') == 0) ? $json->{delay} : $c->config('max_delay');
$delay = ($json->{delay} <= $c->max_delay || $c->max_delay == 0) ? $json->{delay} : $c->max_delay;
}
$f = Lufi::File->new(

View File

@ -9,7 +9,7 @@
<p><%= l('This server sets limitations according to the file size. The expiration delay of your file will be the minimum between what you choose and the following limitations:') %></p>
<ul>
% my $delays = config('delay_for_size');
% $delays->{0} = config('max_delay');
% $delays->{0} = max_delay;
% my @keys = sort keys %{$delays};
% my $i = 0;
% for my $key (@keys) {

View File

@ -20,16 +20,16 @@
<select id="delete-day" class="form-control">
% for my $delay (qw/0 1 7 30 365/) {
% my $text = ($delay == 7 || $delay == 30) ? l('%1 days', $delay) : $d{'delay_'.$delay};
% if (config('max_delay')) {
% if (max_delay) {
% if ($delay) {
% if ($delay < config('max_delay')) {
% if ($delay < max_delay) {
<option value="<%= $delay %>" <%== is_selected($delay) %>><%= $text %></option>
% } elsif ($delay == config('max_delay')) {
% } elsif ($delay == max_delay) {
<option value="<%= $delay %>" <%== is_selected($delay) %>><%= $text %></option>
% last;
% } else {
% my $text = ($delay == 1) ? l('24 hours') : l('%1 days', $delay);
<option value="<%= config('max_delay') %>" <%== is_selected(config('max_delay')) %>><%= l('%1 days', config('max_delay')) %></option>
<option value="<%= max_delay %>" <%== is_selected(max_delay) %>><%= l('%1 days', max_delay) %></option>
% last;
% }
% }