From: Sven Schöling Date: Mon, 17 Oct 2016 11:35:34 +0000 (+0200) Subject: ActionBar: by_description gefixt X-Git-Tag: release-3.5.4~1410 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=dd1ab30b7c2a6bec318dd75100e54c9bfa400e77;p=kivitendo-erp.git ActionBar: by_description gefixt --- 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;