kivitendo/SL/Layout/ActionBar.pm @ 31b247ee
ccf94c5d | Sven Schöling | package SL::Layout::ActionBar;
|
||
use strict;
|
||||
use parent qw(SL::Layout::Base);
|
||||
ff424b75 | Moritz Bunkus | use Carp;
|
||
use Scalar::Util qw(blessed);
|
||||
e0a3b19e | Sven Schöling | use SL::Layout::ActionBar::Action;
|
||
ff424b75 | Moritz Bunkus | use SL::Layout::ActionBar::ComboBox;
|
||
c37fb9ef | Moritz Bunkus | use SL::Layout::ActionBar::Link;
|
||
ff424b75 | Moritz Bunkus | use SL::Layout::ActionBar::Separator;
|
||
e0a3b19e | Sven Schöling | |||
ccf94c5d | Sven Schöling | use constant HTML_CLASS => 'layout-actionbar';
|
||
use Rose::Object::MakeMethods::Generic (
|
||||
'scalar --get_set_init' => [ qw(actions) ],
|
||||
);
|
||||
ff424b75 | Moritz Bunkus | my %class_descriptors = (
|
||
action => { class => 'SL::Layout::ActionBar::Action', num_params => 1, },
|
||||
combobox => { class => 'SL::Layout::ActionBar::ComboBox', num_params => 1, },
|
||||
c37fb9ef | Moritz Bunkus | link => { class => 'SL::Layout::ActionBar::Link', num_params => 1, },
|
||
ff424b75 | Moritz Bunkus | separator => { class => 'SL::Layout::ActionBar::Separator', num_params => 0, },
|
||
);
|
||||
ccf94c5d | Sven Schöling | |||
###### Layout overrides
|
||||
sub pre_content {
|
||||
e0a3b19e | Sven Schöling | my ($self) = @_;
|
||
my $content = join '', map { $_->render } @{ $self->actions };
|
||||
0d36a7ed | Sven Schöling | return if !$content;
|
||
e0a3b19e | Sven Schöling | $::request->presenter->html_tag('div', $content, class => HTML_CLASS);
|
||
ccf94c5d | Sven Schöling | }
|
||
e0a3b19e | Sven Schöling | sub javascripts_inline {
|
||
join '', map { $_->script } @{ $_[0]->actions };
|
||||
ccf94c5d | Sven Schöling | }
|
||
sub javascripts {
|
||||
e0a3b19e | Sven Schöling | 'kivi.ActionBar.js'
|
||
ccf94c5d | Sven Schöling | }
|
||
###### interface
|
||||
ff424b75 | Moritz Bunkus | sub add {
|
||
ccf94c5d | Sven Schöling | my ($self, @actions) = @_;
|
||
ff424b75 | Moritz Bunkus | push @{ $self->actions }, $self->parse_actions(@actions);
|
||
return $self->actions->[-1];
|
||||
ccf94c5d | Sven Schöling | }
|
||
ff424b75 | Moritz Bunkus | 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;
|
||||
}
|
||||
ccf94c5d | Sven Schöling | |||
ff424b75 | Moritz Bunkus | my $descriptor = $class_descriptors{lc $type} || croak("Unknown action type '${type}'");
|
||
my @params = splice(@actions, 0, $descriptor->{num_params});
|
||||
ccf94c5d | Sven Schöling | |||
ff424b75 | Moritz Bunkus | push @parsed, $descriptor->{class}->from_params(@params);
|
||
}
|
||||
return @parsed;
|
||||
}
|
||||
sub init_actions {
|
||||
[]
|
||||
}
|
||||
ccf94c5d | Sven Schöling | |||
1;
|
||||
__END__
|
||||
=encoding utf-8
|
||||
=head1 NAME
|
||||
SL::Layout::ActionBar - Unified action buttons for controllers
|
||||
=head1 CONCEPT
|
||||
This is a layout block that does a unified action bar for any controller who
|
||||
wants to use it. It's designed to be rendered above the content and to be
|
||||
fixed when scrolling.
|
||||
While it can be used as a generic widget container, it's designed to be able to
|
||||
provide commonly used functionality as a short cut. These shortcuts include:
|
||||
=over 4
|
||||
=item *
|
||||
Calling a controller with parameters
|
||||
=item *
|
||||
Submitting a form with added parameters
|
||||
=item *
|
||||
Arrangement utility
|
||||
=back
|
||||
=head1 METHODS
|
||||
=over 4
|
||||
dc227972 | Moritz Bunkus | =item C<add LIST>
|
||
ccf94c5d | Sven Schöling | |||
dc227972 | Moritz Bunkus | to be documented
|
||
ccf94c5d | Sven Schöling | |||
=head1 ACCESS FROM CODE
|
||||
This is accessable through
|
||||
e0a3b19e | Sven Schöling | $::request->layout->get('actionbar')
|
||
ccf94c5d | Sven Schöling | |||
=head1 DOM MODEL
|
||||
The entire block is rendered into a div with the class 'layout-actionbar'.
|
||||
=head1 ACTION WIDGETS
|
||||
Each individual action must be an instance of C<SL::Layout::ActionBar::Action>.
|
||||
=head1 BUGS
|
||||
none yet. :)
|
||||
=head1 AUTHOR
|
||||
Sven Schoeling E<lt>s.schoeling@linet-services.deE<gt>
|
||||
=cut
|