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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 149 - (show annotations)
Wed Jul 16 21:23:27 2008 UTC (14 years, 4 months ago) by dpavlin
File size: 1546 byte(s)
partially working label editor in ObjectDesigner -- no save yet! [0.13]
1 package Frey::Web::Editable;
2 use Moose;
3 extends 'Frey';
4 with 'Frey::Web::Field';
5
6 use Moose::Util::TypeConstraints;
7 use Data::Dump qw/dump/;
8
9 enum 'Render_as' => qw( view edit none );
10 has render_as => ( is => 'rw', isa => 'Render_as', required => 1, default => 'view' );
11
12 has name => (
13 is => 'rw',
14 isa => 'Str',
15 required => 1,
16 );
17
18 has value => (
19 is => 'rw',
20 isa => 'Str',
21 );
22
23 has save_callback => (
24 is => 'rw',
25 isa => 'CodeRef',
26 default => sub { warn "## default save_callback ",dump( @_ ) },
27 );
28
29 sub set_from_hash {
30 my ($self, $f) = @_;
31
32 my $name = $self->name;
33
34 my $field_name = $self->field_name( $name );
35 if(defined $f->{$field_name}) {
36 my $v = $f->{$field_name};
37 return unless $v ne $self->value;
38 $self->value( $v );
39 warn "## set_from_hash $name = $v from $field_name";
40 $self->save_callback->( $self, $v );
41 warn "CHECK: $v == ", $self->value;
42 }
43 }
44
45 sub main {
46 my ( $self ) = @_;
47
48 while ( 1 ) {
49 my ( $f_uuid, $f_val ) = ( $self->field_name( $self->name ) , $self->value );
50 warn "# editable ",$self->uuid, " ", $self->name, " ", $self->value if $self->debug;
51
52 my $out;
53 if ( $self->render_as eq 'edit' ) {
54 $out .= qq|<input type="text" name="$f_uuid" value="$f_val">|;
55 } elsif ( $self->render_as eq 'view' ) {
56 $out .= qq|$f_val|;
57 } else {
58 warn "no renderer ",dump( $self->render_as ), " skipping...";
59 }
60
61 warn $@ if $@;
62 # warn ">>> editable $f_uuid $f_val ",length($out)," bytes\n";
63 my $f = $self->next($out);
64 $self->set_from_hash($f);
65 # $self->exec_callbacks($f); # Buttons
66 }
67 };
68
69 1;

  ViewVC Help
Powered by ViewVC 1.1.26