3416df84d8ec69eea2de072cfd6a0d4b1a239b62
[kivitendo-erp.git] / SL / Layout / ActionBar / ComboBox.pm
1 package SL::Layout::ActionBar::ComboBox;
2
3 use strict;
4 use parent qw(SL::Layout::ActionBar::Action);
5
6 use JSON;
7
8 use Rose::Object::MakeMethods::Generic (
9   'scalar --get_set_init' => [ qw(actions) ],
10 );
11
12 sub parsed_actions {
13   $_[0]{parsed_actions} ||=
14     [ map { SL::Layout::ActionBar::Action->simple($_) } @{ $_[0]->actions || [] } ];
15 }
16
17 sub add_actions {
18   push @{$_[0]{actions} //= $_[0]->init_actions}, @_[1..$#_]
19 }
20
21 sub render {
22   my ($first, @rest) = @{ $_[0]->parsed_actions };
23   $_[0]->p->html_tag('div',
24     $_[0]->p->html_tag('div', $first->render, class => 'layout-actionbar-combobox-head') .
25     $_[0]->p->html_tag('div', join('', map { $_->render } @rest), class => 'layout-actionbar-combobox-list'),
26     id    => $_[0]->id,
27     class => 'layout-actionbar-combobox',
28   );
29 }
30
31 sub script {
32   map { $_->script } @{ $_[0]->parsed_actions }
33 }
34
35 sub init_actions { [] }
36
37 1;