[Rt-commit] rt branch, 4.2/date-input-keep-value, created. rt-4.1.19-112-gd408f86
? sunnavy
sunnavy at bestpractical.com
Fri Sep 6 04:51:51 EDT 2013
The branch, 4.2/date-input-keep-value has been created
at d408f862ca01e7085fc20472966deea2751f72d0 (commit)
- Log -----------------------------------------------------------------
commit a3233a81014f462a6b94e460764f892c69f6698e
Author: sunnavy <sunnavy at bestpractical.com>
Date: Wed Mar 28 12:58:58 2012 +0800
we should keep the input value for cf date/datetime
without that, we may lose its value if first "submit" fails.
see #19660
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 1ce71e5..a9286f8 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -3069,7 +3069,14 @@ sub _ProcessObjectCustomFieldUpdates {
my %values_hash;
foreach my $value (@values) {
- if ( my $entry = $cf_values->HasEntry($value) ) {
+ my $value_in_db = $value;
+ if ( $cf->Type eq 'DateTime' ) {
+ my $date = RT::Date->new($session{CurrentUser});
+ $date->Set(Format => 'unknown', Value => $value);
+ $value_in_db = $date->ISO;
+ }
+
+ if ( my $entry = $cf_values->HasEntry($value_in_db) ) {
$values_hash{ $entry->id } = 1;
next;
}
diff --git a/share/html/Elements/EditCustomField b/share/html/Elements/EditCustomField
index 1965557..b5f64f0 100644
--- a/share/html/Elements/EditCustomField
+++ b/share/html/Elements/EditCustomField
@@ -85,7 +85,21 @@ my $MaxValues = $CustomField->MaxValues;
if ($MaxValues == 1 && $Values) {
# what exactly is this doing? Without the "unless" it breaks RTFM
# transaction extraction into articles.
- $Default = ($Values->First ? $Values->First->Content : '') unless $Default;
+ unless ( $Default ) {
+ if ( $Values->First ) {
+ if ( $CustomField->Type eq 'DateTime' ) {
+ my $date = RT::Date->new($session{CurrentUser});
+ $date->Set(Format => 'ISO', Value => $Values->First->Content);
+ $Default = $date->ISO(Timezone => 'user');
+ }
+ else {
+ $Default = $Values->First->Content;
+ }
+ }
+ else {
+ $Default = '';
+ }
+ }
$Values->GotoFirstItem;
}
# The "Magic" hidden input causes RT to know that we were trying to edit the field, even if
diff --git a/share/html/Elements/EditCustomFieldDate b/share/html/Elements/EditCustomFieldDate
index 9e190be..03533d7 100644
--- a/share/html/Elements/EditCustomFieldDate
+++ b/share/html/Elements/EditCustomFieldDate
@@ -46,7 +46,7 @@
%#
%# END BPS TAGGED BLOCK }}}
% my $name = $NamePrefix.$CustomField->Id.'-Values';
-<& /Elements/SelectDate, Name => "$name", current => 0, ShowTime => 0 &> (<%$DateObj->AsString(Time => 0, Timezone => 'utc')%>)
+<& /Elements/SelectDate, Name => "$name", Default => $Default, current => 0, ShowTime => 0 &> (<%$DateObj->AsString(Time => 0, Timezone => 'utc')%>)
<%INIT>
my $DateObj = RT::Date->new ( $session{'CurrentUser'} );
diff --git a/share/html/Elements/EditCustomFieldDateTime b/share/html/Elements/EditCustomFieldDateTime
index 3d94855..33e139a 100644
--- a/share/html/Elements/EditCustomFieldDateTime
+++ b/share/html/Elements/EditCustomFieldDateTime
@@ -46,11 +46,11 @@
%#
%# END BPS TAGGED BLOCK }}}
% my $name = $NamePrefix.$CustomField->Id.'-Values';
-<& /Elements/SelectDate, Name => "$name", current => 0 &> (<%$DateObj->AsString%>)
+<& /Elements/SelectDate, Name => "$name", Default => $Default, current => 0 &> (<%$DateObj->AsString%>)
<%INIT>
my $DateObj = RT::Date->new ( $session{'CurrentUser'} );
-$DateObj->Set( Format => 'ISO', Value => $Default );
+$DateObj->Set( Format => 'unknown', Value => $Default );
</%INIT>
<%ARGS>
$Object => undef
diff --git a/share/html/Elements/SelectDate b/share/html/Elements/SelectDate
index db1117a..a237797 100644
--- a/share/html/Elements/SelectDate
+++ b/share/html/Elements/SelectDate
@@ -56,7 +56,7 @@ unless ((defined $Default) or ($current <= 0)) {
$year+1900,$mon+1,$mday,
$hour,$min);
}
-$Value = $Value || $Default;
+$Value = $Value || $Default || '';
unless ($Name) {
$Name = $menu_prefix. "_Date";
commit cc38e6f475c9293fddfbe35eb9452a17ed8a5835
Author: sunnavy <sunnavy at bestpractical.com>
Date: Tue Apr 3 12:38:05 2012 +0800
allow to delete a cf date value
as now empty cf date input means delete only
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index a9286f8..378b5c4 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -3089,9 +3089,6 @@ sub _ProcessObjectCustomFieldUpdates {
$values_hash{$val} = 1 if $val;
}
- # For Date Cfs, @values is empty when there is no changes (no datas in form input)
- return @results if ( $cf->Type =~ /^Date(?:Time)?$/ && ! @values );
-
$cf_values->RedoSearch;
while ( my $cf_value = $cf_values->Next ) {
next if $values_hash{ $cf_value->id };
commit abc11fa29db0ce3337784316b1b8f97a5f0886b4
Author: sunnavy <sunnavy at bestpractical.com>
Date: Fri Jun 22 23:28:50 2012 +0800
keep values of ticket core date fields too
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 378b5c4..5576d9e 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -3320,23 +3320,29 @@ sub ProcessTicketDates {
#Run through each field in this list. update the value if apropriate
foreach my $field (@date_fields) {
next unless exists $ARGSRef->{ $field . '_Date' };
- next if $ARGSRef->{ $field . '_Date' } eq '';
+ my $obj = $field . "Obj";
+ my $method = "Set$field";
- my ( $code, $msg );
+ if ( $ARGSRef->{ $field . '_Date' } eq '' ) {
+ if ( $Ticket->$obj->Unix ) {
+ my ( $code, $msg ) = $Ticket->$method( '1970-01-01 00:00:00' );
+ push @results, $msg;
+ }
+ }
+ else {
- my $DateObj = RT::Date->new( $session{'CurrentUser'} );
- $DateObj->Set(
- Format => 'unknown',
- Value => $ARGSRef->{ $field . '_Date' }
- );
+ my $DateObj = RT::Date->new( $session{'CurrentUser'} );
+ $DateObj->Set(
+ Format => 'unknown',
+ Value => $ARGSRef->{ $field . '_Date' }
+ );
- my $obj = $field . "Obj";
- if ( ( defined $DateObj->Unix )
- and ( $DateObj->Unix != $Ticket->$obj()->Unix() ) )
- {
- my $method = "Set$field";
- my ( $code, $msg ) = $Ticket->$method( $DateObj->ISO );
- push @results, "$msg";
+ if ( ( defined $DateObj->Unix )
+ and ( $DateObj->Unix != $Ticket->$obj()->Unix() ) )
+ {
+ my ( $code, $msg ) = $Ticket->$method( $DateObj->ISO );
+ push @results, $msg;
+ }
}
}
diff --git a/share/html/Ticket/Elements/EditDates b/share/html/Ticket/Elements/EditDates
index a410ceb..339e4be 100644
--- a/share/html/Ticket/Elements/EditDates
+++ b/share/html/Ticket/Elements/EditDates
@@ -48,12 +48,17 @@
<table>
<tr>
<td class="label"><&|/l&>Starts</&>:</td>
- <td class="entry"><& /Elements/SelectDate, menu_prefix => 'Starts', current => 0 &>
- (<% $TicketObj->StartsObj->AsString %>)</td>
+ <td class="entry">
+ <& /Elements/SelectDate, menu_prefix => 'Starts', current => 0, Default => $TicketObj->StartsObj->Unix ? $TicketObj->StartsObj->ISO( Timezone => 'user' ) : '' &>
+ (<% $TicketObj->StartsObj->AsString %>)
+ </td>
</tr>
<tr>
<td class="label"><&|/l&>Started</&>:</td>
- <td class="entry"><& /Elements/SelectDate, menu_prefix => 'Started', current => 0 &> (<%$TicketObj->StartedObj->AsString %>)</td>
+ <td class="entry">
+ <& /Elements/SelectDate, menu_prefix => 'Started', current => 0, Default => $TicketObj->StartedObj->Unix ? $TicketObj->StartedObj->ISO( Timezone => 'user' ) : '' &>
+ (<%$TicketObj->StartedObj->AsString %>)
+ </td>
</tr>
<tr>
@@ -61,13 +66,15 @@
<&|/l&>Last Contact</&>:
</td>
<td class="entry">
- <& /Elements/SelectDate, menu_prefix => 'Told', current => 0 &> (<% $TicketObj->ToldObj->AsString %>)
+ <& /Elements/SelectDate, menu_prefix => 'Told', current => 0, Default => $TicketObj->ToldObj->Unix ? $TicketObj->ToldObj->ISO(Timezone => 'user') : '' &>
+ (<% $TicketObj->ToldObj->AsString %>)
</td>
</tr>
<tr>
<td class="label"><&|/l&>Due</&>:</td>
<td class="entry">
- <& /Elements/SelectDate, menu_prefix => 'Due', current => 0 &> (<% $TicketObj->DueObj->AsString %>)
+ <& /Elements/SelectDate, menu_prefix => 'Due', current => 0, Default => $TicketObj->DueObj->Unix ? $TicketObj->DueObj->ISO(Timezone => 'user') : '' &>
+ (<% $TicketObj->DueObj->AsString %>)
</td>
</tr>
<& /Elements/EditCustomFields, Object => $TicketObj, Grouping => 'Dates', InTable => 1 &>
commit bda2b8df22374c85912c82184760630bc3cca3fa
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Mon Dec 10 16:01:45 2012 -0500
Remove unused Value argument to SelectDate
8fea92b added Value to the arguments. However, the issues ticket it
references claims that it's so Ticket/Create.html is sticky -- but as of
8fea92b, Ticket/Create.html was passing SelectDate Default =>, not Value
=>. Ticket/Create.html, the one call site which passed Value =>, was
fixed to use the standard Default in a00a733, prior to 8fea92b.
diff --git a/share/html/Elements/SelectDate b/share/html/Elements/SelectDate
index a237797..bf02055 100644
--- a/share/html/Elements/SelectDate
+++ b/share/html/Elements/SelectDate
@@ -46,7 +46,7 @@
%#
%# END BPS TAGGED BLOCK }}}
% $m->callback( %ARGS, Name => $Name, CallbackName => 'BeforeDateInput' );
-<input type="text" class="datepicker<% $ShowTime ? ' withtime' : '' %>" id="<% $Name %>" name="<% $Name %>" value="<% $Value %>" size="<% $Size %>" />
+<input type="text" class="datepicker<% $ShowTime ? ' withtime' : '' %>" id="<% $Name %>" name="<% $Name %>" value="<% $Default %>" size="<% $Size %>" />
% $m->callback( %ARGS, Name => $Name, CallbackName => 'AfterDateInput' );
<%init>
unless ((defined $Default) or ($current <= 0)) {
@@ -56,7 +56,7 @@ unless ((defined $Default) or ($current <= 0)) {
$year+1900,$mon+1,$mday,
$hour,$min);
}
-$Value = $Value || $Default || '';
+$Default ||= '';
unless ($Name) {
$Name = $menu_prefix. "_Date";
@@ -69,7 +69,6 @@ $ShowTime => 1
$menu_prefix=>''
$current=>time
$Default => ''
-$Value => ''
$Name => undef
$Size => 16
</%args>
commit d408f862ca01e7085fc20472966deea2751f72d0
Author: sunnavy <sunnavy at bestpractical.com>
Date: Sun Aug 18 01:17:34 2013 +0800
check if it's necessary to add custom field value before actually adding it.
if a user inputs 0 as a Date cf value, we should not add it as the new value,
since it means "not set", as it does in ticket's core date fields.
diff --git a/lib/RT/Action/CreateTickets.pm b/lib/RT/Action/CreateTickets.pm
index 8817adb..37f5bb7 100644
--- a/lib/RT/Action/CreateTickets.pm
+++ b/lib/RT/Action/CreateTickets.pm
@@ -1128,7 +1128,10 @@ sub UpdateCustomFields {
}
foreach my $value (@values) {
- next unless length($value);
+ next if $ticket->CustomFieldValueIsEmpty(
+ Field => $cf,
+ Value => $value,
+ );
my ( $val, $msg ) = $ticket->AddCustomFieldValue(
Field => $cf,
Value => $value
diff --git a/lib/RT/Article.pm b/lib/RT/Article.pm
index 78a9fb0..524d3b4 100644
--- a/lib/RT/Article.pm
+++ b/lib/RT/Article.pm
@@ -134,6 +134,10 @@ sub Create {
my $cf = $1;
my @vals = ref( $args{$key} ) eq 'ARRAY' ? @{ $args{$key} } : ( $args{$key} );
foreach my $value (@vals) {
+ next if $self->CustomFieldValueIsEmpty(
+ Field => $cf,
+ Value => $value,
+ );
my ( $cfid, $cfmsg ) = $self->_AddCustomFieldValue(
(UNIVERSAL::isa( $value => 'HASH' )
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 5576d9e..acf8a90 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -3039,6 +3039,10 @@ sub _ProcessObjectCustomFieldUpdates {
if ( $arg eq 'AddValue' || $arg eq 'Value' ) {
foreach my $value (@values) {
+ next if $args{'Object'}->CustomFieldValueIsEmpty(
+ Field => $cf->id,
+ Value => $value,
+ );
my ( $val, $msg ) = $args{'Object'}->AddCustomFieldValue(
Field => $cf->id,
Value => $value
@@ -3081,6 +3085,11 @@ sub _ProcessObjectCustomFieldUpdates {
next;
}
+ next if $args{'Object'}->CustomFieldValueIsEmpty(
+ Field => $cf,
+ Value => $value,
+ );
+
my ( $val, $msg ) = $args{'Object'}->AddCustomFieldValue(
Field => $cf,
Value => $value
@@ -3542,6 +3551,11 @@ sub ProcessRecordBulkCustomFields {
}
elsif ( $op eq 'Add' && !$current_values->HasEntry($value) ) {
+ next if $args{'RecordObj'}->CustomFieldValueIsEmpty(
+ Field => $cfid,
+ Value => $value,
+ );
+
my ( $id, $msg ) = $args{'RecordObj'}->AddCustomFieldValue(
Field => $cfid,
Value => $value
diff --git a/lib/RT/Record.pm b/lib/RT/Record.pm
index e375160..bc64dca 100644
--- a/lib/RT/Record.pm
+++ b/lib/RT/Record.pm
@@ -2070,7 +2070,41 @@ sub _AddCustomFieldValue {
}
}
+=head2 CustomFieldValueIsEmpty { Field => FIELD, Value => VALUE }
+Check if the custom field value is empty.
+
+Some custom fields could have other special empty values, e.g. "1970-01-01" is empty for Date cf
+
+Return 1 if it is empty, 0 otherwise.
+
+=cut
+
+
+sub CustomFieldValueIsEmpty {
+ my $self = shift;
+ my %args = (
+ Field => undef,
+ Value => undef,
+ @_
+ );
+ my $value = $args{Value};
+ return 1 unless defined $value && length $value;
+
+ my $cf = $self->LoadCustomFieldByIdentifier( $args{'Field'} );
+ if ($cf) {
+ if ( $cf->Type =~ /^Date(?:Time)?$/ ) {
+ my $DateObj = RT::Date->new( $self->CurrentUser );
+ $DateObj->Set(
+ Format => 'unknown',
+ Value => $value,
+ $cf->Type eq 'Date' ? ( Timezone => 'UTC' ) : (),
+ );
+ return 1 unless $DateObj->Unix;
+ }
+ }
+ return 0;
+}
=head2 DeleteCustomFieldValue { Field => FIELD, Value => VALUE }
diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index 2a41074..a1de5c6 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -474,7 +474,10 @@ sub Create {
foreach my $value (
UNIVERSAL::isa( $args{$arg} => 'ARRAY' ) ? @{ $args{$arg} } : ( $args{$arg} ) )
{
- next unless defined $value && length $value;
+ next if $self->CustomFieldValueIsEmpty(
+ Field => $cfid,
+ Value => $value,
+ );
# Allow passing in uploaded LargeContent etc by hash reference
my ($status, $msg) = $self->_AddCustomFieldValue(
diff --git a/lib/RT/Transaction.pm b/lib/RT/Transaction.pm
index 81a3dc7..bb702cb 100644
--- a/lib/RT/Transaction.pm
+++ b/lib/RT/Transaction.pm
@@ -1387,7 +1387,10 @@ sub UpdateCustomFields {
foreach
my $value ( UNIVERSAL::isa( $values, 'ARRAY' ) ? @$values : $values )
{
- next unless (defined($value) && length($value));
+ next if $self->CustomFieldValueIsEmpty(
+ Field => $cfid,
+ Value => $value,
+ );
$self->_AddCustomFieldValue(
Field => $cfid,
Value => $value,
diff --git a/share/html/REST/1.0/Forms/ticket/default b/share/html/REST/1.0/Forms/ticket/default
index 2abf8e8..8252078 100644
--- a/share/html/REST/1.0/Forms/ticket/default
+++ b/share/html/REST/1.0/Forms/ticket/default
@@ -392,7 +392,7 @@ else {
else {
my $vals = $ticket->CustomFieldValues($cf->id);
- if ( !defined $val || !length $val ) {
+ if ( $ticket->CustomFieldValueIsEmpty( Field => $cf, Value => $val ) ) {
while ( my $val = $vals->Next ) {
($n, $s) = $ticket->DeleteCustomFieldValue(
Field => $cf, ValueId => $val->id,
@@ -452,6 +452,10 @@ else {
}
for ( @new ) {
while ( $new{$_} && $new{$_}-- ) {
+ next if $ticket->CustomFieldValueIsEmpty(
+ Field => $cf,
+ Value => $_,
+ );
($n, $s) = $ticket->AddCustomFieldValue(
Field => $cf, Value => $_ );
$s =~ s/^# // if defined $s;
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list