From b87398d90b490103e11912243bb8b413c79f4ac1 Mon Sep 17 00:00:00 2001 From: Lin Hua Cheng Date: Wed, 6 Mar 2013 16:21:12 -0800 Subject: [PATCH] Implement configurable auto-fade for alerts messages. The configuration takes what alert types would fade, the delay before it fades and the fade out duration. Fixes bug 1144820 Change-Id: I421ee52308613da72118a507ed8b8b574c176f68 --- horizon/static/horizon/js/horizon.messages.js | 19 +++++++++++++++++++ horizon/templates/horizon/_conf.html | 5 +++++ .../local/local_settings.py.example | 5 +++++ openstack_dashboard/settings.py | 5 +++++ 4 files changed, 34 insertions(+) diff --git a/horizon/static/horizon/js/horizon.messages.js b/horizon/static/horizon/js/horizon.messages.js index e3ce88e67..7e9243217 100644 --- a/horizon/static/horizon/js/horizon.messages.js +++ b/horizon/static/horizon/js/horizon.messages.js @@ -27,6 +27,22 @@ horizon.clearAllMessages = function() { horizon.clearSuccessMessages(); }; +horizon.autoDismissAlerts = function() { + var $alerts = $('#main_content .messages .alert'); + + $alerts.each(function(index, alert) { + var $alert = $(this), + types = $alert.attr('class').split(' '); + + // Check if alert should auto-fade + if (_.intersection(types, horizon.conf.auto_fade_alerts.types).length > 0) { + setTimeout(function() { + $alert.fadeOut(horizon.conf.auto_fade_alerts.fade_duration); + }, horizon.conf.auto_fade_alerts.delay); + } + }); +} + horizon.addInitFunction(function () { // Bind AJAX message handling. $("body").ajaxComplete(function(event, request, settings){ @@ -43,4 +59,7 @@ horizon.addInitFunction(function () { // Bind dismiss(x) handlers for alert messages. $(".alert").alert(); + + // Hide alerts automatically if attribute data-dismiss-auto is set to true. + horizon.autoDismissAlerts(); }); diff --git a/horizon/templates/horizon/_conf.html b/horizon/templates/horizon/_conf.html index 2dc70fa0f..d577f1f74 100644 --- a/horizon/templates/horizon/_conf.html +++ b/horizon/templates/horizon/_conf.html @@ -12,5 +12,10 @@ horizon.conf.static_url = "{{ STATIC_URL }}"; horizon.conf.ajax = { queue_limit: {{ HORIZON_CONFIG.ajax_queue_limit|default:"null" }} }; +horizon.conf.auto_fade_alerts = { + delay: {{ HORIZON_CONFIG.auto_fade_alerts.delay|default:"3000" }}, + fade_duration: {{ HORIZON_CONFIG.auto_fade_alerts.fade_duration|default:"1500" }}, + types: {{ HORIZON_CONFIG.auto_fade_alerts.types|default:"[]"|safe }} +}; {% endcompress %} diff --git a/openstack_dashboard/local/local_settings.py.example b/openstack_dashboard/local/local_settings.py.example index 9202c6cb5..d4a71d4c9 100644 --- a/openstack_dashboard/local/local_settings.py.example +++ b/openstack_dashboard/local/local_settings.py.example @@ -25,6 +25,11 @@ HORIZON_CONFIG = { 'default_dashboard': 'project', 'user_home': 'openstack_dashboard.views.get_user_home', 'ajax_queue_limit': 10, + 'auto_fade_alerts': { + 'delay': 3000, + 'fade_duration': 1500, + 'types': ['alert-success', 'alert-info'] + }, 'help_url': "http://docs.openstack.org", 'exceptions': {'recoverable': exceptions.RECOVERABLE, 'not_found': exceptions.NOT_FOUND, diff --git a/openstack_dashboard/settings.py b/openstack_dashboard/settings.py index da899449f..d568533ba 100644 --- a/openstack_dashboard/settings.py +++ b/openstack_dashboard/settings.py @@ -59,6 +59,11 @@ HORIZON_CONFIG = { 'default_dashboard': 'project', 'user_home': 'openstack_dashboard.views.get_user_home', 'ajax_queue_limit': 10, + 'auto_fade_alerts': { + 'delay': 3000, + 'fade_duration': 1500, + 'types': ['alert-success', 'alert-info'] + }, 'help_url': "http://docs.openstack.org", 'exceptions': {'recoverable': exceptions.RECOVERABLE, 'not_found': exceptions.NOT_FOUND,