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
This commit is contained in:
Lin Hua Cheng 2013-03-06 16:21:12 -08:00
parent f38cd451df
commit b87398d90b
4 changed files with 34 additions and 0 deletions

View File

@ -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();
});

View File

@ -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 }}
};
</script>
{% endcompress %}

View File

@ -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,

View File

@ -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,