From 3dc29e42a53f674d4a5b745663b1f85b54131de2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Fri, 7 Oct 2016 18:21:12 +0200 Subject: [PATCH] =?utf8?q?ActionBar:=20calling=20conventions=20ge=C3=A4nde?= =?utf8?q?rt,=20+check/disabled/confirm?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Layout/ActionBar/Action.pm | 35 ++++++++++++++++++++++++----- SL/Layout/ActionBar/ScriptButton.pm | 13 ----------- SL/Layout/ActionBar/Submit.pm | 13 ----------- SL/Layout/Base.pm | 7 +++++- css/lx-office-erp/main.css | 13 +++++++++++ js/kivi.ActionBar.js | 24 ++++++++++++++++++-- 6 files changed, 70 insertions(+), 35 deletions(-) diff --git a/SL/Layout/ActionBar/Action.pm b/SL/Layout/ActionBar/Action.pm index 454255c8c..8ac1d2d63 100644 --- a/SL/Layout/ActionBar/Action.pm +++ b/SL/Layout/ActionBar/Action.pm @@ -6,7 +6,7 @@ use parent qw(Rose::Object); use SL::Presenter; use Rose::Object::MakeMethods::Generic ( - 'scalar --get_set_init' => [ qw(id) ], + 'scalar --get_set_init' => [ qw(id params text) ], ); # subclassing interface @@ -16,14 +16,14 @@ sub render { } sub script { - die 'needs to be implemented'; + sprintf q|$('#%s').data('action', %s);|, $_[0]->id, JSON->new->allow_blessed->convert_blessed->encode($_[0]->params); } - # static constructors sub from_descriptor { - my ($class, $descriptor) = @_;a + my ($class, $descriptor) = @_; + require SL::Layout::ActionBar::Separator; { separator => SL::Layout::ActionBar::Separator->new, @@ -38,12 +38,12 @@ sub simple { if ($params{submit}) { require SL::Layout::ActionBar::Submit; - return SL::Layout::ActionBar::Submit->new(text => $text, %params); + return SL::Layout::ActionBar::Submit->new(text => $text, params => \%params); } if ($params{function}) { require SL::Layout::ActionBar::ScriptButton; - return SL::Layout::ActionBar::ScriptButton->new(text => $text, %params); + return SL::Layout::ActionBar::ScriptButton->new(text => $text, params => \%params); } if ($params{combobox}) { @@ -66,3 +66,26 @@ sub init_id { 1; __END__ + +=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?) + +- disabled => true/false (done) + +TODO: + +- runtime disable/enable + diff --git a/SL/Layout/ActionBar/ScriptButton.pm b/SL/Layout/ActionBar/ScriptButton.pm index 47c1247af..501c15d23 100644 --- a/SL/Layout/ActionBar/ScriptButton.pm +++ b/SL/Layout/ActionBar/ScriptButton.pm @@ -3,12 +3,6 @@ package SL::Layout::ActionBar::ScriptButton; use strict; use parent qw(SL::Layout::ActionBar::Action); -use JSON; - -use Rose::Object::MakeMethods::Generic ( - 'scalar --get_set_init' => [ qw(text function) ], -); - sub render { $_[0]->p->html_tag('div', $_[0]->text, id => $_[0]->id, @@ -16,11 +10,4 @@ sub render { ); } -sub script { - # store submit and form and stuff in data attribute - sprintf q|$('#%s').data('action', %s);|, $_[0]->id, JSON::to_json({ - function => $_[0]->function, - }); -} - 1; diff --git a/SL/Layout/ActionBar/Submit.pm b/SL/Layout/ActionBar/Submit.pm index 751a96915..a277e3be2 100644 --- a/SL/Layout/ActionBar/Submit.pm +++ b/SL/Layout/ActionBar/Submit.pm @@ -3,12 +3,6 @@ package SL::Layout::ActionBar::Submit; use strict; use parent qw(SL::Layout::ActionBar::Action); -use JSON; - -use Rose::Object::MakeMethods::Generic ( - 'scalar --get_set_init' => [ qw(text submit) ], -); - sub render { $_[0]->p->html_tag('div', $_[0]->text, id => $_[0]->id, @@ -16,11 +10,4 @@ sub render { ); } -sub script { - # store submit and form and stuff in data attribute - sprintf q|$('#%s').data('action', %s);|, $_[0]->id, JSON::to_json({ - submit => $_[0]->submit, - }); -} - 1; diff --git a/SL/Layout/Base.pm b/SL/Layout/Base.pm index c2590449c..ba2db6017 100644 --- a/SL/Layout/Base.pm +++ b/SL/Layout/Base.pm @@ -330,7 +330,12 @@ classes, which should be changed. The other points work pretty well. =head1 BUGS -None yet, if you don't count the horrible stylesheet/javascript interface. +* stylesheet/javascript interface is a horrible mess. + +* It's currently not possible to do compositor layouts without assupmtions +about the position of the content. That's because the content will return +control to the actual controller, so the layouts need to know where to split +pre- and post-content. =head1 AUTHOR diff --git a/css/lx-office-erp/main.css b/css/lx-office-erp/main.css index 2b9042cbf..db3536b8a 100644 --- a/css/lx-office-erp/main.css +++ b/css/lx-office-erp/main.css @@ -543,6 +543,12 @@ div.layout-actionbar { } div.layout-actionbar-action { + -webkit-touch-callout: none; /* iOS Safari */ + -webkit-user-select: none; /* Chrome/Safari/Opera */ + -khtml-user-select: none; /* Konqueror */ + -moz-user-select: none; /* Firefox */ + -ms-user-select: none; /* Internet Explorer/Edge */ + user-select: none; /* don't select text on double click */ transition: background-color 0s; -moz-transition: background-color 0s; -webkit-transition: background-color 0s; @@ -575,3 +581,10 @@ div.layout-actionbar div.layout-actionbar-scriptbutton:hover { -moz-border-radius: 2px; border-radius: 2px; } + +div.layout-actionbar div.layout-actionbar-action-disabled, +div.layout-actionbar div.layout-actionbar-action-disabled:hover { + color: gray; + background-color: whitesmoke; + border-color: lightgray; +} diff --git a/js/kivi.ActionBar.js b/js/kivi.ActionBar.js index aeba436d9..2c28d9b4c 100644 --- a/js/kivi.ActionBar.js +++ b/js/kivi.ActionBar.js @@ -3,12 +3,23 @@ namespace('kivi', function(k){ k.ActionBarAction = function(e) { var data = $(e).data('action'); + + if (data.disabled) + $(e).addClass('layout-actionbar-action-disabled'); // dispatch as needed if (data.submit) { var form = data.submit[0]; var params = data.submit[1]; $(e).click(function(event) { - var $hidden, key; + var $hidden, key, func; + if (data.disabled) return; + if (data.confirm && !confirm(data.confirm)) return; + if (data.checks) { + for (var check in data.check) { + func = kivi.get_function_by_name(check); + if (!func()) return; + } + } for (key in params) { $hidden = $('') $hidden.attr('name', key) @@ -21,7 +32,16 @@ namespace('kivi', function(k){ // TODO: what to do with templated calls console.log(data.function) $(e).click(function(event) { - var func = kivi.get_function_by_name(data.function[0]); + var func; + if (data.disabled) return; + if (data.confirm && !confirm(data.confirm)) return; + if (data.checks) { + for (var check in data.check) { + func = kivi.get_function_by_name(check); + if (!func()) return; + } + } + func = kivi.get_function_by_name(data.function[0]); func.apply(document, data.function.slice(1)) }); } -- 2.20.1