ActionBar: falsche Doku entfernt
[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 Carp;
7 use Scalar::Util qw(blessed);
8 use SL::Layout::ActionBar::Action;
9 use SL::Layout::ActionBar::ComboBox;
10 use SL::Layout::ActionBar::Link;
11 use SL::Layout::ActionBar::Separator;
12
13 use constant HTML_CLASS => 'layout-actionbar';
14
15 use Rose::Object::MakeMethods::Generic (
16   'scalar --get_set_init' => [ qw(actions) ],
17 );
18
19 my %class_descriptors = (
20   action    => { class => 'SL::Layout::ActionBar::Action',    num_params => 1, },
21   combobox  => { class => 'SL::Layout::ActionBar::ComboBox',  num_params => 1, },
22   link      => { class => 'SL::Layout::ActionBar::Link',      num_params => 1, },
23   separator => { class => 'SL::Layout::ActionBar::Separator', num_params => 0, },
24 );
25
26 ###### Layout overrides
27
28 sub pre_content {
29   my ($self) = @_;
30
31   my $content = join '', map { $_->render } @{ $self->actions };
32   return if !$content;
33   $::request->presenter->html_tag('div', $content, class => HTML_CLASS);
34 }
35
36 sub javascripts_inline {
37   join '', map { $_->script } @{ $_[0]->actions };
38 }
39
40 sub javascripts {
41   'kivi.ActionBar.js'
42 }
43
44 ###### interface
45
46 sub add {
47   my ($self, @actions) = @_;
48
49   push @{ $self->actions }, $self->parse_actions(@actions);
50
51   return $self->actions->[-1];
52 }
53
54 sub parse_actions {
55   my ($self_or_class, @actions) = @_;
56
57   my @parsed;
58
59   while (my $type = shift(@actions)) {
60     if (blessed($type) && $type->isa('SL::Layout::ActionBar::Action')) {
61       push @parsed, $type;
62       continue;
63     }
64
65     my $descriptor = $class_descriptors{lc $type} || croak("Unknown action type '${type}'");
66     my @params     = splice(@actions, 0, $descriptor->{num_params});
67
68     push @parsed, $descriptor->{class}->from_params(@params);
69   }
70
71   return @parsed;
72 }
73
74 sub init_actions {
75   []
76 }
77
78 1;
79
80 __END__
81
82 =encoding utf-8
83
84 =head1 NAME
85
86 SL::Layout::ActionBar - Unified action buttons for controllers
87
88 =head1 CONCEPT
89
90 This is a layout block that does a unified action bar for any controller who
91 wants to use it. It's designed to be rendered above the content and to be
92 fixed when scrolling.
93
94 While it can be used as a generic widget container, it's designed to be able to
95 provide commonly used functionality as a short cut. These shortcuts include:
96
97 =over 4
98
99 =item *
100
101 Calling a controller with parameters
102
103 =item *
104
105 Submitting a form with added parameters
106
107 =item *
108
109 Arrangement utility
110
111 =back
112
113
114 =head1 METHODS
115
116 =over 4
117
118 =item C<add LIST>
119
120 to be documented
121
122 =head1 ACCESS FROM CODE
123
124 This is accessable through
125
126   $::request->layout->get('actionbar')
127
128 =head1 DOM MODEL
129
130 The entire block is rendered into a div with the class 'layout-actionbar'.
131
132 =head1 ACTION WIDGETS
133
134 Each individual action must be an instance of C<SL::Layout::ActionBar::Action>.
135
136 =head1 BUGS
137
138 none yet. :)
139
140 =head1 AUTHOR
141
142 Sven Schoeling E<lt>s.schoeling@linet-services.deE<gt>
143
144 =cut