477151dbc9e1929b939bd90754cf1391f7fa2295
[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 use List::MoreUtils qw(none);
8 use SL::Presenter::Tag qw(html_tag);
9
10 use Rose::Object::MakeMethods::Generic (
11   'scalar --get_set_init' => [ qw(actions) ],
12 );
13
14 sub from_params {
15   my ($class, $actions) = @_;
16
17   my $combobox = $class->new;
18   push @{ $combobox->actions }, SL::Layout::ActionBar->parse_actions(@{ $actions });
19
20   return $combobox;
21 }
22
23 sub render {
24   my ($first, @rest) = @{ $_[0]->actions };
25
26   return                if none { $_->callable } @{ $_[0]->actions };
27   return $first->render if !@rest;
28
29   html_tag('div',
30     html_tag('div', $first->render . html_tag('span'), class => 'layout-actionbar-combobox-head') .
31     html_tag('div', join('', map { $_->render } @rest), class => 'layout-actionbar-combobox-list'),
32     id    => $_[0]->id,
33     class => 'layout-actionbar-combobox',
34   );
35 }
36
37 sub script {
38   map { $_->script } @{ $_[0]->actions }
39 }
40
41 sub init_actions { [] }
42
43 1;