Skip to content

Commit

Permalink
changed formatDate to dateFormat in Date/DateTime elements
Browse files Browse the repository at this point in the history
PerlTidy code
overwrite ability added to "record" and "column_model"

git-svn-id: http://html-formfu.googlecode.com/svn/trunk/HTML-FormFu-ExtJS@1572 ad6ea75e-0b29-0410-be19-adbfd45e731a
  • Loading branch information
monken committed Aug 3, 2009
1 parent b500751 commit ffe4e23
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 71 deletions.
8 changes: 4 additions & 4 deletions lib/HTML/FormFu/ExtJS/Element/Date.pm
Expand Up @@ -23,15 +23,15 @@ sub render {
sub record {
my $class = shift;
my $self = shift;
my $super = $class->SUPER::record($self);
my $super = $class->SUPER::record($self, @_);
return {%{$super}, type => "date", dateFormat => 'Y-m-d'}
}

sub column_model {
my $class = shift;
my $self = shift;
my $super = $class->SUPER::column_model($self);
my $format = $self->attrs->{format_date} || $self->attrs_xml->{format_date} || 'Y-m-d';
my $super = $class->SUPER::column_model($self, @_);
my $format = $super->{dateFormat} || 'Y-m-d';
return {%{$super}, renderer => \('Ext.util.Format.dateRenderer("'.$format.'")') }
}

Expand All @@ -54,7 +54,7 @@ to a more readable version depending on your locale.
=head2 column_model
To change the format of the date object specify C<< $element->attrs->{format_data} >>.
To change the format of the date object specify C<< $element->attrs->{dateFormat} >>.
The date parsing and format syntax is a subset of PHP's date() function.
See L<http://extjs.com/deploy/dev/docs/?class=Date> for details.
It defaults to C<Y-m-d> (which is the same as Perl's C<%Y-%m-%d>).
Expand Down
8 changes: 4 additions & 4 deletions lib/HTML/FormFu/ExtJS/Element/DateTime.pm
Expand Up @@ -27,15 +27,15 @@ sub render {
sub record {
my $class = shift;
my $self = shift;
my $super = $class->SUPER::record($self);
my $super = $class->SUPER::record($self, @_);
return {%{$super}, type => "date", dateFormat => 'Y-m-d G:i'}
}

sub column_model {
my $class = shift;
my $self = shift;
my $super = $class->SUPER::column_model($self);
my $format = $self->attrs->{format_date} || $self->attrs_xml->{format_date} || 'Y-m-d G:i';
my $super = $class->SUPER::column_model($self, @_);
my $format = $self->attrs->{dateFormat} || $self->attrs_xml->{dateFormat} || 'Y-m-d G:i';
return {%{$super}, renderer => \('Ext.util.Format.dateRenderer("'.$format.'")') }
}

Expand All @@ -53,7 +53,7 @@ You cannot put this element in a multi element because it is one itself.
=head2 column_model
To change the format of the date object specify C<< $element->attrs->{format_data} >>.
To change the format of the date object specify C<< $element->attrs->{dateFormat} >>.
The date parsing and format syntax is a subset of PHP's date() function.
See L<http://extjs.com/deploy/dev/docs/?class=Date> for details.
It defaults to C<Y-m-d G:i> (which is the same as Perl's C<%Y-%m-%d %R>).
Expand Down
97 changes: 38 additions & 59 deletions lib/HTML/FormFu/ExtJS/Element/_Field.pm
Expand Up @@ -5,79 +5,64 @@ use warnings;
use utf8;

use HTML::FormFu::Util qw(
xml_escape
xml_escape
);
use HTML::FormFu::ExtJS::Util qw(
_camel_case
_css_case
_camel_case
_css_case
);


sub render {
my $class = shift;
my $self = shift;
my $parent = $self->can("_get_attributes") ? $self : $self->form;
my $value = $self->default;
map { $value = $_->process($value) } @{$self->get_deflators};

return {
fieldLabel => xml_escape( $self->label ),
hideLabel => $self->label ? \0 : \1,
(scalar $self->id) ? (id => scalar $self->id) : (),
$self->nested_name ? (name => $self->nested_name) : (),
defined $self->default ? (value => $value) : (),
$parent->_get_attributes($self)
};
}
my $class = shift;
my $self = shift;
my $parent = $self->can("_get_attributes") ? $self : $self->form;
my $value = $self->default;
map { $value = $_->process($value) } @{ $self->get_deflators };

return {
fieldLabel => xml_escape( $self->label ),
hideLabel => $self->label ? \0 : \1,
( scalar $self->id ) ? ( id => scalar $self->id ) : (),
$self->nested_name ? ( name => $self->nested_name ) : (),
defined $self->default ? ( value => $value ) : (),
$parent->_get_attributes($self)
};
}

=head2 record
C<record> returns a HashRef with contains all informations to create a record
field from this field element.
$class->record( $element, { force_type => 'int', defaultValue => 10 } );
$class->record( $element );
The arguments hash understands:
You can override the default values by passing an extra hashref.
= head3 only_name
Use just the elements name, not it's nested name.
This is needed for custom clientside processing of repeatable elements.
$class->record( $element, { mapping => 'myname', type => 'mytype' } );
= head3 force_type
Used to set an other record field type, than the default 'string'.
= head3 defaultValue
Used to set the default value in the record field.
=cut

sub record {
my $class = shift;
my $self = shift;
my %args = (
only_name => 0,
force_type => undef,
defaultValue => undef,
@_
);

my $name = $args{only_name} ? $self->name : $self->nested_name;
my $class = shift;
my $self = shift;
my %args = %{ shift || {} };

my $name = $self->nested_name;
return {
name => _camel_case($name),
mapping => $name,
type => (defined $args{force_type} && length $args{force_type}) ? $args{force_type} : "string",
(defined $args{defaultValue}) ? (defaultValue => $args{defaultValue}) : ()
mapping => $self->nested_name,
type => "string",
%args
};
}


=head2 column_model
C<column_model> returns a HashRef with contains all informations to create an
entry for a column model from this field element.
$class->column_model( $element, { only_name => 1 } );
$class->column_model( $element );
All attributes that were given to the element configuration are added to the
column model:
Expand All @@ -86,31 +71,25 @@ column model:
attrs:
width: 150
You can override the defaults by passing a hashref:
The arguments hash understands:
= head3 only_name
Use just the elements name, not it's nested name.
This is needed for custom clientside processing of repeatable elements.
$class->column_model( $element, { dataIndex => 'myIndex' } );
=cut

sub column_model {
my $class = shift;
my $self = shift;
my %args = (
only_name => 0,
@_
);
my $parent = $self->can("_get_attributes") ? $self : $self->form;
my $class = shift;
my $self = shift;
my %args = %{ shift || {} };

my $data_index = $args{only_name} ? $self->name : $self->nested_name;
my $data_index = $self->nested_name;

return {
id => _css_case($data_index),
dataIndex => _camel_case($data_index),
header => scalar $self->label || scalar $self->name,
$parent->_get_attributes($self)
$self->form->_get_attributes($self),
%args
};
}

Expand Down
10 changes: 8 additions & 2 deletions t/08-grid_record.t
Expand Up @@ -6,6 +6,12 @@ use warnings;

my $form = new HTML::FormFu::ExtJS;
$form->load_config_file("t/01-text.yml");
is_deeply( $form->_record , [{name => "test", type => "string", mapping => "test"}, {mapping => "test2", name => "test2", type => "string"}]);
is_deeply(
$form->_record,
[
{ name => "test", type => "string", mapping => "test" },
{ mapping => "test2", name => "test2", type => "string" }
]
);

ok($form->render_items);
ok( $form->render_items );
2 changes: 1 addition & 1 deletion t/column_model/01-basic.t
Expand Up @@ -19,7 +19,7 @@ is_deeply( $form->_column_model, [
'id' => 'created',
'renderer' => \'Ext.util.Format.dateRenderer("d.m.Y")',
'header' => 'Created',
'formatDate' => 'd.m.Y'
'dateFormat' => 'd.m.Y'
},
{
'dataIndex' => 'sexValue',
Expand Down
2 changes: 1 addition & 1 deletion t/column_model/01-basic.yml
Expand Up @@ -8,7 +8,7 @@
label: Created
default_natural: today
attrs:
formatDate: d.m.Y
dateFormat: d.m.Y
- type: Radiogroup
label: Sex
name: sex
Expand Down

0 comments on commit ffe4e23

Please sign in to comment.