/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 129 - (hide annotations)
Mon Jul 14 23:44:18 2008 UTC (14 years, 2 months ago) by dpavlin
File size: 1551 byte(s)
refactor to generalize callbacks a bit
1 dpavlin 113 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 dpavlin 129 use Frey::Web::Design;
16 dpavlin 113 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 dpavlin 129 my $w = Frey::Web::Design->new( fey_class => $self->fey_class, layout => $layout, render_as => 'edit' );
35 dpavlin 113
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 dpavlin 121 $self->add_css( 'static/form.css' );
61    
62     my $html = $self->page(
63     body => '<h1>' . $self->fey_class . '</h1>'
64     . $layout_picker
65     . qq|<form method="post">$form</form>|
66 dpavlin 113 );
67    
68     warn ">>> $layout ",length( $html ),"\n";
69    
70     $req->print( $html );
71     $req->next;
72    
73     $f = { $req->params };
74     }
75    
76     warn "NO WAY OUT!";
77     };
78    
79     1;

  ViewVC Help
Powered by ViewVC 1.1.26