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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 153 - (hide annotations)
Wed Jul 16 23:21:19 2008 UTC (14 years, 2 months ago) by dpavlin
File size: 1932 byte(s)
label editor which save to yaml on disk and use it
1 dpavlin 129 package Frey::Web::Design;
2     use Moose;
3 dpavlin 143 extends 'Frey::Web::Item';
4 dpavlin 129 with 'Frey::Web::Button';
5 dpavlin 153 with 'Frey::Storage';
6 dpavlin 129
7     =head1 NAME
8    
9     Frey::Web::Design - field designer for L<Frey::Web::Item>
10    
11     =cut
12    
13     use Data::Dump qw/dump/;
14    
15 dpavlin 143 has 'labels' => (
16     is => 'rw',
17     isa => 'HashRef[Str]',
18 dpavlin 153 lazy_build => 1,
19 dpavlin 143 );
20    
21 dpavlin 153 sub _build_labels {
22     my $self = shift;
23     $self->load( 'var/design/' . $self->fey_class . '-labels' ) || {}
24     };
25    
26 dpavlin 149 has 'label_order' => (
27 dpavlin 143 is => 'rw',
28 dpavlin 149 isa => 'HashRef[Int]',
29     default => sub { {} },
30 dpavlin 143 );
31    
32 dpavlin 149 has 'label_editable' => (
33     is => 'rw',
34     isa => 'HashRef[Frey::Web::Editable]',
35     default => sub { {} },
36     );
37    
38 dpavlin 150 has 'label_count' => (
39     is => 'rw',
40     isa => 'Int',
41     default => 0,
42     );
43    
44 dpavlin 149 use Frey::Web::Editable;
45    
46 dpavlin 143 around 'field_label' => sub {
47     my ($next, $self, $name) = @_;
48 dpavlin 149 my $orig_label = $self->$next($name);
49 dpavlin 143
50 dpavlin 150 my $label = $self->labels->{ $name } ||= $orig_label;
51     my $order = $self->label_order->{ $name };
52     my $count = $self->label_count;
53 dpavlin 143
54 dpavlin 150 if ( ! defined $order ) {
55     warn "field_label $count $name -> $label\n";
56     $self->label_order->{ $name } = $count++;
57     $self->label_count( $count );
58     $self->label_editable->{ $name } = Frey::Web::Editable->new(
59 dpavlin 149 name => $name,
60     value => $label,
61     render_as => 'edit',
62     save_callback => sub {
63 dpavlin 150 my ( $caller, $val ) = @_;
64     $self->labels->{ $name } = $val;
65 dpavlin 149 # XXX we really need this since we are in continutation and have old value!
66 dpavlin 150 $caller->value( $val );
67     warn "## saved $val new labels = ",dump( $self->labels, $caller->value );
68 dpavlin 153 $self->store( 'var/design/' . $self->fey_class . '-labels', $self->labels );
69 dpavlin 149 }
70     );
71     }
72 dpavlin 143
73 dpavlin 150 warn "around field_label ", $self->uuid, " $order $count ", dump( $self->labels ), $/;
74 dpavlin 129
75 dpavlin 149 my $html;
76 dpavlin 150 $html .= qq|<a style="color:#888" href="">&larr;</a>| if $self->label_order->{ $name } > 0 ;
77     $html .= $self->label_editable->{ $name }->process( Frey::Request->params );
78 dpavlin 149 $html .= qq|<a style="color:#888" href="">&rarr;</a>|;
79    
80     return $html;
81 dpavlin 129 };
82    
83     1;

  ViewVC Help
Powered by ViewVC 1.1.26