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?
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);
}
}
--- /dev/null
+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;