fix 11432 DataTable date input

This commit is contained in:
Doug Bell 2010-08-10 14:05:35 -05:00
parent 731ae3801a
commit 625da8bb41
4 changed files with 39 additions and 1 deletions

View file

@ -142,6 +142,26 @@ sub getDataTemplateVars {
#----------------------------------------------------------------------------
=head2 getDateFormat ( )
Get the current date format for the current user in a strftime format that YUI can
understand.
=cut
sub getDateFormat {
my ( $self ) = @_;
my $dateFormat
= WebGUI::DateTime->new( $self->session )->webguiToStrftime( $self->session->user->get('dateFormat') );
# Special handle %_varmonth_ super special WebGUI field that strftime doesn't have
$dateFormat =~ s/%_varmonth_/%m/g;
return $dateFormat;
}
#----------------------------------------------------------------------------
=head2 getEditForm ( )
Add the data table to the edit form.
@ -161,6 +181,7 @@ sub getEditForm {
value => $self->get("data"),
defaultValue => undef,
showEdit => 1,
dateFormat => $self->getDateFormat,
}
)->toHtml
. q{</td></tr>}
@ -225,6 +246,7 @@ sub prepareView {
name => $self->getId,
value => $self->get('data'),
defaultValue => undef,
dateFormat => $self->getDateFormat,
}
);
$dt->prepare;

View file

@ -68,6 +68,10 @@ Any extra name=value pairs needed to save the data successfully
If true, will enable the table for editing. This is only necessary when
displaying the table with getValueAsHtml().
=head4 dateFormat
A strftime string describing the proper date format
=cut
sub definition {
@ -81,6 +85,7 @@ sub definition {
ajaxSaveUrl => { defaultValue => undef, },
ajaxSaveFunc => { defaultValue => "view", },
ajaxSaveExtras => { defaultValue => undef, },
dateFormat => { defaultValue => '%y-%m-%d', },
};
return $class->SUPER::definition( $session, $definition );
@ -116,6 +121,8 @@ sub getDataTableHtml {
textbox => "textbox",
);
my $dateFormat = $self->get('dateFormat') || '%y-%m-%d';
my @columnsJson = ();
for my $column ( @{ $data->{columns} } ) {
@ -125,6 +132,7 @@ sub getDataTableHtml {
. qq["key" : "$column->{ key }", ]
. qq["abbr" : "$column->{ key }", ]
. qq["formatter" : "$column->{ formatter }", ]
. ( $column->{formatter} eq "Date" ? qq["dateOptions" : { "format" : "$dateFormat" },] : "" )
. qq["resizable" : 1, ]
. qq["sortable" : 1];
@ -155,6 +163,7 @@ sub getDataTableHtml {
"ajaxDataFunc" => $self->get('ajaxDataFunc'),
"ajaxSaveUrl" => $self->get('ajaxSaveUrl'),
"ajaxSaveFunc" => $self->get('ajaxSaveFunc'),
"dateFormat" => $dateFormat,
};
my $optionsJson = JSON->new->encode($options);