From 625da8bb416b3437372ec3f4b1cf0ab1de940074 Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Tue, 10 Aug 2010 14:05:35 -0500 Subject: [PATCH] fix 11432 DataTable date input --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset/Wobject/DataTable.pm | 22 +++++++++++++++++++ lib/WebGUI/Form/DataTable.pm | 9 ++++++++ www/extras/yui-webgui/build/form/datatable.js | 8 ++++++- 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index bf5d33982..3f1f17e9b 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -10,6 +10,7 @@ - fixed #11758: formatting on account stuff is wrong - fixed #11770: Starter needs to set all account plugins - fixed #11771: Default Newsletter template not set + - fixed #11432: DataTable date input 7.9.10 - fixed #11721: spamStopWords not in WebGUI.conf.original diff --git a/lib/WebGUI/Asset/Wobject/DataTable.pm b/lib/WebGUI/Asset/Wobject/DataTable.pm index 6dd346a37..38298f888 100644 --- a/lib/WebGUI/Asset/Wobject/DataTable.pm +++ b/lib/WebGUI/Asset/Wobject/DataTable.pm @@ -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{} @@ -225,6 +246,7 @@ sub prepareView { name => $self->getId, value => $self->get('data'), defaultValue => undef, + dateFormat => $self->getDateFormat, } ); $dt->prepare; diff --git a/lib/WebGUI/Form/DataTable.pm b/lib/WebGUI/Form/DataTable.pm index 1b4a44549..f1c12a1cb 100644 --- a/lib/WebGUI/Form/DataTable.pm +++ b/lib/WebGUI/Form/DataTable.pm @@ -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); diff --git a/www/extras/yui-webgui/build/form/datatable.js b/www/extras/yui-webgui/build/form/datatable.js index 514fe7409..d9f89b854 100644 --- a/www/extras/yui-webgui/build/form/datatable.js +++ b/www/extras/yui-webgui/build/form/datatable.js @@ -202,7 +202,10 @@ WebGUI.Form.DataTable YAHOO.util.Dom.get( this.containerId + "-table" ).style.display = "none"; } - var dataTableOptions = { }; + var dataTableOptions = { + dateOptions : { format : this.options.dateFormat } + }; + if ( this.options.showEdit ) { dataTableOptions.draggableColumns = true; } @@ -629,6 +632,9 @@ WebGUI.Form.DataTable sortable : ( col ? col.sortable : 1 ), editor : ( format == "date" ? "date" : "textbox") }; + if ( format == "date" ) { + newCol["dateOptions"] = { format : this.options.dateFormat }; + } var newIndex = col ? col.getKeyIndex() : undefined; this.dataTable.insertColumn( newCol, newIndex );