From: biopete Date: Thu, 13 Apr 2006 16:45:07 +0000 (+0000) Subject: Changed View so it uses table name rather than class moniker in template paths. X-Git-Tag: 2.11~43 X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=2c41363d0f5abf35c8d642db4b837f52f5954b2c;p=maypole.git Changed View so it uses table name rather than class moniker in template paths. 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 --- diff --git a/lib/Maypole/Model/CDBI/AsForm.pm b/lib/Maypole/Model/CDBI/AsForm.pm index 66ccaf6..a5296cd 100644 --- a/lib/Maypole/Model/CDBI/AsForm.pm +++ b/lib/Maypole/Model/CDBI/AsForm.pm @@ -11,6 +11,7 @@ package Maypole::Model::CDBI::AsForm; # -- $class->to_field($has_many_col); # foreign inputs # $class->search_inputs; / + use strict; use warnings; @@ -32,8 +33,8 @@ our @EXPORT = _options_from_objects _options_from_arrays _options_from_hashes _options_from_array _options_from_hash _to_select_or_create ); - -our $VERSION = '.10'; + +our $VERSION = '.10'; =head1 NAME @@ -107,7 +108,7 @@ example usages. $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. @@ -115,7 +116,7 @@ Not all _to_* methods pay attention to all arguments. For example, '_to_textfiel $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', { @@ -191,7 +192,7 @@ static values. You can also specify these in the relationship arguments. 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 @@ -355,13 +356,13 @@ sub search_inputs { } + + =head2 unselect_element - unselect any selected elemets in a HTML::Element select list widget + unselect any selected elements in a HTML::Element select list widget =cut - -# sub unselect_element { my ($self, $el) = @_; #unless (ref $el eq 'HTML::Element') { @@ -460,8 +461,7 @@ sub _field_from_relationship { } return; } - - + =head2 _field_from_column($field, $args) Returns an input based on the column's characteristics, namely type, or nothing. @@ -939,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; @@ -956,8 +956,6 @@ sub _to_link_hidden { $a; } - - =head2 _to_foreign_inputs $html_els = $class_or_obj->_to_foreign_inputs($accssr, [$fields, $accssr_meta]); @@ -1111,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 @@ -1139,6 +1148,8 @@ sub _select_guts { } return $a; + + } =head2 _options_from_objects ( $objects, $args); @@ -1248,7 +1259,7 @@ sub _to_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 # with a radio button, in order to allow this field to be left @@ -1345,8 +1356,7 @@ sub _rename_foreign_input { foreach (keys %$element); } } - -=head2 _box($value) +=head2 _box($value) This functions computes the dimensions of a textarea based on the value or the defaults. @@ -1354,7 +1364,6 @@ or the defaults. =cut our ($min_rows, $max_rows, $min_cols, $max_cols) = (2 => 50, 20 => 100); - sub _box { my $text = shift; diff --git a/lib/Maypole/View/Base.pm b/lib/Maypole/View/Base.pm index a2718c4..3164c01 100644 --- a/lib/Maypole/View/Base.pm +++ b/lib/Maypole/View/Base.pm @@ -19,7 +19,7 @@ sub paths { 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" ));