X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FLayout%2FActionBar.pm;h=25a62ccbec2f6e0594616cfeb9bd1072e46ccf02;hb=a6ce2c7f3f7ae10f7065fb86121c8d11049617ee;hp=edb836553efa19973e1a21cf5077749c4ca422c4;hpb=0d36a7edcadf3ef0013e96318a28d17b10772082;p=kivitendo-erp.git diff --git a/SL/Layout/ActionBar.pm b/SL/Layout/ActionBar.pm index edb836553..25a62ccbe 100644 --- a/SL/Layout/ActionBar.pm +++ b/SL/Layout/ActionBar.pm @@ -3,7 +3,12 @@ package SL::Layout::ActionBar; use strict; use parent qw(SL::Layout::Base); +use Carp; +use Scalar::Util qw(blessed); use SL::Layout::ActionBar::Action; +use SL::Layout::ActionBar::ComboBox; +use SL::Layout::ActionBar::Link; +use SL::Layout::ActionBar::Separator; use constant HTML_CLASS => 'layout-actionbar'; @@ -11,6 +16,12 @@ use Rose::Object::MakeMethods::Generic ( 'scalar --get_set_init' => [ qw(actions) ], ); +my %class_descriptors = ( + action => { class => 'SL::Layout::ActionBar::Action', num_params => 1, }, + combobox => { class => 'SL::Layout::ActionBar::ComboBox', num_params => 1, }, + link => { class => 'SL::Layout::ActionBar::Link', num_params => 1, }, + separator => { class => 'SL::Layout::ActionBar::Separator', num_params => 0, }, +); ###### Layout overrides @@ -32,22 +43,37 @@ sub javascripts { ###### interface -sub add_actions { +sub add { my ($self, @actions) = @_; - push @{ $self->actions }, map { - !ref $_ ? SL::Layout::ActionBar::Action->from_descriptor($_) - : ref $_ && 'ARRAY' eq ref $_ ? SL::Layout::ActionBar::Action->simple($_) - : ref $_ && $_->isa('SL::Layout::Action') ? $_ - : do { die 'invalid action' }; - } @actions; -} -sub init_actions { - [] + push @{ $self->actions }, $self->parse_actions(@actions); + + return $self->actions->[-1]; } +sub parse_actions { + my ($self_or_class, @actions) = @_; + my @parsed; + while (my $type = shift(@actions)) { + if (blessed($type) && $type->isa('SL::Layout::ActionBar::Action')) { + push @parsed, $type; + continue; + } + + my $descriptor = $class_descriptors{lc $type} || croak("Unknown action type '${type}'"); + my @params = splice(@actions, 0, $descriptor->{num_params}); + + push @parsed, $descriptor->{class}->from_params(@params); + } + + return @parsed; +} + +sub init_actions { + [] +} 1; @@ -89,16 +115,9 @@ Arrangement utility =over 4 -=item C - -Dispatches each each argument to C - -=item C - - -=item C +=item C -=item C