ActionBar: by_description gefixt
authorSven Schöling <s.schoeling@linet-services.de>
Mon, 17 Oct 2016 11:35:34 +0000 (13:35 +0200)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 28 Feb 2017 09:04:33 +0000 (10:04 +0100)
SL/Layout/ActionBar/Action.pm
SL/Layout/ActionBar/ComboBox.pm [new file with mode: 0644]

index 8ac1d2d..8b83295 100644 (file)
@@ -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 (file)
index 0000000..3416df8
--- /dev/null
@@ -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;