[Rt-commit] rt branch, 4.2/date-input-keep-value, created. rt-4.1.19-112-g7c9263b

? sunnavy sunnavy at bestpractical.com
Wed Sep 4 12:25:28 EDT 2013


The branch, 4.2/date-input-keep-value has been created
        at  7c9263b507540ca02e7ebf5f09d392669ca4c3d4 (commit)

- Log -----------------------------------------------------------------
commit 241a6ef9e84779d0970cc3e9dba73313c16d7d01
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/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..229fc1a 100644
--- a/share/html/Elements/EditCustomFieldDateTime
+++ b/share/html/Elements/EditCustomFieldDateTime
@@ -46,7 +46,7 @@
 %#
 %# 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'} );
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 7497a7f397713ec3fde78105ff5a9b56bdccd633
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 1ce71e5..d381fb4 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -3082,9 +3082,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 edf403f81003bbfd605889276ef54bf89c1c64b0
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 d381fb4..a00b956 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -3313,23 +3313,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 5c468e1834c359da28bc99959408bcdc3330a2e6
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 7c9263b507540ca02e7ebf5f09d392669ca4c3d4
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 a00b956..547193a 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
@@ -3074,6 +3078,11 @@ sub _ProcessObjectCustomFieldUpdates {
                     next;
                 }
 
+                next if $args{'Object'}->CustomFieldValueIsEmpty(
+                    Field => $cf,
+                    Value => $value,
+                );
+
                 my ( $val, $msg ) = $args{'Object'}->AddCustomFieldValue(
                     Field => $cf,
                     Value => $value
@@ -3535,6 +3544,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