Commit fcf4cdc7 by David Baumgold

Implement minShown and maxShown for notification views

parent 91c2594c
...@@ -31,7 +31,8 @@ CMS.Models.Section = Backbone.Model.extend({ ...@@ -31,7 +31,8 @@ CMS.Models.Section = Backbone.Model.extend({
if(!this.msgView) { if(!this.msgView) {
this.msgView = new CMS.Views.Notification({ this.msgView = new CMS.Views.Notification({
model: this.msg, model: this.msg,
closeIcon: false closeIcon: false,
minShown: 1000
}); });
} }
this.msgView.show(); this.msgView.show();
......
...@@ -2,13 +2,15 @@ CMS.Views.Alert = Backbone.View.extend({ ...@@ -2,13 +2,15 @@ CMS.Views.Alert = Backbone.View.extend({
options: { options: {
type: "alert", type: "alert",
shown: true, // is this view currently being shown? 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() { initialize: function() {
this.template = _.template($("#"+this.options.type+"-tpl").text()), this.template = _.template($("#"+this.options.type+"-tpl").text()),
this.setElement($("#page-"+this.options.type)); this.setElement($("#page-"+this.options.type));
this.listenTo(this.model, 'change', this.render); this.listenTo(this.model, 'change', this.render);
return this.render(); return this.show();
}, },
render: function() { render: function() {
var attrs = $.extend({}, this.options, this.model.attributes); var attrs = $.extend({}, this.options, this.model.attributes);
...@@ -21,12 +23,28 @@ CMS.Views.Alert = Backbone.View.extend({ ...@@ -21,12 +23,28 @@ CMS.Views.Alert = Backbone.View.extend({
"click .action-secondary": "secondaryClick" "click .action-secondary": "secondaryClick"
}, },
show: function() { show: function() {
clearTimeout(this.hideTimeout);
this.options.shown = true; 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() { hide: function() {
this.options.shown = false; if(this.shownAt && $.isNumeric(this.options.minShown) &&
return this.render(); 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;
delete this.shownAt;
this.render();
}
return this;
}, },
primaryClick: function() { primaryClick: function() {
var actions = this.model.get("actions"); 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