Actionbar nicht ohne content rendern
[kivitendo-erp.git] / SL / Layout / ActionBar.pm
1 package SL::Layout::ActionBar;
2
3 use strict;
4 use parent qw(SL::Layout::Base);
5
6 use SL::Layout::ActionBar::Action;
7
8 use constant HTML_CLASS => 'layout-actionbar';
9
10 use Rose::Object::MakeMethods::Generic (
11   'scalar --get_set_init' => [ qw(actions) ],
12 );
13
14
15 ###### Layout overrides
16
17 sub pre_content {
18   my ($self) = @_;
19
20   my $content = join '', map { $_->render } @{ $self->actions };
21   return if !$content;
22   $::request->presenter->html_tag('div', $content, class => HTML_CLASS);
23 }
24
25 sub javascripts_inline {
26   join '', map { $_->script } @{ $_[0]->actions };
27 }
28
29 sub javascripts {
30   'kivi.ActionBar.js'
31 }
32
33 ###### interface
34
35 sub add_actions {
36   my ($self, @actions) = @_;
37   push @{ $self->actions }, map {
38        !ref $_ ? SL::Layout::ActionBar::Action->from_descriptor($_)
39      :  ref $_ && 'ARRAY' eq ref $_ ? SL::Layout::ActionBar::Action->simple($_)
40      :  ref $_ && $_->isa('SL::Layout::Action') ? $_
41      : do { die 'invalid action' };
42   } @actions;
43 }
44
45 sub init_actions {
46   []
47 }
48
49
50
51
52 1;
53
54 __END__
55
56 =encoding utf-8
57
58 =head1 NAME
59
60 SL::Layout::ActionBar - Unified action buttons for controllers
61
62 =head1 CONCEPT
63
64 This is a layout block that does a unified action bar for any controller who
65 wants to use it. It's designed to be rendered above the content and to be
66 fixed when scrolling.
67
68 While it can be used as a generic widget container, it's designed to be able to
69 provide commonly used functionality as a short cut. These shortcuts include:
70
71 =over 4
72
73 =item *
74
75 Calling a controller with parameters
76
77 =item *
78
79 Submitting a form with added parameters
80
81 =item *
82
83 Arrangement utility
84
85 =back
86
87
88 =head1 METHODS
89
90 =over 4
91
92 =item C<add_actions LIST>
93
94 Dispatches each each argument to C<add_action>
95
96 =item C<add_action>
97
98
99 =item C<add_separator>
100
101 =item C<add_
102
103 =head1 ACCESS FROM CODE
104
105 This is accessable through
106
107   $::request->layout->get('actionbar')
108
109 =head1 DOM MODEL
110
111 The entire block is rendered into a div with the class 'layout-actionbar'.
112
113 =head1 ACTION WIDGETS
114
115 Each individual action must be an instance of C<SL::Layout::ActionBar::Action>.
116
117 =head1 BUGS
118
119 none yet. :)
120
121 =head1 AUTHOR
122
123 Sven Schoeling E<lt>s.schoeling@linet-services.deE<gt>
124
125 =cut