From aa8809a6fe7015f001643b74a5599aebdf6a2123 Mon Sep 17 00:00:00 2001 From: "Martin Helmling martin.helmling@octosoft.eu" Date: Mon, 7 Nov 2016 10:34:10 +0100 Subject: [PATCH] =?utf8?q?Automatisches=20L=C3=B6schen=20von=20Flashanzeig?= =?utf8?q?e=20unterdr=C3=BCckbar?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Bei jedem ClientJS call wird bisher vor Ausführung der Antwortdaten in Javascript die Info/Warnung/Fehleranzeige gelöscht. Bei periodischen ClientJS call kann das zu unerwünschten Effekten führen, z.B. eine Fehlermeldung wird so schnell gelöscht, dass sie nicht erkannt werden kann. Nun kann optional dies per $self->js->no_flash_clear abgeschaltet werden --- SL/ClientJS.pm | 27 ++++++++++++++++++++++++--- js/client_js.js | 3 ++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/SL/ClientJS.pm b/SL/ClientJS.pm index 91ff14b18..91a12576b 100644 --- a/SL/ClientJS.pm +++ b/SL/ClientJS.pm @@ -10,7 +10,7 @@ use SL::JSON (); use Rose::Object::MakeMethods::Generic ( scalar => [ qw() ], - 'scalar --get_set_init' => [ qw(controller _actions _flash _flash_detail _error) ], + 'scalar --get_set_init' => [ qw(controller _actions _flash _flash_detail _no_flash_clear _error) ], ); my %supported_methods = ( @@ -190,11 +190,15 @@ sub init__error { return ''; } +sub init__no_flash_clear { + return ''; +} + sub to_json { my ($self) = @_; - return SL::JSON::to_json({ error => $self->_error }) if $self->_error; - return SL::JSON::to_json({ eval_actions => $self->_actions }); + return SL::JSON::to_json({ error => $self->_error }) if $self->_error; + return SL::JSON::to_json({ no_flash_clear => $self->_no_flash_clear, eval_actions => $self->_actions }); } sub to_array { @@ -257,6 +261,12 @@ sub flash_detail { return $self; } +sub no_flash_clear{ + my ($self) = @_; + $self->_no_flash_clear('1'); + return $self; +} + sub error { my ($self, @messages) = @_; @@ -484,6 +494,17 @@ C on the same C<$self> will be merged by type. On the client side the flashes of all types will be cleared after each successful ClientJS call that did not end with C<$js-Eerror(...)>. +This clearing can be switched of by the function C + +=item C + +Display a detailed message C<$message> in the flash of type C<$type>. Multiple calls of +C on the same C<$self> will be merged by type. +So the flash message can be hold short and the visibility of details can toggled by the user. + +=item C + +No automatic clearing of flash after successful ClientJS call =item C diff --git a/js/client_js.js b/js/client_js.js index c592e4c8e..d29fca627 100644 --- a/js/client_js.js +++ b/js/client_js.js @@ -35,6 +35,7 @@ ns.eval_json_result = function(data) { if (data.error) return ns.display_flash('error', data.error); + if (!data.no_flash_clear) { $(['info', 'warning', 'error']).each(function(idx, category) { $('#flash_' + category).hide(); $('#flash_detail_' + category).hide(); @@ -42,7 +43,7 @@ ns.eval_json_result = function(data) { $('#flash_' + category + '_content').empty(); $('#flash_' + category + '_detail').empty(); }); - + } if ((data.js || '') != '') eval(data.js); -- 2.20.1