display date custom fields as real dates, #23121
[freeside.git] / rt / share / html / Elements / ColumnMap
index 8afe4a1..878950b 100644 (file)
@@ -2,7 +2,7 @@
 %#
 %# COPYRIGHT:
 %#
-%# This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC
+%# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC
 %#                                          <sales@bestpractical.com>
 %#
 %# (Except where explicitly superseded by other copyright notices)
@@ -64,7 +64,7 @@ my $COLUMN_MAP = {
     Created => {
         attribute => 'Created',
         title     => 'Created', # loc
-        value     => sub { return $_[0]->CreatedObj->AsString }
+        value     => sub { return $_[0]->CreatedObj },
     },
     CreatedRelative => {
         attribute => 'Created',
@@ -72,14 +72,14 @@ my $COLUMN_MAP = {
         value     => sub { return $_[0]->CreatedObj->AgeAsString }
     },
     CreatedBy => {
-        attribute => 'CreatedBy',
+        attribute => 'Creator',
         title     => 'Created By', # loc
         value     => sub { return $_[0]->CreatorObj->Name }
     },
     LastUpdated => {
         attribute => 'LastUpdated',
         title     => 'Last Updated', # loc
-        value     => sub { return $_[0]->LastUpdatedObj->AsString }
+        value     => sub { return $_[0]->LastUpdatedObj },
     },
     LastUpdatedRelative => {
         attribute => 'LastUpdated',
@@ -99,15 +99,31 @@ my $COLUMN_MAP = {
             # Display custom field contents, separated by newlines.
             # For Image custom fields we also show a thumbnail here.
 
-            my $values = $_[0]->CustomFieldValues( $_[-1] );
-            my @values = map {
-                (
-                    ($_->CustomFieldObj->Type eq 'Image')
-                        ? \($m->scomp( '/Elements/ShowCustomFieldImage', Object => $_ ))
-                        : $_->Content
-                ),
-                \'<br />',
-            } @{ $values->ItemsArrayRef };
+            my $object = shift;
+            my $cfname = pop;
+            my $values = $object->CustomFieldValues( $cfname );
+            return if $values->Count == 0;
+            my @values;
+            # it is guaranteed to be the same type for all fields, right?
+            my $v = $values->First;
+            my $cftype = $v->CustomFieldObj->Type;
+
+            do {
+                if ($cftype eq 'Image') {
+                    push @values, 
+                        \($m->scomp( '/Elements/ShowCustomFieldImage',
+                                      Object => $v ));
+                } elsif ( $cftype eq 'Date' or $cftype eq 'DateTime' ) {
+                    # then actually return the date object;
+                    # ProcessColumnMapValue will stringify it
+                    my $DateObj = RT::Date->new( $session{'CurrentUser'} );
+                    $DateObj->Set(Format => 'unknown', Value => $v->Content);
+                    push @values, $DateObj;
+                } else {
+                    push @values, $v->Content;
+                }
+                push @values, \'<br />'; # this is deeply silly
+            } while ($v = $values->Next);
             pop @values; # Remove that last <br />
             return @values;
         },
@@ -116,19 +132,21 @@ my $COLUMN_MAP = {
     CheckBox => {
         title => sub {
             my $name = $_[1] || 'SelectedTickets';
-            my $checked = $m->request_args->{ $name .'All' }? 'checked="checked"': '';
+            my $checked = $DECODED_ARGS->{ $name .'All' }? 'checked="checked"': '';
 
-            return \qq{<input type="checkbox" name="${name}All" value="1" $checked
-                              onclick="setCheckbox(this.form, '$name', this.checked)" />};
+            return \qq{<input type="checkbox" name="}, $name, \qq{All" value="1" $checked
+                              onclick="setCheckbox(this.form, },
+                              $m->interp->apply_escapes($name,'j'),
+                              \qq{, this.checked)" />};
         },
         value => sub {
             my $id = $_[0]->id;
 
             my $name = $_[2] || 'SelectedTickets';
-            return \qq{<input type="checkbox" name="$name" value="$id" checked="checked" />}
-                if $m->request_args->{ $name . 'All'};
+            return \qq{<input type="checkbox" name="}, $name, \qq{" value="$id" checked="checked" />}
+                if $DECODED_ARGS->{ $name . 'All'};
 
-            my $arg = $m->request_args->{ $name };
+            my $arg = $DECODED_ARGS->{ $name };
             my $checked = '';
             if ( $arg && ref $arg ) {
                 $checked = 'checked="checked"' if grep $_ == $id, @$arg;
@@ -136,7 +154,7 @@ my $COLUMN_MAP = {
             elsif ( $arg ) {
                 $checked = 'checked="checked"' if $arg == $id;
             }
-            return \qq{<input type="checkbox" name="$name" value="$id" $checked />}
+            return \qq{<input type="checkbox" name="}, $name, \qq{" value="$id" $checked />}
         },
     },
     RadioButton => {
@@ -145,10 +163,10 @@ my $COLUMN_MAP = {
             my $id = $_[0]->id;
 
             my $name = $_[2] || 'SelectedTicket';
-            my $arg = $m->request_args->{ $name };
+            my $arg = $DECODED_ARGS->{ $name };
             my $checked = '';
             $checked = 'checked="checked"' if $arg && $arg == $id;
-            return \qq{<input type="radio" name="SelectedTicket" value="$id" $checked />};
+            return \qq{<input type="radio" name="}, $name, \qq{" value="$id" $checked />};
         },
     },
     (map {