X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FLayout%2FActionBar%2FComboBox.pm;h=477151dbc9e1929b939bd90754cf1391f7fa2295;hb=dac355365ac502d9a70d7180a7c23f6dfc7d2e32;hp=5e5c863a1947ba7fd94f669833f13f1c0af71a24;hpb=121f8ff14cb83da8be3654a471d8180f657337f1;p=kivitendo-erp.git diff --git a/SL/Layout/ActionBar/ComboBox.pm b/SL/Layout/ActionBar/ComboBox.pm index 5e5c863a1..477151dbc 100644 --- a/SL/Layout/ActionBar/ComboBox.pm +++ b/SL/Layout/ActionBar/ComboBox.pm @@ -4,32 +4,38 @@ use strict; use parent qw(SL::Layout::ActionBar::Action); use JSON; +use List::MoreUtils qw(none); +use SL::Presenter::Tag qw(html_tag); 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 from_params { + my ($class, $actions) = @_; + + my $combobox = $class->new; + push @{ $combobox->actions }, SL::Layout::ActionBar->parse_actions(@{ $actions }); -sub add_actions { - push @{$_[0]{actions} //= $_[0]->init_actions}, @_[1..$#_] + return $combobox; } sub render { - my ($first, @rest) = @{ $_[0]->parsed_actions }; - $_[0]->p->html_tag('div', - $_[0]->p->html_tag('div', $first->render . $_[0]->p->html_tag('span'), class => 'layout-actionbar-combobox-head') . - $_[0]->p->html_tag('div', join('', map { $_->render } @rest), class => 'layout-actionbar-combobox-list'), + my ($first, @rest) = @{ $_[0]->actions }; + + return if none { $_->callable } @{ $_[0]->actions }; + return $first->render if !@rest; + + html_tag('div', + html_tag('div', $first->render . html_tag('span'), class => 'layout-actionbar-combobox-head') . + 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 } + map { $_->script } @{ $_[0]->actions } } sub init_actions { [] }