From 5bc3c720b5c6f422ca3fa63d6d400d3a46fd633d Mon Sep 17 00:00:00 2001 From: Martin Helmling Date: Thu, 28 May 2015 17:51:42 +0200 Subject: [PATCH] Flashanzeige erweitert: Nun auch Details MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Für alle drei Flashanzeigen gibt es Detailanzeigen/optionalen Timeout Details als textueller Link [Details] ebenfalls wird Fenster nach oben gescrolled, damit flash info sichtbar ist. Bei einigen Fehlermeldungen, z.B. bei LaTex Fehlern empfiehlt es sich, kleinere Fehlermeldungen anzuzeigen, die dem Kunden verständlicher sind, in den Details kann der lange Fehlertext (z.B auch sql Fehler) angezeigt werden Änderung in clientjs: nach Ausgabe einer Flash Anzeige (Info/Warning/Error) wird nach oben gesprungen ( derzeit zum frame-header). Damit wird die Anzeige auf jeden Fall sichtbar. Flashanzeige erweitert: Funktion zum Text löschen nach Timeout Bei neuen Controllern, die per AJAX laufen, ist es empfehlenswert bestimmte Texte nach einer gewissen Zeit implizit zu löschen, damit eine weitere identische Anzeige erkennbar ist. Die Funktion ist derzeit explizit per js->run('kivi.clear_flash','info',10000) im Controller einzubauen, ggf, später als eigenständige clientjs - Funktion --- SL/ClientJS.pm | 22 +++++++++++++++++++++- js/client_js.js | 20 ++++++++++++++++++++ scripts/generate_client_js_actions.tpl | 9 +++++++++ templates/webpages/common/flash.html | 16 ++++++++++++++-- 4 files changed, 64 insertions(+), 3 deletions(-) diff --git a/SL/ClientJS.pm b/SL/ClientJS.pm index 91c9e1abe..4cdb2037e 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 _error) ], + 'scalar --get_set_init' => [ qw(controller _actions _flash _flash_detail _error) ], ); my %supported_methods = ( @@ -115,6 +115,7 @@ my %supported_methods = ( redirect_to => 1, # window.location.href = flash => 2, # kivi.display_flash(, ) + flash_detail => 2, # kivi.display_flash_detail(, ) reinit_widgets => 0, # kivi.reinit_widgets() run => -1, # kivi.run(, ) run_once_for => 3, # kivi.run_once_for(, ) @@ -180,6 +181,10 @@ sub init__flash { return {}; } +sub init__flash_detail { + return {}; +} + sub init__error { return ''; } @@ -236,6 +241,21 @@ sub flash { return $self; } +sub flash_detail { + my ($self, $type, @messages) = @_; + + my $message = join '
', grep { $_ } @messages; + + if (!$self->_flash_detail->{$type}) { + $self->_flash_detail->{$type} = [ 'flash_detail', $type, $message ]; + push @{ $self->_actions }, $self->_flash_detail->{$type}; + } else { + $self->_flash_detail->{$type}->[-1] .= ' ' . $message; + } + + return $self; +} + sub error { my ($self, @messages) = @_; diff --git a/js/client_js.js b/js/client_js.js index 6d8981990..6b3784a5a 100644 --- a/js/client_js.js +++ b/js/client_js.js @@ -8,6 +8,22 @@ namespace("kivi", function(ns) { ns.display_flash = function(type, message) { $('#flash_' + type + '_content').text(message); $('#flash_' + type).show(); + $('#frame-header')[0].scrollIntoView(); +}; + +ns.display_flash_detail = function(type, message) { + $('#flash_' + type + '_detail').html(message); + $('#flash_' + type + '_disp').show(); +}; + +ns.clear_flash = function(category , timeout) { + window.setTimeout(function(){ + $('#flash_' + category).hide(); + $('#flash_detail_' + category).hide(); + $('#flash_' + category + '_disp').hide(); + $('#flash_' + category + '_content').empty(); + $('#flash_' + category + '_detail').empty(); + }, timeout); }; ns.eval_json_result = function(data) { @@ -19,7 +35,10 @@ ns.eval_json_result = function(data) { $(['info', 'warning', 'error']).each(function(idx, category) { $('#flash_' + category).hide(); + $('#flash_detail_' + category).hide(); + $('#flash_' + category + '_disp').hide(); $('#flash_' + category + '_content').empty(); + $('#flash_' + category + '_detail').empty(); }); if ((data.js || '') != '') @@ -128,6 +147,7 @@ ns.eval_json_result = function(data) { // ## other stuff ## else if (action[0] == 'redirect_to') window.location.href = action[1]; else if (action[0] == 'flash') kivi.display_flash(action[1], action[2]); + else if (action[0] == 'flash_detail') kivi.display_flash_detail(action[1], action[2]); else if (action[0] == 'reinit_widgets') kivi.reinit_widgets(); else if (action[0] == 'run') kivi.run(action[1], action.slice(2, action.length)); else if (action[0] == 'run_once_for') kivi.run_once_for(action[1], action[2], action[3]); diff --git a/scripts/generate_client_js_actions.tpl b/scripts/generate_client_js_actions.tpl index 9e2180289..50a427c45 100644 --- a/scripts/generate_client_js_actions.tpl +++ b/scripts/generate_client_js_actions.tpl @@ -8,6 +8,12 @@ namespace("kivi", function(ns) { ns.display_flash = function(type, message) { $('#flash_' + type + '_content').text(message); $('#flash_' + type).show(); + $('#frame-header')[0].scrollIntoView(); +}; + +ns.display_flash_detail = function(type, message) { + $('#flash_' + type + '_detail').html(message); + $('#flash_' + type + '_disp').show(); }; ns.eval_json_result = function(data) { @@ -19,7 +25,10 @@ ns.eval_json_result = function(data) { $(['info', 'warning', 'error']).each(function(idx, category) { $('#flash_' + category).hide(); + $('#flash_detail_' + category).hide(); + $('#flash_' + category + '_disp').hide(); $('#flash_' + category + '_content').empty(); + $('#flash_' + category + '_detail').empty(); }); if ((data.js || '') != '') diff --git a/templates/webpages/common/flash.html b/templates/webpages/common/flash.html index 4b705cdfc..1f537ac4a 100644 --- a/templates/webpages/common/flash.html +++ b/templates/webpages/common/flash.html @@ -1,14 +1,26 @@ [%- USE HTML -%][%- USE LxERP %][%- USE T8 %] [%- BLOCK output %] [%- END %] [%- PROCESS output title=LxERP.t8('Error') type='error' messages = FLASH.error %] -- 2.20.1