X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=lib%2FMaypole%2FModel%2FCDBI%2FAsForm.pm;h=a5296cd2bbe9be9e8f8057c3d4424e2003c2b06f;hb=2c41363d0f5abf35c8d642db4b837f52f5954b2c;hp=59bf438196eba292b995f519558a34e95a017425;hpb=883d0367cf16313f19a9747df2e1d2e16ea75fb5;p=maypole.git diff --git a/lib/Maypole/Model/CDBI/AsForm.pm b/lib/Maypole/Model/CDBI/AsForm.pm index 59bf438..a5296cd 100644 --- a/lib/Maypole/Model/CDBI/AsForm.pm +++ b/lib/Maypole/Model/CDBI/AsForm.pm @@ -11,7 +11,6 @@ package Maypole::Model::CDBI::AsForm; # -- $class->to_field($has_many_col); # foreign inputs # $class->search_inputs; / -use 5.006; use strict; use warnings; @@ -35,14 +34,6 @@ our @EXPORT = _options_from_array _options_from_hash _to_select_or_create ); -our @EXPORTOK = - qw( - - - ); - - - our $VERSION = '.10'; =head1 NAME @@ -118,6 +109,8 @@ example usages. 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. $beer->to_field('brewery', 'readonly', { @@ -205,6 +198,7 @@ static values. You can also specify these in the relationship arguments. Tell AsForm not to make hidden inputs for relationship constraints. It does this sometimes when making foreign inputs . +=back =head2 to_cgi @@ -363,7 +357,12 @@ sub search_inputs { -# + +=head2 unselect_element + + unselect any selected elements in a HTML::Element select list widget + +=cut sub unselect_element { my ($self, $el) = @_; #unless (ref $el eq 'HTML::Element') { @@ -940,13 +939,13 @@ sub _to_link_hidden { $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}); - $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; @@ -957,8 +956,6 @@ sub _to_link_hidden { $a; } - - =head2 _to_foreign_inputs $html_els = $class_or_obj->_to_foreign_inputs($accssr, [$fields, $accssr_meta]); @@ -1112,9 +1109,20 @@ sub _select_guts { 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++; + } + } # Single Hash - if ($type eq 'HASH') { + elsif ($type eq 'HASH') { $a->push_content($self->_options_from_hash($items, $args)); } # Single Array @@ -1144,12 +1152,6 @@ sub _select_guts { } - - - - - - =head2 _options_from_objects ( $objects, $args); Private method to makes a options out of objects. It attempts to call each @@ -1238,7 +1240,7 @@ sub _options_from_hashes { my $val = $_->{$pk}; my $opt = HTML::Element->new("option", value => $val ); $opt->attr(selected => "selected") if $selected->{$val}; - my $content = $fclass and $stringify and $fclass->can($stringify) ? + my $content = ($fclass and $stringify and $fclass->can($stringify)) ? $fclass->$stringify($_) : join(' ', @$_); $opt->push_content( $content ); @@ -1255,11 +1257,8 @@ sub _to_select_or_create { my $create = $self->to_field($col, 'foreign_inputs', $args); $create->{'__select_or_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 @@ -1273,7 +1272,6 @@ sub _to_select_or_create { sub _to_checkbox { my ($self, $col, $args) = @_; my $nullable = eval {self->column_nullable($col)} || 0; - return $self->_to_radio($col) if !ref($self) || $nullable; my $value = $self->$col; my $a = HTML::Element->new("input", type=> "checkbox", name => $col);