From dd1ab30b7c2a6bec318dd75100e54c9bfa400e77 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Mon, 17 Oct 2016 13:35:34 +0200 Subject: [PATCH] ActionBar: by_description gefixt --- SL/Layout/ActionBar/Action.pm | 11 ++++++---- SL/Layout/ActionBar/ComboBox.pm | 37 +++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 SL/Layout/ActionBar/ComboBox.pm diff --git a/SL/Layout/ActionBar/Action.pm b/SL/Layout/ActionBar/Action.pm index 8ac1d2d63..8b83295c5 100644 --- a/SL/Layout/ActionBar/Action.pm +++ b/SL/Layout/ActionBar/Action.pm @@ -24,10 +24,12 @@ sub script { sub from_descriptor { my ($class, $descriptor) = @_; require SL::Layout::ActionBar::Separator; + require SL::Layout::ActionBar::ComboBox; - { + return { separator => SL::Layout::ActionBar::Separator->new, - } or die 'unknown descriptor'; + combobox => SL::Layout::ActionBar::ComboBox->new, + }->{$descriptor} or die 'unknown descriptor'; } # TODO: this necessary? @@ -46,8 +48,9 @@ sub simple { return SL::Layout::ActionBar::ScriptButton->new(text => $text, params => \%params); } - if ($params{combobox}) { - + if ($params{actions}) { + require SL::Layout::ActionBar::ComboBox; + return SL::Layout::ActionBar::ComboBox->new(text => $text, %params); } } diff --git a/SL/Layout/ActionBar/ComboBox.pm b/SL/Layout/ActionBar/ComboBox.pm new file mode 100644 index 000000000..3416df84d --- /dev/null +++ b/SL/Layout/ActionBar/ComboBox.pm @@ -0,0 +1,37 @@ +package SL::Layout::ActionBar::ComboBox; + +use strict; +use parent qw(SL::Layout::ActionBar::Action); + +use JSON; + +use Rose::Object::MakeMethods::Generic ( + 'scalar --get_set_init' => [ qw(actions) ], +); + +sub parsed_actions { + $_[0]{parsed_actions} ||= + [ map { SL::Layout::ActionBar::Action->simple($_) } @{ $_[0]->actions || [] } ]; +} + +sub add_actions { + push @{$_[0]{actions} //= $_[0]->init_actions}, @_[1..$#_] +} + +sub render { + my ($first, @rest) = @{ $_[0]->parsed_actions }; + $_[0]->p->html_tag('div', + $_[0]->p->html_tag('div', $first->render, class => 'layout-actionbar-combobox-head') . + $_[0]->p->html_tag('div', join('', map { $_->render } @rest), class => 'layout-actionbar-combobox-list'), + id => $_[0]->id, + class => 'layout-actionbar-combobox', + ); +} + +sub script { + map { $_->script } @{ $_[0]->parsed_actions } +} + +sub init_actions { [] } + +1; -- 2.20.1