Skip to content

Commit

Permalink
Issue kimchi-project#79: All error messages should keep on UI until u…
Browse files Browse the repository at this point in the history
…ser dismiss it

This commit also fixes a bug where alert "close" buttons would close modal windows.

Signed-off-by: Samuel Guimarães <[email protected]>
  • Loading branch information
samhenri authored and alinefm committed Jun 27, 2016
1 parent 5843b31 commit e2c5025
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 34 deletions.
69 changes: 36 additions & 33 deletions ui/js/src/wok.message.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,53 +18,56 @@
* limitations under the License.
*/

wok.message = function(msg, level, node, closeable, onclick) {
wok.message = function(msg, level, node, closeable, onclick, alertId) {
"use strict";
var close = closeable || true;
var container = node || $('#alert-fields');
if ($(container).size() < 1) {
container = $('<div id="alert-fields"/>').appendTo($('#alert-container'));
}
var message = '<div role="alert" class="alert ' + (level || '') + ' alert-dismissible fade in" style="display: none;">';
if(!node || closeable) {
message += '<button type="button" class="close" data-dismiss="alert" aria-label="Close" onclick="' + (onclick || '') + '"><span aria-hidden="true"><i class="fa fa-times-circle"></i></span></button>';
}
message += msg;
message += '</div>';
var $message = $(message);
$(container).show();
$(container).append($message);
$message.alert();
$message.fadeIn(100);
if($("#" + alertId).length === 0) {
if ($(container).size() < 1) {
container = $('<div id="alert-fields"/>').appendTo($('#alert-container'));
}
var message = '<div '+( alertId ? 'id="'+alertId+'"' : '')+' role="alert" class="alert ' + (level || '') + ' '+( close ? 'alert-dismissible' : '')+' fade in" style="display: none;">';
if(!node || close) {
message += '<button type="button" class="close" data-dismiss="alert" aria-label="Close" onclick="' + (onclick || '') + '"><span aria-hidden="true"><i class="fa fa-times-circle"></i></span></button>';
}
message += msg;
message += '</div>';
var $message = $(message);
$(container).show();
$(container).append($message);
$message.alert();
$message.fadeIn(100);

if(!closeable){
var timeout = setTimeout(function() {
$message.delay(4000).fadeOut(100, function() {
$message.alert('close');
$(this).remove();
if ($(container).children().length < 1) {
$(container).hide();
}
});
}, 10000);
if(!close){
var timeout = setTimeout(function() {
$message.delay(4000).fadeOut(100, function() {
$message.alert('close');
$(this).remove();
if ($(container).children().length < 1) {
$(container).hide();
}
});
}, 10000);
}
}
};

wok.message.warn = function(msg, node, closeable) {
wok.message.warn = function(msg, node, closeable, alertId) {
"use strict";
wok.message(msg, 'alert-warning', node, closeable);
wok.message(msg, 'alert-warning', node, closeable, null, alertId);
};
wok.message.error = function(msg, node, closeable) {
wok.message.error = function(msg, node, closeable, alertId) {
"use strict";
wok.message(msg, 'alert-danger', node, closeable);
wok.message(msg, 'alert-danger', node, closeable, null, alertId);
};
wok.message.error.code = function(code, node, closeable) {
wok.message.error.code = function(code, node, closeable, alertId) {
"use strict";
var msg = code + ": " + i18n[code];
wok.message(msg, 'alert-danger', node, closeable);
wok.message(msg, 'alert-danger', node, closeable, null, alertId);
};
wok.message.success = function(msg, node, closeable) {
wok.message.success = function(msg, node, closeable, alertId) {
"use strict";
wok.message(msg, 'alert-success', node, closeable);
wok.message(msg, 'alert-success', node, closeable, null, alertId);
};
wok.message.notify = function(notification, node) {
"use strict";
Expand Down
2 changes: 1 addition & 1 deletion ui/js/src/wok.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ wok.window = (function() {
$('#' + windowID).remove();
});

$(windowNode).appendTo('#' + target).on('click', '.window .close', function() {
$(windowNode).appendTo('#' + target).on('click', '.modal-header > .close', function() {
wok.window.close();
});

Expand Down

0 comments on commit e2c5025

Please sign in to comment.