1 |
package Frey::Web::Design; |
package Frey::Web::Design; |
2 |
use Moose; |
use Moose; |
3 |
extends 'Frey'; |
extends 'Frey::Web::Item'; |
|
with 'Frey::Web::Item'; |
|
4 |
with 'Frey::Web::Button'; |
with 'Frey::Web::Button'; |
5 |
|
|
6 |
=head1 NAME |
=head1 NAME |
11 |
|
|
12 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
13 |
|
|
14 |
before 'main' => sub { |
has 'labels' => ( |
15 |
my $self = shift; |
is => 'rw', |
16 |
|
isa => 'HashRef[Str]', |
17 |
$self->add_button( 'Finish design' => sub { |
default => sub { {} }, |
18 |
my $f = shift; |
); |
19 |
my $hash = $self->set_from_hash($f); |
|
20 |
warn "## Add hash ", $self->uuid, " => ",dump( $hash, $f ); |
has 'label_order' => ( |
21 |
|
is => 'rw', |
22 |
$self->render_as( 'view' ); |
isa => 'HashRef[Int]', |
23 |
$self->remove_button( 'Finish design' ); |
default => sub { {} }, |
24 |
}); |
); |
25 |
|
|
26 |
|
has 'label_editable' => ( |
27 |
|
is => 'rw', |
28 |
|
isa => 'HashRef[Frey::Web::Editable]', |
29 |
|
default => sub { {} }, |
30 |
|
); |
31 |
|
|
32 |
|
has 'label_count' => ( |
33 |
|
is => 'rw', |
34 |
|
isa => 'Int', |
35 |
|
default => 0, |
36 |
|
); |
37 |
|
|
38 |
|
use Frey::Web::Editable; |
39 |
|
|
40 |
|
around 'field_label' => sub { |
41 |
|
my ($next, $self, $name) = @_; |
42 |
|
my $orig_label = $self->$next($name); |
43 |
|
|
44 |
|
my $label = $self->labels->{ $name } ||= $orig_label; |
45 |
|
my $order = $self->label_order->{ $name }; |
46 |
|
my $count = $self->label_count; |
47 |
|
|
48 |
|
if ( ! defined $order ) { |
49 |
|
warn "field_label $count $name -> $label\n"; |
50 |
|
$self->label_order->{ $name } = $count++; |
51 |
|
$self->label_count( $count ); |
52 |
|
$self->label_editable->{ $name } = Frey::Web::Editable->new( |
53 |
|
name => $name, |
54 |
|
value => $label, |
55 |
|
render_as => 'edit', |
56 |
|
save_callback => sub { |
57 |
|
my ( $caller, $val ) = @_; |
58 |
|
$self->labels->{ $name } = $val; |
59 |
|
# XXX we really need this since we are in continutation and have old value! |
60 |
|
$caller->value( $val ); |
61 |
|
warn "## saved $val new labels = ",dump( $self->labels, $caller->value ); |
62 |
|
} |
63 |
|
); |
64 |
|
} |
65 |
|
|
66 |
|
warn "around field_label ", $self->uuid, " $order $count ", dump( $self->labels ), $/; |
67 |
|
|
68 |
|
my $html; |
69 |
|
$html .= qq|<a style="color:#888" href="">←</a>| if $self->label_order->{ $name } > 0 ; |
70 |
|
$html .= $self->label_editable->{ $name }->process( Frey::Request->params ); |
71 |
|
$html .= qq|<a style="color:#888" href="">→</a>|; |
72 |
|
|
73 |
|
return $html; |
74 |
}; |
}; |
75 |
|
|
76 |
1; |
1; |