ActionBar: calling conventions geƤndert, +check/disabled/confirm
[kivitendo-erp.git] / SL / Layout / ActionBar / Action.pm
1 package SL::Layout::ActionBar::Action;
2
3 use strict;
4 use parent qw(Rose::Object);
5
6 use SL::Presenter;
7
8 use Rose::Object::MakeMethods::Generic (
9   'scalar --get_set_init' => [ qw(id params text) ],
10 );
11
12 # subclassing interface
13
14 sub render {
15   die 'needs to be implemented';
16 }
17
18 sub script {
19   sprintf q|$('#%s').data('action', %s);|, $_[0]->id, JSON->new->allow_blessed->convert_blessed->encode($_[0]->params);
20 }
21
22 # static constructors
23
24 sub from_descriptor {
25   my ($class, $descriptor) = @_;
26   require SL::Layout::ActionBar::Separator;
27
28   {
29      separator => SL::Layout::ActionBar::Separator->new,
30   } or die 'unknown descriptor';
31 }
32
33 # TODO: this necessary?
34 sub simple {
35   my ($class, $data) = @_;
36
37   my ($text, %params) = @$data;
38
39   if ($params{submit}) {
40     require SL::Layout::ActionBar::Submit;
41     return SL::Layout::ActionBar::Submit->new(text => $text, params => \%params);
42   }
43
44   if ($params{function}) {
45     require SL::Layout::ActionBar::ScriptButton;
46     return SL::Layout::ActionBar::ScriptButton->new(text => $text, params => \%params);
47   }
48
49   if ($params{combobox}) {
50
51   }
52 }
53
54 # shortcut for presenter
55
56 sub p {
57   SL::Presenter->get
58 }
59
60 # unique id to tie div and javascript together
61 sub init_id {
62   $_[0]->p->name_to_id('action[]')
63 }
64
65
66 1;
67
68 __END__
69
70 =head 1
71
72 planned options for clickables:
73
74 - checks => [ ... ] (done)
75
76 a list of functions that need to return true before submitting
77
78 - submit => [ form-selector, { params } ] (done)
79
80 on click submit the form specified by form-selector with the additional params
81
82 - function => function-name (done)
83
84 on click call the specified function (is this a special case of checks?)
85
86 - disabled => true/false (done)
87
88 TODO:
89
90 - runtime disable/enable
91