Fix #1335 Auto close alert after delay

This commit is contained in:
Nicolas Le Goff
2013-07-12 18:48:01 +02:00
parent 6ae2f29a52
commit f037a84d33
2 changed files with 8 additions and 1 deletions

View File

@@ -23,6 +23,7 @@ define([
if (options) {
this.alert = options.alert || "info";
this.message = options.message || "";
this.delay = parseInt(options.delay, 10) || 0;
}
// remove view when alert is closed
this.$el.bind("closed", function () {
@@ -30,12 +31,17 @@ define([
});
},
render: function() {
var self = this;
var template = _.template($("#alert_template").html(), {
msg: this.message
});
this.$el.addClass("alert-" + this.alert).html(template).alert();
if (this.delay > 0) {
window.setTimeout(function() { self.$el.alert('close') }, this.delay);
}
$(".block-alert").empty().append(this.$el);
return this;

View File

@@ -59,7 +59,8 @@ define([
new AlertView({
alert: "success",
message: i18n.t("fields_save")
message: i18n.t("fields_save"),
delay: 2000
}).render();
},
error: function(xhr, textStatus, errorThrown) {