[Rt-commit] rt branch, 5.0/custom-date-ranges-config-in-web-ui, updated. rt-4.4.4-725-gc7b5c8a65
Michel Rodriguez
michel at bestpractical.com
Thu Mar 12 09:54:27 EDT 2020
The branch, 5.0/custom-date-ranges-config-in-web-ui has been updated
via c7b5c8a6512d86f98f6d5399b8ca598cad035f5e (commit)
from 70a2c2bfd4560abf28d0af074ab464ae76f23167 (commit)
Summary of changes:
lib/RT/Config.pm | 105 +++++++++++++++++---
lib/RT/Interface/Web/MenuBuilder.pm | 6 ++
share/html/Admin/Tools/Config/Elements/Option | 2 +-
.../{EditPassword => CustomDateRangesSpecs} | 68 ++++++-------
.../Reminders.html => Prefs/CustomDateRanges.html} | 51 +++++-----
share/html/Prefs/Other.html | 3 +-
share/html/Widgets/Form/CustomDateRange | 109 +++------------------
.../{CustomDateRange => CustomDateRangesInput} | 62 ++----------
8 files changed, 181 insertions(+), 225 deletions(-)
copy share/html/Elements/{EditPassword => CustomDateRangesSpecs} (54%)
copy share/html/{Ticket/Reminders.html => Prefs/CustomDateRanges.html} (67%)
copy share/html/Widgets/Form/{CustomDateRange => CustomDateRangesInput} (71%)
- Log -----------------------------------------------------------------
commit c7b5c8a6512d86f98f6d5399b8ca598cad035f5e
Author: michel <michel at bestpractical.com>
Date: Thu Mar 12 14:52:53 2020 +0100
Added Custom Date Ranges as a user preference.
diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index ac47babbf..f4b173974 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -56,6 +56,7 @@ use File::Spec ();
use Symbol::Global::Name;
use List::MoreUtils 'uniq';
use Clone ();
+use Data::Dumper;
# Store log messages generated before RT::Logger is available
our @PreInitLoggerMessages;
@@ -1224,6 +1225,10 @@ our %META;
CustomDateRangesUI => {
Type => 'HASH',
Widget => '/Widgets/Form/CustomDateRange',
+ WidgetArguments => {},
+ Section => 'Custom date ranges',
+ SortOrder => 1,
+ Overridable => 1,
},
ExternalStorage => {
Type => 'HASH',
@@ -2494,12 +2499,72 @@ sub EnableExternalAuth {
return;
}
+sub AllCustomDateRanges {
+ my ( $self, $include_users ) = @_;
+ my $config = $self->Get( 'CustomDateRanges' );
+ my $cdr_origin = {};
+ _CustomDateRangesSpecOrigin( $config, 'config files', $cdr_origin );
+
+ if ( $include_users ) {
+ my $db_config = $self->Get( 'CustomDateRangesUI' );
+ _CustomDateRangesSpecOrigin( $db_config, 'database', $cdr_origin );
+ $config = _MergeCustomDateRangesSpecs( $config, $db_config );
+ }
+ return ( $config, $cdr_origin );
+}
+
+# stores the origin of the custom date ranges specs, for error reporting
+# $spec is a CDR config (from CustomDateRanges, CustomDateRangesUI or a user preferences)
+# $origin is a string that gets recorded
+# $cdr_origin is a hash to which the origin gets added
+sub _CustomDateRangesSpecOrigin {
+ my( $spec, $origin, $cdr_origin ) = @_;
+ return {} if ! CustomDateRangesSpecHasContent( $spec );
+ foreach my $type ( keys %$spec ) {
+ my $spec_type = $spec->{$type};
+ next if ref( $spec->{$type} ) ne 'HASH';
+ foreach my $name ( keys %{$spec->{$type}} ) {
+ $cdr_origin->{$type}->{$name} = $origin;
+ }
+ }
+}
+
+# merge all custom date ranges definitions into one
+sub _MergeCustomDateRangesSpecs {
+ my @specs = @_;
+ my $merged = {};
+ foreach my $spec ( @specs ) {
+ foreach my $type ( keys %$spec ) {
+ my $spec_type = $spec->{$type};
+ foreach my $name ( keys %$spec_type ) {
+ $merged->{$type}->{$name} ||= $spec_type->{$name};
+ }
+ }
+ }
+ return $merged;
+}
+
+# returns true if one of the categories of custom date ranges (RT::Ticket...)
+# has any content, false otherwise
+sub CustomDateRangesSpecHasContent {
+ my $spec = shift;
+ return if ref( $spec ) ne 'HASH';
+ foreach my $type ( keys %$spec ) {
+ my $spec_type = $spec->{$type};
+ next if ref( $spec_type ) ne 'HASH';
+ return 1 if scalar keys %$spec_type;
+ }
+ return;
+}
+
sub BuildCustomDateRangesUI {
my $self = shift;
my $args = shift;
- my $config = $self->Get( 'CustomDateRanges' );
- my $content = $self->Get( 'CustomDateRangesUI' );
+ my $user_config = $args->{UserConfig} || 0;
+
+ my( $config, $origin ) = $self->AllCustomDateRanges( $user_config );
+ my $current = $user_config ? $HTML::Mason::Commands::session{'CurrentUser'}->UserObj->Preferences("CustomDateRanges") : $self->Get( 'CustomDateRangesUI' );
my @results;
my %label = (
@@ -2511,21 +2576,22 @@ sub BuildCustomDateRangesUI {
my $ok = 1;
my $need_save;
- if ($content) {
- my @current_names = sort keys %{ $content->{'RT::Ticket'} };
+ if ($current) {
+ my @current_names = sort keys %{ $current->{'RT::Ticket'} };
for my $id ( 0 .. $#current_names ) {
my $current_name = $current_names[$id];
- my $spec = $content->{'RT::Ticket'}{$current_name};
+ my $spec = $current->{'RT::Ticket'}{$current_name};
my $name = $args->{"$id-name"};
if ( $config && $config->{'RT::Ticket'}{$name} ) {
- push @results, loc( "[_1] already exists", $name );
+ my $defined_in = $origin->{'RT::Ticket'}->{$name};
+ push @results, loc( "[_1] already exists in [_2]", $name, $defined_in );
$ok = 0;
next;
}
if ( $args->{"$id-Delete"} ) {
- delete $content->{'RT::Ticket'}{$current_name};
+ delete $current->{'RT::Ticket'}{$current_name};
push @results, loc( 'Deleted [_1]', $current_name );
$need_save ||= 1;
next;
@@ -2555,9 +2621,9 @@ sub BuildCustomDateRangesUI {
$updated ||= 1;
}
- $content->{'RT::Ticket'}{$name} = $spec;
+ $current->{'RT::Ticket'}{$name} = $spec;
if ( $name ne $current_name ) {
- delete $content->{'RT::Ticket'}{$current_name};
+ delete $current->{'RT::Ticket'}{$current_name};
$updated ||= 1;
}
@@ -2576,8 +2642,9 @@ sub BuildCustomDateRangesUI {
my $i = 0;
for my $name ( @{ $args->{name} } ) {
if ($name) {
- if ( $config && $config->{'RT::Ticket'}{$name} || $content && $content->{'RT::Ticket'}{$name} ) {
- push @results, loc( "[_1] already exists", $name );
+ if ( $config && $config->{'RT::Ticket'}{$name} || $current && $current->{'RT::Ticket'}{$name} ) {
+ my $defined_in = $origin->{'RT::Ticket'}->{$name};
+ push @results, loc( "[_1] already exists in [_2]", $name, $defined_in );
$ok = 0;
$i++;
next;
@@ -2603,19 +2670,31 @@ sub BuildCustomDateRangesUI {
}
}
- $content->{'RT::Ticket'}{$name} = $spec;
+ $current->{'RT::Ticket'}{$name} = $spec;
push @results, loc( 'Created [_1]', $name );
$need_save ||= 1;
$i++;
}
}
- $args->{CustomDateRangesUI}= $content;
+ $args->{CustomDateRangesUI}= $current;
return ( $ok, \@results);
}
sub loc { return RT->SystemUser->loc( @_ ) }
+sub Stringify {
+ my $value = shift;
+ return "" if !defined($value);
+
+ local $Data::Dumper::Terse = 1;
+ local $Data::Dumper::Indent = 2;
+ local $Data::Dumper::Sortkeys = 1;
+ my $output = Dumper $value;
+ chomp $output;
+ return $output;
+};
+
my $database_config_cache_time = 0;
my %original_setting_from_files;
my $in_config_change_txn = 0;
diff --git a/lib/RT/Interface/Web/MenuBuilder.pm b/lib/RT/Interface/Web/MenuBuilder.pm
index 56d525fe1..a63425252 100644
--- a/lib/RT/Interface/Web/MenuBuilder.pm
+++ b/lib/RT/Interface/Web/MenuBuilder.pm
@@ -308,6 +308,12 @@ sub BuildMainNav {
}
}
+ if( $request_path eq '/Prefs/SearchOptions.html' ) {
+ $page->child( custom_date_ranges => title => loc('Custom Date Ranges'), path => "/Prefs/CustomDateRanges.html" );
+ }
+ if( $request_path eq '/Prefs/CustomDateRanges.html' ) {
+ $page->child( custom_date_ranges => title => loc('Search Preferences'), path => "/Prefs/SearchOptions.html" );
+ }
if ( $request_path =~ m{^/Ticket/} ) {
if ( ( $HTML::Mason::Commands::DECODED_ARGS->{'id'} || '' ) =~ /^(\d+)$/ ) {
diff --git a/share/html/Admin/Tools/Config/Elements/Option b/share/html/Admin/Tools/Config/Elements/Option
index dc5dbe976..cd06d150d 100644
--- a/share/html/Admin/Tools/Config/Elements/Option
+++ b/share/html/Admin/Tools/Config/Elements/Option
@@ -82,7 +82,7 @@ my $is_immutable = $meta->{Immutable}
|| ($is_code && $val =~ s/sub \{ "DUMMY" \}/sub { ... }/g)
|| ($is_code && !$has_execute_code);
-my $current_value = $is_code ? $val : $raw_value;
+my $current_value = $is_code || $widget eq '/Widgets/Form/CustomDateRange' ? $val : $raw_value;
my $args = $meta->{'WidgetArguments'} || {};
if ($widget eq '/Widgets/Form/Boolean') {
%$args = (
diff --git a/share/html/Elements/CustomDateRangesSpecs b/share/html/Elements/CustomDateRangesSpecs
new file mode 100644
index 000000000..6f810588c
--- /dev/null
+++ b/share/html/Elements/CustomDateRangesSpecs
@@ -0,0 +1,92 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2020 Best Practical Solutions, LLC
+%# <sales at bestpractical.com>
+%#
+%# (Except where explicitly superseded by other copyright notices)
+%#
+%#
+%# LICENSE:
+%#
+%# This work is made available to you under the terms of Version 2 of
+%# the GNU General Public License. A copy of that license should have
+%# been provided with this software, but in any event can be snarfed
+%# from www.gnu.org.
+%#
+%# This work 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
+%# General Public License for more details.
+%#
+%# You should have received a copy of the GNU General Public License
+%# along with this program; if not, write to the Free Software
+%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+%#
+%#
+%# CONTRIBUTION SUBMISSION POLICY:
+%#
+%# (The following paragraph is not intended to limit the rights granted
+%# to you to modify and distribute this software under the terms of
+%# the GNU General Public License and is only of importance to you if
+%# you choose to contribute your changes and enhancements to the
+%# community by submitting them to Best Practical Solutions, LLC.)
+%#
+%# By intentionally submitting any modifications, corrections or
+%# derivatives to this work, or any other work intended for use with
+%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+%# you are the copyright holder for those contributions and you grant
+%# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
+%# royalty-free, perpetual, license to use, copy, create derivative
+%# works based on those contributions, and sublicense and distribute
+%# those contributions and any derivatives thereof.
+%#
+%# END BPS TAGGED BLOCK }}}
+
+<&|/Widgets/TitleBox, title => loc( "Custom date ranges in [_1]", $Location) &>
+% if ( $Config && keys %{$Config->{'RT::Ticket'}} ) {
+ <div class="">
+ <div class="form-row input-row-header">
+ <div class="col-md-2"><&|/l&>Name</&></div>
+ <div class="col-md-2"><&|/l&>From</&></div>
+ <div class="col-md-2"><&|/l&>From Value if Unset</&></div>
+ <div class="col-md-2"><&|/l&>To</&></div>
+ <div class="col-md-2"><&|/l&>To Value if Unset</&></div>
+ <div class="col-md-1"><&|/l&>Business<br>Hours?</&></div>
+ </div>
+% my $i = 0;
+% for my $name ( sort keys %{$Config->{'RT::Ticket'}} ) {
+% $i++;
+ <div class="<% $i % 2 ? 'oddline' : 'evenline' %> form-row input-row">
+ <div class="col-md-2"><% $name %></div>
+% my $spec = $Config->{'RT::Ticket'}{$name};
+% my %date_range_spec = RT::Ticket->_ParseCustomDateRangeSpec($name, $spec);
+ <div class="col-md-2"><% $date_range_spec{from} %></div>
+ <div class="col-md-2"><% $date_range_spec{from_fallback} || '' %></div>
+ <div class="col-md-2"><% $date_range_spec{to} %></div>
+ <div class="col-md-2"><% $date_range_spec{to_fallback} || '' %></div>
+ <div class="col-md-1"><% $date_range_spec{business_time} ? loc('Yes') : loc('No') %></div>
+ <div class="col-md-1 evenline" style="background-color:white;"></div>
+ </div>
+% }
+ </div>
+% }
+% else {
+ <p><&|/l&>No custom date ranges in <% $Location %></&></p>
+% }
+</&>
+
+<%INIT>
+
+Abort(loc("Permission Denied")) unless $session{'CurrentUser'}->HasRight( Object=> RT->System, Right => 'SuperUser')
+ || $session{'CurrentUser'}->HasRight( Object=> RT->System, Right => 'ModifySelf' );
+
+</%INIT>
+
+<%ARGS>
+$Location
+$Config
+</%ARGS>
diff --git a/share/html/Prefs/CustomDateRanges.html b/share/html/Prefs/CustomDateRanges.html
new file mode 100644
index 000000000..5de2526d8
--- /dev/null
+++ b/share/html/Prefs/CustomDateRanges.html
@@ -0,0 +1,80 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2019 Best Practical Solutions, LLC
+%# <sales at bestpractical.com>
+%#
+%# (Except where explicitly superseded by other copyright notices)
+%#
+%#
+%# LICENSE:
+%#
+%# This work is made available to you under the terms of Version 2 of
+%# the GNU General Public License. A copy of that license should have
+%# been provided with this software, but in any event can be snarfed
+%# from www.gnu.org.
+%#
+%# This work 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
+%# General Public License for more details.
+%#
+%# You should have received a copy of the GNU General Public License
+%# along with this program; if not, write to the Free Software
+%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+%#
+%#
+%# CONTRIBUTION SUBMISSION POLICY:
+%#
+%# (The following paragraph is not intended to limit the rights granted
+%# to you to modify and distribute this software under the terms of
+%# the GNU General Public License and is only of importance to you if
+%# you choose to contribute your changes and enhancements to the
+%# community by submitting them to Best Practical Solutions, LLC.)
+%#
+%# By intentionally submitting any modifications, corrections or
+%# derivatives to this work, or any other work intended for use with
+%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+%# you are the copyright holder for those contributions and you grant
+%# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
+%# royalty-free, perpetual, license to use, copy, create derivative
+%# works based on those contributions, and sublicense and distribute
+%# those contributions and any derivatives thereof.
+%#
+%# END BPS TAGGED BLOCK }}}
+<& /Elements/Header, Title => loc("Custom Date Ranges") &>
+<& /Elements/Tabs &>
+<& /Elements/ListActions, actions => \@actions &>
+
+<form method="post" action="CustomDateRanges.html">
+ <& /Widgets/Form/CustomDateRange, UserPreferences => 1, %ARGS &>
+ <input type="hidden" name="UserConfig" value="1" />
+<& /Elements/Submit, Name => 'SavePreferences', Label => loc('Save Changes') &>
+</form>
+<form>
+<%INIT>
+my @actions;
+
+if( $ARGS{SavePreferences} ) {
+ my( $ok, $results) = RT::Config->BuildCustomDateRangesUI( \%ARGS );
+ push @actions, @$results;
+ if( $ok ) {
+ my $CustomDateRangesSpec = $ARGS{CustomDateRangesUI};
+ if( values %{$CustomDateRangesSpec->{'RT::Ticket'}} ) {
+ my ($set_ok, $msg) = $session{'CurrentUser'}->UserObj->SetPreferences("CustomDateRanges", $CustomDateRangesSpec );
+ push @actions, $set_ok ? loc("Custom date ranges saved.") : $msg;
+ }
+ else {
+ my ($delete_ok, $msg) = $session{'CurrentUser'}->UserObj->DeletePreferences("CustomDateRanges");
+ push @actions, $delete_ok ? loc("Custom date ranges deleted.") : $msg;
+ }
+ }
+}
+
+</%INIT>
+
+<%ARGS>
+</%ARGS>
diff --git a/share/html/Prefs/Other.html b/share/html/Prefs/Other.html
index b1fb9a539..48e15eef0 100644
--- a/share/html/Prefs/Other.html
+++ b/share/html/Prefs/Other.html
@@ -54,6 +54,7 @@
<&|/Widgets/TitleBox, title => loc( $section ) &>
% foreach my $option( RT->Config->Options( Section => $section ) ) {
% next if $option eq 'EmailFrequency' && !RT->Config->Get('RecordOutgoingEmail');
+% next if $option eq 'CustomDateRangesUI';
% my $meta = RT->Config->Meta( $option );
<& $meta->{'Widget'},
Default => 1,
@@ -98,7 +99,7 @@ if ( $Update ) {
},
Store => $preferences,
Types => [RT->Config->Options], Default => 1, Arguments => \%ARGS,
- DefaultValue => { map { $_ => RT->Config->Get($_) }
+ DefaultValue => { map { $_ => RT->Config->Get($_) // '' }
RT->Config->Options
}, );
diff --git a/share/html/Widgets/Form/CustomDateRange b/share/html/Widgets/Form/CustomDateRange
index d5112dab2..4918e83b4 100644
--- a/share/html/Widgets/Form/CustomDateRange
+++ b/share/html/Widgets/Form/CustomDateRange
@@ -46,116 +46,33 @@
%#
%# END BPS TAGGED BLOCK }}}
-<&|/Widgets/TitleBox, title => loc('Custom Date Ranges In Config Files') &>
-% if ( $config && keys %{$config->{'RT::Ticket'}} ) {
- <table class="collection-as-table">
- <tr class="collection-as-table">
- <th class="collection-as-table"><&|/l&>Name</&></th>
- <th class="collection-as-table"><&|/l&>From</&></th>
- <th class="collection-as-table"><&|/l&>From Value if Unset</&></th>
- <th class="collection-as-table"><&|/l&>To</&></th>
- <th class="collection-as-table"><&|/l&>To Value if Unset</&></th>
- <th class="collection-as-table"><&|/l&>Business<br>Hours?</&></th>
- </tr>
-% my $i = 0;
-% for my $name ( sort keys %{$config->{'RT::Ticket'}} ) {
-% $i++;
- <tr class="<% $i % 2 ? 'oddline' : 'evenline' %>">
- <td class="collection-as-table"><% $name %></td>
-% my $spec = $config->{'RT::Ticket'}{$name};
-% my %date_range_spec = RT::Ticket->_ParseCustomDateRangeSpec($name, $spec);
- <td class="collection-as-table"><% $date_range_spec{from} %></td>
- <td class="collection-as-table"><% $date_range_spec{from_fallback} || '' %></td>
- <td class="collection-as-table"><% $date_range_spec{to} %></td>
- <td class="collection-as-table"><% $date_range_spec{to_fallback} || '' %></td>
- <td class="collection-as-table"><% $date_range_spec{business_time} ? loc('Yes') : loc('No') %></td>
- </tr>
-% }
- </table>
+<& /Elements/CustomDateRangesSpecs, Location => "config files", Config => $from_config &>
+% if ( $UserPreferences ) {
+ <& /Elements/CustomDateRangesSpecs, Location => "database", Config => $from_db &>
+ <& /Widgets/Form/CustomDateRangesInput, Location => "user preferences", Config => $from_user &>
% }
% else {
- <p><&|/l&>No custom date ranges in config files</&></p>
+ <& /Widgets/Form/CustomDateRangesInput, Location => "database", Config => $from_db &>
% }
-</&>
+<%INIT>
-<div id="custom-date-range-input">
- <input id="CustomDateRangesUI" type="hidden" name="CustomDateRangeUI" value="" />
- <input id="CustomDateRangesUI-updated" type="hidden" name="updated" value="0" />
- <input type="hidden" name="CustomDateRangesUI-Current" value="<% $CurrentValue %>" />
- <&|/Widgets/TitleBox, title => loc('Custom Date Ranges') &>
- <div id="custom-date-ranges">
- <div class="form-row input-row-header">
- <div class="col-md-2"><&|/l&>Name</&></div>
- <div class="col-md-2"><&|/l&>From</&></div>
- <div class="col-md-2"><&|/l&>From Value if Unset</&></div>
- <div class="col-md-2"><&|/l&>To</&></div>
- <div class="col-md-2"><&|/l&>To Value if Unset</&></div>
- <div class="col-md-1"><&|/l&>Business<br>Hours?</&></div>
- <div class="col-md-1">
- <input type="checkbox" name="DeleteAll" value="1" onclick="setCheckbox(this, /^\d+-Delete$/)" />
- <&|/l&>Delete</&>
- </div>
- </div>
-% my $i = 0;
-% if ( $content ) {
-% my $id = 0;
-% for my $name ( sort keys %{$content->{'RT::Ticket'}} ) {
-% $i++;
- <div class="form-row input-row">
- <div class="col-md-2"><input type="text" size="15" name="<% $id %>-name" value="<% $name %>" /></div>
-% my %date_range_spec = RT::Ticket->_ParseCustomDateRangeSpec($name, $content->{'RT::Ticket'}{$name});
- <div class="col-md-2"><& /Elements/SelectCustomDateRangeField, Name => "$id-from", Default => $date_range_spec{from} &></div>
- <div class="col-md-2"><& /Elements/SelectCustomDateRangeField, Name => "$id-from_fallback", Default => $date_range_spec{from_fallback} &></div>
- <div class="col-md-2"><& /Elements/SelectCustomDateRangeField, Name => "$id-to", Default => $date_range_spec{to} &></div>
- <div class="col-md-2"><& /Elements/SelectCustomDateRangeField, Name => "$id-to_fallback", Default => $date_range_spec{to_fallback} &></div>
- <div class="col-md-1">
- <select name="<% $id %>-business_time">
- <option value="1" <% $date_range_spec{business_time} ? 'selected="selected"' : '' |n%>><&|/l&>Yes</&></option>
- <option value="0" <% $date_range_spec{business_time} ? '': 'selected="selected"' |n%>><&|/l&>No</&></option>
- </select>
- </div>
- <div class="col-md-1"><input type="checkbox" name="<% $id %>-Delete" value="1" /></div>
- </div>
-% $id++;
-% }
-% }
+Abort(loc("Permission Denied")) unless $session{'CurrentUser'}->HasRight( Object=> RT->System, Right => 'SuperUser')
+ || ( $UserPreferences && $session{'CurrentUser'}->HasRight( Object=> RT->System, Right => 'ModifySelf' ) );
-% for ( 1 .. 3 ) {
-% $i++;
- <div class="form-row input-row">
- <div class="col-md-2"><input type="text" size="15" name="name" value="" /></div>
- <div class="col-md-2"><& /Elements/SelectCustomDateRangeField, Name => 'from' &></div>
- <div class="col-md-2"><& /Elements/SelectCustomDateRangeField, Name => 'from_fallback' &></div>
- <div class="col-md-2"><& /Elements/SelectCustomDateRangeField, Name => 'to' &></div>
- <div class="col-md-2"><& /Elements/SelectCustomDateRangeField, Name => 'to_fallback' &></div>
- <div class="col-md-1">
- <select name="business_time">
- <option value="1"><&|/l&>Yes</&></option>
- <option value="0" selected="selected"><&|/l&>No</&></option>
- </select>
- </div>
- <div class="col-md-1"></div>
- </div>
-% }
- </div>
- </&>
-</div>
-<%INIT>
+my $from_config = RT->Config->Get('CustomDateRanges');
+my $from_db = RT->Config->Get('CustomDateRangesUI');
-Abort(loc("Permission Denied")) unless $session{'CurrentUser'}->HasRight( Object=> RT->System, Right => 'SuperUser');
+my $from_user = $UserPreferences ? $session{'CurrentUser'}->UserObj->Preferences("CustomDateRanges" ) : undef;
-my $config = RT->Config->Get('CustomDateRanges');
-my $content = RT->Config->Get('CustomDateRangesUI');
</%INIT>
-
<%ARGS>
-$Save => $ARGS{updated};
-$Name
+$Save => $ARGS{updated},
$Arguments => {},
$Default => 0,
$DefaultValue => '',
$CurrentValue => '',
+$UserPreferences => 0,
</%ARGS>
diff --git a/share/html/Widgets/Form/CustomDateRange b/share/html/Widgets/Form/CustomDateRangesInput
similarity index 71%
copy from share/html/Widgets/Form/CustomDateRange
copy to share/html/Widgets/Form/CustomDateRangesInput
index d5112dab2..5301642ed 100644
--- a/share/html/Widgets/Form/CustomDateRange
+++ b/share/html/Widgets/Form/CustomDateRangesInput
@@ -46,43 +46,11 @@
%#
%# END BPS TAGGED BLOCK }}}
-<&|/Widgets/TitleBox, title => loc('Custom Date Ranges In Config Files') &>
-% if ( $config && keys %{$config->{'RT::Ticket'}} ) {
- <table class="collection-as-table">
- <tr class="collection-as-table">
- <th class="collection-as-table"><&|/l&>Name</&></th>
- <th class="collection-as-table"><&|/l&>From</&></th>
- <th class="collection-as-table"><&|/l&>From Value if Unset</&></th>
- <th class="collection-as-table"><&|/l&>To</&></th>
- <th class="collection-as-table"><&|/l&>To Value if Unset</&></th>
- <th class="collection-as-table"><&|/l&>Business<br>Hours?</&></th>
- </tr>
-% my $i = 0;
-% for my $name ( sort keys %{$config->{'RT::Ticket'}} ) {
-% $i++;
- <tr class="<% $i % 2 ? 'oddline' : 'evenline' %>">
- <td class="collection-as-table"><% $name %></td>
-% my $spec = $config->{'RT::Ticket'}{$name};
-% my %date_range_spec = RT::Ticket->_ParseCustomDateRangeSpec($name, $spec);
- <td class="collection-as-table"><% $date_range_spec{from} %></td>
- <td class="collection-as-table"><% $date_range_spec{from_fallback} || '' %></td>
- <td class="collection-as-table"><% $date_range_spec{to} %></td>
- <td class="collection-as-table"><% $date_range_spec{to_fallback} || '' %></td>
- <td class="collection-as-table"><% $date_range_spec{business_time} ? loc('Yes') : loc('No') %></td>
- </tr>
-% }
- </table>
-% }
-% else {
- <p><&|/l&>No custom date ranges in config files</&></p>
-% }
-</&>
-
<div id="custom-date-range-input">
<input id="CustomDateRangesUI" type="hidden" name="CustomDateRangeUI" value="" />
<input id="CustomDateRangesUI-updated" type="hidden" name="updated" value="0" />
- <input type="hidden" name="CustomDateRangesUI-Current" value="<% $CurrentValue %>" />
- <&|/Widgets/TitleBox, title => loc('Custom Date Ranges') &>
+ <input type="hidden" name="CustomDateRangesUI-Current" value="<% RT::Config::Stringify( $Config ) %>" />
+ <&|/Widgets/TitleBox, title => loc('Custom Date Ranges in [_1]', $Location ) &>
<div id="custom-date-ranges">
<div class="form-row input-row-header">
<div class="col-md-2"><&|/l&>Name</&></div>
@@ -97,13 +65,13 @@
</div>
</div>
% my $i = 0;
-% if ( $content ) {
+% if ( $Config ) {
% my $id = 0;
-% for my $name ( sort keys %{$content->{'RT::Ticket'}} ) {
+% for my $name ( sort keys %{$Config->{'RT::Ticket'}} ) {
% $i++;
<div class="form-row input-row">
<div class="col-md-2"><input type="text" size="15" name="<% $id %>-name" value="<% $name %>" /></div>
-% my %date_range_spec = RT::Ticket->_ParseCustomDateRangeSpec($name, $content->{'RT::Ticket'}{$name});
+% my %date_range_spec = RT::Ticket->_ParseCustomDateRangeSpec($name, $Config->{'RT::Ticket'}{$name});
<div class="col-md-2"><& /Elements/SelectCustomDateRangeField, Name => "$id-from", Default => $date_range_spec{from} &></div>
<div class="col-md-2"><& /Elements/SelectCustomDateRangeField, Name => "$id-from_fallback", Default => $date_range_spec{from_fallback} &></div>
<div class="col-md-2"><& /Elements/SelectCustomDateRangeField, Name => "$id-to", Default => $date_range_spec{to} &></div>
@@ -140,22 +108,8 @@
</div>
</&>
</div>
-<%INIT>
-
-Abort(loc("Permission Denied")) unless $session{'CurrentUser'}->HasRight( Object=> RT->System, Right => 'SuperUser');
-
-my $config = RT->Config->Get('CustomDateRanges');
-my $content = RT->Config->Get('CustomDateRangesUI');
-</%INIT>
-
<%ARGS>
-$Save => $ARGS{updated};
-$Name
-
-$Arguments => {},
-
-$Default => 0,
-$DefaultValue => '',
-$CurrentValue => '',
-
+$Location
+$Config
</%ARGS>
+
-----------------------------------------------------------------------
More information about the rt-commit
mailing list