/[Frey]/trunk/lib/Frey/ObjectDesigner.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/lib/Frey/ObjectDesigner.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 113 - (show annotations)
Sun Jul 13 17:38:01 2008 UTC (14 years, 2 months ago) by dpavlin
File size: 1643 byte(s)
Single object designer skeleton
1 package Frey::ObjectDesigner;
2 use Moose;
3
4 extends 'Frey';
5 with 'Frey::Web';
6
7 has 'fey_class' => (
8 is => 'rw',
9 isa => 'Str',
10 required => 1,
11 );
12
13 use Data::Dump qw/dump/;
14
15 use Frey::Web::Row;
16 use Frey::Web::Links;
17
18 sub html {
19 my ( $self, $req ) = @_;
20
21 my $f = { $req->params };
22 my $layout = delete( $f->{layout} ) || 'div';
23
24 while ( 1 ) {
25
26 warn "<<< GOT REQUEST ",dump( $f );
27
28 # re-apply (changed?) layout to elements
29 if ( defined $f->{layout} ) {
30 $layout = delete( $f->{layout} );
31 warn "# new layout = $layout\n";
32 }
33
34 my $w = Frey::Web::Row->new( fey_class => $self->fey_class, layout => $layout, render_as => 'edit' );
35
36 my $form = $w->process($f);
37
38 $form = qq|<table>$form</table>| if $layout eq 'table';
39
40 if ( $layout eq 'columns' ) {
41 # add header to table
42 my $header = $w->render_iterator( sub {
43 my ( $name, $field_name, $label, $val ) = @_;
44 return if $name =~ /^_/;
45 return qq|<th>$label</th>|;
46 });
47 $form = qq|<table><tr>$header</tr>$form</table>|;
48 }
49
50 my $layout_picker =
51 qq|<div class="layout">layout: | .
52 Frey::Web::Links->new(
53 name => 'layout',
54 current => $layout,
55 values => [ 'div', 'table', 'columns' ],
56 )->links .
57 qq|</div>|
58 ;
59
60 my $html = dom2html(
61 html => [
62 head => [
63 link => { rel=>"stylesheet", href=>"/static/form.css", type=>"text/css" }
64 ],
65 body => [
66 h1 => [ $self->fey_class ],
67 $layout_picker,
68 form => { method=>'post' } => [
69 $form,
70 ],
71 ],
72 ]
73 );
74
75 warn ">>> $layout ",length( $html ),"\n";
76
77 $req->print( $html );
78 $req->next;
79
80 $f = { $req->params };
81 }
82
83 warn "NO WAY OUT!";
84 };
85
86 1;

  ViewVC Help
Powered by ViewVC 1.1.26