X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=lib%2FMaypole%2FModel%2FCDBI%2FAsForm.pm;h=02403e006084d86ddcb4946586725291f482fcbd;hb=8d3f7b6c5612270c10042d8e0a9e52ad4ad54a46;hp=39cda98cd80f77a0cbceb0dc41201510d6ee153e;hpb=28823167d12d4cd1419cc6a58900c0fc5819e1af;p=maypole.git diff --git a/lib/Maypole/Model/CDBI/AsForm.pm b/lib/Maypole/Model/CDBI/AsForm.pm index 39cda98..02403e0 100644 --- a/lib/Maypole/Model/CDBI/AsForm.pm +++ b/lib/Maypole/Model/CDBI/AsForm.pm @@ -1,6 +1,12 @@ package Maypole::Model::CDBI::AsForm; -use 5.006; +#TODO -- + +# TESTED and Works -- +# has_many select -- $obj->to_field($has_many_col); # select one form many +# -- $class->to_field($has_many_col); # foreign inputs +# $class->search_inputs; / + use strict; use warnings; @@ -9,47 +15,22 @@ use base 'Exporter'; use Data::Dumper; use Class::DBI::Plugin::Type (); use HTML::Element; +use Carp qw/cluck/; our $OLD_STYLE = 0; # pjs -- Added new methods to @EXPORT -our @EXPORT = - qw( - to_cgi to_field _to_textarea _to_textfield _to_select +our @EXPORT = + qw( + to_cgi to_field foreign_input_delimiter search_inputs unselect_element + _field_from_how _field_from_relationship _field_from_column + _to_textarea _to_textfield _to_select _select_guts _to_foreign_inputs _to_enum_select _to_bool_select - _to_select_from_many _to_select_from_related _to_select_from_objs _to_hidden _to_link_hidden _rename_foreign_input _to_readonly _options_from_objects _options_from_arrays _options_from_hashes - _options_from_scalars - _field_from_how _field_from_relationship _field_from_column - _select_guts unselect_element search_inputs make_param_foreign + _options_from_array _options_from_hash ); -our $VERSION = '.09'; - -# 11-05-05 - added _to_link_hidden to make a link to the hidden object -# - fixed _to_hidden when called with no args. Hides self obj. -# 11-04-05 - _to_textfield: tries to call "deflate4edit" if column is has_a -# 11-08-05 - Changed Version to .08 - - - -# 1-10-06 -- fixed bug in to_textfiled that was stringifyingf CDBI objects -# # -# -# 1-20-06 - to_select - call db_Main with has a class. -# 1-24-06 - to_select_from_many now named _to_select_from_many . Old deprecated -# - hasmany_class removed in favor of model's related_class method. -# - took out do_select. That is a model action. -# - use search_columns instead of search_fields now. -# - use to_field('column', 'select', {args}) instead of a_select_box. -# -- took out make_hidden_element.was my own personal hack -# -- added _box from DH's FormView to calculate decent textarea size -# -- Refactor to_field into _from_* method calls. -# -# 1-25-06 -- Added _to_checkbox and _to_radio from FView -# 1-27-06 -- Refactored into yet more exported methods -# 1-28-06 -- select constraints where, join order by - +our $VERSION = '.95'; =head1 NAME @@ -72,51 +53,105 @@ Maypole::Model:CDBI::AsForm - Produce HTML form elements for database columns end_form; } - . . . somewhere use to_field($col, $how, $args) - package BeerDB::Pint; - __PACKAGE__->has_a('drinker', 'BeerDB::Drinker'); - __PACKAGE__->has_a('beer', 'BeerDB::Beer'); - package BeerDB::Drinker; - __PACKAGE__->has_many('pints', 'BeerDB::Pint'); - - # NEED to do mapping - my $sel = BeerDB::Drinker->to_field('pints', 'select') # multiple - my $sel = $Drunk->to_field('pints', 'select'); # Already had beers selected -package Job; + . . . -__PACKAGE__->has_a('employer' => 'Employer'); -__PACKAGE__->has_a('contact' => 'Contact') + # Somewhere else in a Maypole application about beer... -package Contact; -__PACKAGE__->has_a('employer_also' => 'Employer'); -__PACKAGE__->has_many('jobs' => 'Job', - { join => { employer => 'employer_also' }, - constraint => { 'finshed' => 0 }, - order_by => "created ASC", - } -); -package Employer; -__PACKAGE__->has_many('jobs' => 'Job',); -__PACKAGE__->has_many('contacts' => 'Contact', - order_by => 'name DESC', -); + $beer->to_field('brewery', 'textfield', { + name => 'brewery_id', value => $beer->brewery, + # however, no need to set value since $beer is object + }); + # Rate a beer + $beer->to_field(rating => select => { + items => [1 , 2, 3, 4, 5], + }); - # Below gives select boxes with the multiple attribute. - my $select_jobs_for_new_contact = - Contact->to_field('jobs', 'select'); # Uses constraint and order by + # Select a Brewery to visit in the UK + Brewery->to_field(brewery_id => { + items => [ Brewery->search_like(location => 'UK') ], + }); - my $edit_jobs_for_existing_contact = - $contact->to_field('jobs', 'select'); + # Make a select for a boolean field + $Pub->to_field('open' , { items => [ {'Open' => 1, 'Closed' => 0 } ] }); + $beer->to_field('brewery', { + selected => $beer->brewery, # again not necessary since caller is obj. + }); + + + $beer->to_field('brewery', 'link_hidden', {r => $r, uri => 'www.maypole.perl.org/brewery/view/'.$beer->brewery}); + # an html link that is also a hidden input to the object. R is required to + # make the uri unless you pass a uri + + + + ##################################################### + # Templates Usage + +