Added optgroups arg so to_select can group items in optgroups. Still needs docs.
git-svn-id: http://svn.maypole.perl.org/Maypole/trunk@477
48953598-375a-da11-a14b-
00016c27c3ee
# -- $class->to_field($has_many_col); # foreign inputs
# $class->search_inputs; /
# -- $class->to_field($has_many_col); # foreign inputs
# $class->search_inputs; /
use strict;
use warnings;
use strict;
use warnings;
_options_from_objects _options_from_arrays _options_from_hashes
_options_from_array _options_from_hash _to_select_or_create
);
_options_from_objects _options_from_arrays _options_from_hashes
_options_from_array _options_from_hash _to_select_or_create
);
$beer->to_field($col, $args);
Not all _to_* methods pay attention to all arguments. For example, '_to_textfield' does not look in $args->{'items'} at all.
$beer->to_field($col, $args);
Not all _to_* methods pay attention to all arguments. For example, '_to_textfield' does not look in $args->{'items'} at all.
=over
=item name -- the name the element will have , this trumps the derived name.
=over
=item name -- the name the element will have , this trumps the derived name.
$beer->to_field('brewery', 'readonly', {
name => 'brewery_id'
});
$beer->to_field('brewery', 'readonly', {
name => 'brewery_id'
});
=item value -- the initial value the element will have, trumps derived value
$beer->to_field('brewery', 'textfield', {
=item value -- the initial value the element will have, trumps derived value
$beer->to_field('brewery', 'textfield', {
constraint => {location => 'London'},
'join' => {'brewery_tablecolumn => 'beer_obj_column'},
);
constraint => {location => 'London'},
'join' => {'brewery_tablecolumn => 'beer_obj_column'},
);
=item no_hidden_constraints --
Tell AsForm not to make hidden inputs for relationship constraints. It does
=item no_hidden_constraints --
Tell AsForm not to make hidden inputs for relationship constraints. It does
- unselect any selected elemets in a HTML::Element select list widget
+ unselect any selected elements in a HTML::Element select list widget
sub unselect_element {
my ($self, $el) = @_;
#unless (ref $el eq 'HTML::Element') {
sub unselect_element {
my ($self, $el) = @_;
#unless (ref $el eq 'HTML::Element') {
=head2 _field_from_column($field, $args)
Returns an input based on the column's characteristics, namely type, or nothing.
=head2 _field_from_column($field, $args)
Returns an input based on the column's characteristics, namely type, or nothing.
$name = $args->{name} || $obj->primary_column->name;
}
elsif ($obj = $args->{items}->[0]) {
$name = $args->{name} || $obj->primary_column->name;
}
elsif ($obj = $args->{items}->[0]) {
- # cool)
- $name = $args->{name} || $obj->primary_column->name; # TODO make use meta data
+ $name = $args->{name} || $accessor || $obj->primary_column->name;
+ # TODO use meta data above maybe
else { # hiding linking related object with id in args
$obj = $self->related_class($r, $accessor)->retrieve($args->{id});
else { # hiding linking related object with id in args
$obj = $self->related_class($r, $accessor)->retrieve($args->{id});
- $name = $args->{name} || $obj->primary_column->name; # TODO make use meta data
+ $name = $args->{name} || $accessor ; #$obj->primary_column->name;
+ # TODO use meta data above maybe
}
$self->_croak("_to_link_hidden has no object") unless ref $obj;
my $href = $uri || $r->config->{uri_base} . "/". $obj->table."/view/".$obj->id;
}
$self->_croak("_to_link_hidden has no object") unless ref $obj;
my $href = $uri || $r->config->{uri_base} . "/". $obj->table."/view/".$obj->id;
=head2 _to_foreign_inputs
$html_els = $class_or_obj->_to_foreign_inputs($accssr, [$fields, $accssr_meta]);
=head2 _to_foreign_inputs
$html_els = $class_or_obj->_to_foreign_inputs($accssr, [$fields, $accssr_meta]);
my $items = $args->{items};
my $type = ref $items;
my $proto = eval { ref $items->[0]; } || "";
my $items = $args->{items};
my $type = ref $items;
my $proto = eval { ref $items->[0]; } || "";
- warn "Type is $type, proto is $proto\n";
+ my $optgroups = $args->{optgroups} || '';
+
+ # Array of hashes, one for each optgroup
+ if ($optgroups) {
+ my $i = 0;
+ foreach (@$optgroups) {
+ my $ogrp= HTML::Element->new('optgroup', label => $_);
+ $ogrp->push_content($self->_options_from_hash($items->[$i], $args));
+ $a->push_content($ogrp);
+ $i++;
+ }
+ }
+ elsif ($type eq 'HASH') {
$a->push_content($self->_options_from_hash($items, $args));
}
# Single Array
$a->push_content($self->_options_from_hash($items, $args));
}
# Single Array
}
=head2 _options_from_objects ( $objects, $args);
}
=head2 _options_from_objects ( $objects, $args);
$self->to_field('__select_or_create__',{ name => '__select_or_create__' , value => 1 } );
return ($select, $create);
}
$self->to_field('__select_or_create__',{ name => '__select_or_create__' , value => 1 } );
return ($select, $create);
}
#
# checkboxes: if no data in hand (ie called as class method), replace
# with a radio button, in order to allow this field to be left
#
# checkboxes: if no data in hand (ie called as class method), replace
# with a radio button, in order to allow this field to be left
foreach (keys %$element);
}
}
foreach (keys %$element);
}
}
This functions computes the dimensions of a textarea based on the value
or the defaults.
This functions computes the dimensions of a textarea based on the value
or the defaults.
=cut
our ($min_rows, $max_rows, $min_cols, $max_cols) = (2 => 50, 20 => 100);
=cut
our ($min_rows, $max_rows, $min_cols, $max_cols) = (2 => 50, 20 => 100);
sub _box
{
my $text = shift;
sub _box
{
my $text = shift;
push(@output,
(
$r->model_class
push(@output,
(
$r->model_class
- && File::Spec->catdir( $path, $r->model_class->moniker )
+ && File::Spec->catdir( $path, $r->model_class->table )
)
);
push(@output, File::Spec->catdir( $path, "custom" ));
)
);
push(@output, File::Spec->catdir( $path, "custom" ));