ActionBar: neuer Typ für einfachen Link in Hauptzeile (nicht in Combo)
[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_actions LIST>
119
120 Dispatches each each argument to C<add_action>
121
122 =item C<add_action>
123
124
125 =item C<add_separator>
126
127 =item C<add_
128
129 =head1 ACCESS FROM CODE
130
131 This is accessable through
132
133   $::request->layout->get('actionbar')
134
135 =head1 DOM MODEL
136
137 The entire block is rendered into a div with the class 'layout-actionbar'.
138
139 =head1 ACTION WIDGETS
140
141 Each individual action must be an instance of C<SL::Layout::ActionBar::Action>.
142
143 =head1 BUGS
144
145 none yet. :)
146
147 =head1 AUTHOR
148
149 Sven Schoeling E<lt>s.schoeling@linet-services.deE<gt>
150
151 =cut