/[Frey]/trunk/lib/Frey/Web/Row.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/Web/Row.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 74 - (show annotations)
Wed Jul 9 20:46:40 2008 UTC (15 years, 9 months ago) by dpavlin
Original Path: trunk/lib/Strix/View/User.pm
File size: 2006 byte(s)
implement all CRUD operations

- Add fails because Fey::Loader has problem with autoincrement in our schema
- we override main from Continurity::Widget and do everything ourselfs
1 package Strix::View::User;
2
3 use Data::Dump qw/dump/;
4
5 use metaclass 'Moose::Meta::Class' => (
6 attribute_metaclass => 'Continuity::Meta::Attribute::FormField'
7 );
8
9 use Moose;
10
11 extends 'Continuity::Widget';
12 #with 'BonusTypes';
13
14 sub main {
15 my ( $self ) = @_;
16
17 if ( ! $self->_fey ) {
18 $self->add_button( 'Add' => sub {
19 warn "## Add button callback ",dump( @_ );
20 my $f = shift;
21 # my $out = $self->render_edit;
22 # my $f = $self->next($out);
23 warn "## my uuid ",$self->uuid;
24 $self->set_from_hash($f, sub {
25 warn "## inside set_from_hash ",dump( @_ );
26 my $hash = shift || die "no hash?";
27 delete( $hash->{id} ); # FIXME clear primary key
28 # $hash->{id} = undef;
29 my $u = Strix::User->insert( %$hash );
30 warn "Inserted ",$u->id;
31 $self->_fey( $u );
32 });
33 });
34 } else {
35
36 $self->add_button( 'Edit' => sub {
37 my $out = $self->render_edit;
38 my $f = $self->next($out);
39 $self->set_from_hash($f, sub {
40 warn "## inside set_from_hash ",dump( @_ );
41 my $hash = shift || die "no hash?";
42 $self->_fey->update( %$hash );
43 });
44 });
45
46 $self->add_button('Delete' => sub {
47 print STDERR "delete ID @{[$self->id]}!\n";
48 $self->_fey->delete;
49 $self->next("Deleted id @{[$self->id]}!");
50 $self->render_as( 'deleted' );
51 Strix::Schema->ClearObjectCaches(); # XXX important!
52 });
53
54 }
55
56 while(1) {
57 my $code = '$self->render_' . $self->render_as . ';';
58 warn "CODE: $code";
59 my $out = eval "$code";
60 warn $@ if $@;
61 my $f = $self->next($out);
62 $self->set_from_hash($f);
63 $self->exec_buttons($f);
64 }
65 };
66
67 use Data::Dump qw/dump/;
68
69 use Strix::User;
70 my $m = Strix::User->meta;
71
72 foreach ( $m->get_attribute_list ) {
73 my $attr = $m->get_attribute( $_ );
74 warn ">> $_\n";
75
76 # FIXME primary key would have to be read-only!
77
78 has $_ => (
79 is => $attr->_is_metadata,
80 label => ucfirst($_),
81 required => $attr->is_required,
82 );
83
84 }
85
86 has _foo => (
87 is => 'rw',
88 label => 'Foo',
89 );
90
91 has _fey => (
92 is => 'rw',
93 label => 'Fey object',
94 isa => 'Strix::User',
95 );
96
97 1;

  ViewVC Help
Powered by ViewVC 1.1.26