Revision 3dc29e42
Von Sven Schöling vor fast 8 Jahren hinzugefügt
SL/Layout/ActionBar/Action.pm | ||
---|---|---|
6 | 6 |
use SL::Presenter; |
7 | 7 |
|
8 | 8 |
use Rose::Object::MakeMethods::Generic ( |
9 |
'scalar --get_set_init' => [ qw(id) ], |
|
9 |
'scalar --get_set_init' => [ qw(id params text) ],
|
|
10 | 10 |
); |
11 | 11 |
|
12 | 12 |
# subclassing interface |
... | ... | |
16 | 16 |
} |
17 | 17 |
|
18 | 18 |
sub script { |
19 |
die 'needs to be implemented';
|
|
19 |
sprintf q|$('#%s').data('action', %s);|, $_[0]->id, JSON->new->allow_blessed->convert_blessed->encode($_[0]->params);
|
|
20 | 20 |
} |
21 | 21 |
|
22 |
|
|
23 | 22 |
# static constructors |
24 | 23 |
|
25 | 24 |
sub from_descriptor { |
26 |
my ($class, $descriptor) = @_;a |
|
25 |
my ($class, $descriptor) = @_; |
|
26 |
require SL::Layout::ActionBar::Separator; |
|
27 | 27 |
|
28 | 28 |
{ |
29 | 29 |
separator => SL::Layout::ActionBar::Separator->new, |
... | ... | |
38 | 38 |
|
39 | 39 |
if ($params{submit}) { |
40 | 40 |
require SL::Layout::ActionBar::Submit; |
41 |
return SL::Layout::ActionBar::Submit->new(text => $text, %params); |
|
41 |
return SL::Layout::ActionBar::Submit->new(text => $text, params => \%params);
|
|
42 | 42 |
} |
43 | 43 |
|
44 | 44 |
if ($params{function}) { |
45 | 45 |
require SL::Layout::ActionBar::ScriptButton; |
46 |
return SL::Layout::ActionBar::ScriptButton->new(text => $text, %params); |
|
46 |
return SL::Layout::ActionBar::ScriptButton->new(text => $text, params => \%params);
|
|
47 | 47 |
} |
48 | 48 |
|
49 | 49 |
if ($params{combobox}) { |
... | ... | |
66 | 66 |
1; |
67 | 67 |
|
68 | 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 |
|
SL/Layout/ActionBar/ScriptButton.pm | ||
---|---|---|
3 | 3 |
use strict; |
4 | 4 |
use parent qw(SL::Layout::ActionBar::Action); |
5 | 5 |
|
6 |
use JSON; |
|
7 |
|
|
8 |
use Rose::Object::MakeMethods::Generic ( |
|
9 |
'scalar --get_set_init' => [ qw(text function) ], |
|
10 |
); |
|
11 |
|
|
12 | 6 |
sub render { |
13 | 7 |
$_[0]->p->html_tag('div', $_[0]->text, |
14 | 8 |
id => $_[0]->id, |
... | ... | |
16 | 10 |
); |
17 | 11 |
} |
18 | 12 |
|
19 |
sub script { |
|
20 |
# store submit and form and stuff in data attribute |
|
21 |
sprintf q|$('#%s').data('action', %s);|, $_[0]->id, JSON::to_json({ |
|
22 |
function => $_[0]->function, |
|
23 |
}); |
|
24 |
} |
|
25 |
|
|
26 | 13 |
1; |
SL/Layout/ActionBar/Submit.pm | ||
---|---|---|
3 | 3 |
use strict; |
4 | 4 |
use parent qw(SL::Layout::ActionBar::Action); |
5 | 5 |
|
6 |
use JSON; |
|
7 |
|
|
8 |
use Rose::Object::MakeMethods::Generic ( |
|
9 |
'scalar --get_set_init' => [ qw(text submit) ], |
|
10 |
); |
|
11 |
|
|
12 | 6 |
sub render { |
13 | 7 |
$_[0]->p->html_tag('div', $_[0]->text, |
14 | 8 |
id => $_[0]->id, |
... | ... | |
16 | 10 |
); |
17 | 11 |
} |
18 | 12 |
|
19 |
sub script { |
|
20 |
# store submit and form and stuff in data attribute |
|
21 |
sprintf q|$('#%s').data('action', %s);|, $_[0]->id, JSON::to_json({ |
|
22 |
submit => $_[0]->submit, |
|
23 |
}); |
|
24 |
} |
|
25 |
|
|
26 | 13 |
1; |
SL/Layout/Base.pm | ||
---|---|---|
330 | 330 |
|
331 | 331 |
=head1 BUGS |
332 | 332 |
|
333 |
None yet, if you don't count the horrible stylesheet/javascript interface. |
|
333 |
* stylesheet/javascript interface is a horrible mess. |
|
334 |
|
|
335 |
* It's currently not possible to do compositor layouts without assupmtions |
|
336 |
about the position of the content. That's because the content will return |
|
337 |
control to the actual controller, so the layouts need to know where to split |
|
338 |
pre- and post-content. |
|
334 | 339 |
|
335 | 340 |
=head1 AUTHOR |
336 | 341 |
|
css/lx-office-erp/main.css | ||
---|---|---|
543 | 543 |
} |
544 | 544 |
|
545 | 545 |
div.layout-actionbar-action { |
546 |
-webkit-touch-callout: none; /* iOS Safari */ |
|
547 |
-webkit-user-select: none; /* Chrome/Safari/Opera */ |
|
548 |
-khtml-user-select: none; /* Konqueror */ |
|
549 |
-moz-user-select: none; /* Firefox */ |
|
550 |
-ms-user-select: none; /* Internet Explorer/Edge */ |
|
551 |
user-select: none; /* don't select text on double click */ |
|
546 | 552 |
transition: background-color 0s; |
547 | 553 |
-moz-transition: background-color 0s; |
548 | 554 |
-webkit-transition: background-color 0s; |
... | ... | |
575 | 581 |
-moz-border-radius: 2px; |
576 | 582 |
border-radius: 2px; |
577 | 583 |
} |
584 |
|
|
585 |
div.layout-actionbar div.layout-actionbar-action-disabled, |
|
586 |
div.layout-actionbar div.layout-actionbar-action-disabled:hover { |
|
587 |
color: gray; |
|
588 |
background-color: whitesmoke; |
|
589 |
border-color: lightgray; |
|
590 |
} |
js/kivi.ActionBar.js | ||
---|---|---|
3 | 3 |
|
4 | 4 |
k.ActionBarAction = function(e) { |
5 | 5 |
var data = $(e).data('action'); |
6 |
|
|
7 |
if (data.disabled) |
|
8 |
$(e).addClass('layout-actionbar-action-disabled'); |
|
6 | 9 |
// dispatch as needed |
7 | 10 |
if (data.submit) { |
8 | 11 |
var form = data.submit[0]; |
9 | 12 |
var params = data.submit[1]; |
10 | 13 |
$(e).click(function(event) { |
11 |
var $hidden, key; |
|
14 |
var $hidden, key, func; |
|
15 |
if (data.disabled) return; |
|
16 |
if (data.confirm && !confirm(data.confirm)) return; |
|
17 |
if (data.checks) { |
|
18 |
for (var check in data.check) { |
|
19 |
func = kivi.get_function_by_name(check); |
|
20 |
if (!func()) return; |
|
21 |
} |
|
22 |
} |
|
12 | 23 |
for (key in params) { |
13 | 24 |
$hidden = $('<input type=hidden>') |
14 | 25 |
$hidden.attr('name', key) |
... | ... | |
21 | 32 |
// TODO: what to do with templated calls |
22 | 33 |
console.log(data.function) |
23 | 34 |
$(e).click(function(event) { |
24 |
var func = kivi.get_function_by_name(data.function[0]); |
|
35 |
var func; |
|
36 |
if (data.disabled) return; |
|
37 |
if (data.confirm && !confirm(data.confirm)) return; |
|
38 |
if (data.checks) { |
|
39 |
for (var check in data.check) { |
|
40 |
func = kivi.get_function_by_name(check); |
|
41 |
if (!func()) return; |
|
42 |
} |
|
43 |
} |
|
44 |
func = kivi.get_function_by_name(data.function[0]); |
|
25 | 45 |
func.apply(document, data.function.slice(1)) |
26 | 46 |
}); |
27 | 47 |
} |
Auch abrufbar als: Unified diff
ActionBar: calling conventions geändert, +check/disabled/confirm