Commit fcf4cdc7 by David Baumgold

Implement minShown and maxShown for notification views

parent 91c2594c
......@@ -31,7 +31,8 @@ CMS.Models.Section = Backbone.Model.extend({
if(!this.msgView) {
this.msgView = new CMS.Views.Notification({
model: this.msg,
closeIcon: false
closeIcon: false,
minShown: 1000
});
}
this.msgView.show();
......
......@@ -2,13 +2,15 @@ CMS.Views.Alert = Backbone.View.extend({
options: {
type: "alert",
shown: true, // is this view currently being shown?
closeIcon: true // should we render a close button in the top right corner?
closeIcon: true, // should we render a close button in the top right corner?
minShown: 0, // length of time after this view has been shown before it can be hidden (milliseconds)
maxShown: Infinity // length of time after this view has been shown before it will be automatically hidden (milliseconds)
},
initialize: function() {
this.template = _.template($("#"+this.options.type+"-tpl").text()),
this.setElement($("#page-"+this.options.type));
this.listenTo(this.model, 'change', this.render);
return this.render();
return this.show();
},
render: function() {
var attrs = $.extend({}, this.options, this.model.attributes);
......@@ -21,12 +23,28 @@ CMS.Views.Alert = Backbone.View.extend({
"click .action-secondary": "secondaryClick"
},
show: function() {
clearTimeout(this.hideTimeout);
this.options.shown = true;
return this.render();
this.shownAt = new Date();
this.render();
if($.isNumeric(this.options.maxShown)) {
this.hideTimeout = setTimeout($.proxy(this.hide, this),
this.options.maxShown);
}
return this;
},
hide: function() {
if(this.shownAt && $.isNumeric(this.options.minShown) &&
this.options.minShown > new Date() - this.shownAt)
{
this.hideTimeout = setTimeout($.proxy(this.hide, this),
this.options.minShown - (new Date() - this.shownAt));
} else {
this.options.shown = false;
return this.render();
delete this.shownAt;
this.render();
}
return this;
},
primaryClick: function() {
var actions = this.model.get("actions");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment