1 package SL::Layout::ActionBar::Action;
4 use parent qw(Rose::Object);
8 use Rose::Object::MakeMethods::Generic (
9 'scalar --get_set_init' => [ qw(id params text) ],
12 # subclassing interface
15 die 'needs to be implemented';
19 sprintf q|$('#%s').data('action', %s);|, $_[0]->id, JSON->new->allow_blessed->convert_blessed->encode($_[0]->params);
22 # this is mostly so that outside consumer don't need to load subclasses themselves
24 my ($class, $data) = @_;
26 require SL::Layout::ActionBar::Submit;
28 my ($text, %params) = @$data;
29 return if exists($params{only_if}) && !$params{only_if};
30 return if exists($params{not_if}) && $params{not_if};
31 return SL::Layout::ActionBar::Submit->new(text => $text, params => \%params);
36 # shortcut for presenter
46 # unique id to tie div and javascript together
48 $_[0]->params->{id} //
49 $_[0]->p->name_to_id('action[]')
60 SL::Layout::ActionBar::Action - base class for action bar actions
64 This base class for actions can be used to implement elements that can be
65 added to L<SL::Layout::ActionBar>.
67 Elements can be interactive or simply used for layout. Most of the actual
68 semantics are handled in the corresponding javascript C<js/kivi.ActionBar.js>, so
69 this is only used to generate the DOM elements and to provide information for
70 request time logic decisions.
76 package SL::Layout::ActionBar::Custom;
77 use parent qw(SL::Layout::ActionBar::Action);
80 SL::Layout::ActionBar::Custom->new(
81 text => t8('Description'),
89 # parse sugared version:
90 SL::Layout::ActionBar::Custom->from_params(
103 Needs to be implemented. Should render only the bare minimum necessary to
104 identify the element at run time.
108 Will be called during layout rendering. Defaults to dumping the params section
109 into data field of the rendered DOM element.
111 =item * C<from_params>
113 Parse sugared version. Defaults for historic reasons to the implementation of
114 L<SL::Layout::ActionBar::Submit>, all others must implement their own.
118 Used to determine whether an instance is callable or only a layout element.
128 Returns the current request presenter.
132 Will get initialized to either the provided id from the params or to a
133 generated unique id. Should be used to tie the rendered DOM and script
138 =head1 RECOGNIZED PARAMETERS
142 =item * C<< submit => [ $selector, \%params ] >>
144 On click, submit the form found with the first parameter. If params is present
145 and a hashref, the key value elements will be added to the form before
146 submitting. Beware that this will destroy the form if the user uses the browser
147 history to jump back to this page, so ony use parametrized submits for post
148 submits that redirect on completion.
150 =item * C<< link => $url >>
152 On click, will load the given url.
154 =item * C<< call => [ $function_name, @args ] >>
156 On click, will call the function name with the argument array. The return will
157 be discarded. It is assumed that the fucntion will trigger an asynchronous
160 Contrast with C<checks>.
162 =item * C<< checks => \@function_names >>
164 Before any of C<submit>, C<link>, or C<call> are evaluated all
165 functions in C<check> are called. Only if all of them return a true value the
166 action will be triggered.
168 Checks are expected not to trigger asynchronous actions (contrast with C<call>),
169 but may change the DOM to indicate to the user why they fail.
171 Each must return a boolean value.
173 =item * C<< confirm => t8('Yes/No Question') >>
175 Before any of C<submit>, C<link>, or C<call> are evaluated, the user
176 will be asked to confirm. If checks are present and failed, confirm will not be
179 =item * C<< only_if => $bool >>
181 Pseudo parameter. If present and false, the element will not be rendered.
183 =item * C<< not_if => $bool >>
185 Pseudo parameter. If present and true, the element will not be rendered.
187 =item * C<< only_once => 1 >>
189 If present, a click will C<disable> the action to prevent multiple activations.
191 =item * C<< accesskey => $text >>
193 Registers an accesskey for this element. While the most common accesskey is
194 'enter', in theory every other should work as well. Modifier keys can be added
195 to the accesskey string with 'ctrl+', 'alt+', or 'shift+'. 'shift+' is not
196 necessary for upper case letters.
198 =item * C<< disabled => t8('tooltip') >>
200 Renders the element disabled, ignores all actions (C<submit>, C<call>, C<link>)
201 and adds the given tooltip hopefully explaining why the element is disabled.
203 =item * C<< id => $id >>
205 Sets the DOM id of the rendered element. If missing, the element will get a
208 =item * C<< tooltip => t8('tooltip') >>
210 Sets a tooltip for the element.
220 Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>