kivitendo/SL/Layout/ActionBar/Action.pm @ 6f1da6d4
e0a3b19e | Sven Schöling | package SL::Layout::ActionBar::Action;
|
||
use strict;
|
||||
use parent qw(Rose::Object);
|
||||
use SL::Presenter;
|
||||
6ce40ffc | Sven Schöling | require SL::Layout::ActionBar::Submit;
|
||
e0a3b19e | Sven Schöling | |||
use Rose::Object::MakeMethods::Generic (
|
||||
3dc29e42 | Sven Schöling | 'scalar --get_set_init' => [ qw(id params text) ],
|
||
e0a3b19e | Sven Schöling | );
|
||
# subclassing interface
|
||||
sub render {
|
||||
die 'needs to be implemented';
|
||||
}
|
||||
sub script {
|
||||
3dc29e42 | Sven Schöling | sprintf q|$('#%s').data('action', %s);|, $_[0]->id, JSON->new->allow_blessed->convert_blessed->encode($_[0]->params);
|
||
e0a3b19e | Sven Schöling | }
|
||
# static constructors
|
||||
sub from_descriptor {
|
||||
3dc29e42 | Sven Schöling | my ($class, $descriptor) = @_;
|
||
require SL::Layout::ActionBar::Separator;
|
||||
dd1ab30b | Sven Schöling | require SL::Layout::ActionBar::ComboBox;
|
||
e0a3b19e | Sven Schöling | |||
dd1ab30b | Sven Schöling | return {
|
||
e0a3b19e | Sven Schöling | separator => SL::Layout::ActionBar::Separator->new,
|
||
dd1ab30b | Sven Schöling | combobox => SL::Layout::ActionBar::ComboBox->new,
|
||
6ce40ffc | Sven Schöling | }->{$descriptor} || do { die 'unknown descriptor' };
|
||
e0a3b19e | Sven Schöling | }
|
||
6ce40ffc | Sven Schöling | # this is mostly so that outside consumer don't need to load subclasses themselves
|
||
e0a3b19e | Sven Schöling | sub simple {
|
||
my ($class, $data) = @_;
|
||||
my ($text, %params) = @$data;
|
||||
6ce40ffc | Sven Schöling | return SL::Layout::ActionBar::Submit->new(text => $text, params => \%params);
|
||
e0a3b19e | Sven Schöling | }
|
||
# shortcut for presenter
|
||||
sub p {
|
||||
SL::Presenter->get
|
||||
}
|
||||
2cac4306 | Sven Schöling | sub init_params {
|
||
+{}
|
||||
}
|
||||
e0a3b19e | Sven Schöling | # unique id to tie div and javascript together
|
||
sub init_id {
|
||||
2cac4306 | Sven Schöling | $_[0]->params->{id} //
|
||
e0a3b19e | Sven Schöling | $_[0]->p->name_to_id('action[]')
|
||
}
|
||||
1;
|
||||
__END__
|
||||
3dc29e42 | Sven Schöling | |||
=head 1
|
||||
planned options for clickables:
|
||||
- checks => [ ... ] (done)
|
||||
a list of functions that need to return true before submitting
|
||||
- submit => [ form-selector, { params } ] (done)
|
||||
on click submit the form specified by form-selector with the additional params
|
||||
- function => function-name (done)
|
||||
on click call the specified function (is this a special case of checks?)
|
||||
8817139d | Moritz Bunkus | - disabled => true/false/tooltip explaning why disabled (done)
|
||
3dc29e42 | Sven Schöling | |||
TODO:
|
||||
- runtime disable/enable
|