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