diff --git a/cms/static/js/models/feedback.js b/cms/static/js/models/feedback.js index 34eaec0d69..54873f4147 100644 --- a/cms/static/js/models/feedback.js +++ b/cms/static/js/models/feedback.js @@ -4,7 +4,8 @@ CMS.Models.SystemFeedback = Backbone.Model.extend({ "title": null, "message": null, "shown": true, - "close": false // show a close button? + "close": false, // show a close button? + "icon": true // show an icon? /* could also have an "actions" hash: here is an example demonstrating the expected structure "actions": { @@ -28,5 +29,11 @@ CMS.Models.SystemFeedback = Backbone.Model.extend({ ] } */ + }, + show: function() { + this.set("shown", true); + }, + hide: function() { + this.set("shown", false); } }); diff --git a/cms/static/js/views/feedback.js b/cms/static/js/views/feedback.js index 36b4e1d7cb..e1c1344f6b 100644 --- a/cms/static/js/views/feedback.js +++ b/cms/static/js/views/feedback.js @@ -1,20 +1,27 @@ CMS.Views.SystemFeedback = Backbone.View.extend({ initialize: function() { - this.setElement(document.getElementById(this.id)); + this.setElement($("#page-"+this.type)); this.listenTo(this.model, 'change', this.render); return this.render(); }, + template: _.template($("#system-feedback-tpl").text()), render: function() { - this.$el.html(this.template(this.model.attributes)); + var attrs = this.model.attributes; + if(attrs.type) { + attrs.modelType = attrs.type; + delete attrs.type; + } + attrs.viewType = this.type; + this.$el.html(this.template(attrs)); return this; }, events: { - "click .action-alert-close": "hide", + "click .action-close": "hide", "click .action-primary": "primaryClick", "click .action-secondary": "secondaryClick" }, hide: function() { - this.model.set("shown", false); + this.model.hide(); }, primaryClick: function() { var primary = this.model.get("actions").primary; @@ -37,6 +44,20 @@ CMS.Views.SystemFeedback = Backbone.View.extend({ }); CMS.Views.Alert = CMS.Views.SystemFeedback.extend({ - template: _.template($("#alert-tpl").text()), - id: "page-alert" + type: "alert" +}); +CMS.Views.Notification = CMS.Views.SystemFeedback.extend({ + type: "notification" +}); +CMS.Views.Prompt = CMS.Views.SystemFeedback.extend({ + type: "prompt", + render: function() { + if(this.model.get('shown')) { + $body.addClass('prompt-is-shown'); + } else { + $body.removeClass('prompt-is-shown'); + } + // super() in Javascript has awkward syntax :( + return CMS.Views.SystemFeedback.prototype.render.apply(this, arguments); + } }); diff --git a/cms/static/js/views/server_error.js b/cms/static/js/views/server_error.js index 4b95bf176f..71b2a2ca6f 100644 --- a/cms/static/js/views/server_error.js +++ b/cms/static/js/views/server_error.js @@ -3,8 +3,15 @@ CMS.ServerError = function(model, error) { "type": "error", "title": "Server Error", "message": error.responseText, - "close": true + "actions": { + "primary": { + "text": "Dismiss", + "click": function(model) { + model.hide(); + } + } + } }); - new CMS.Views.Alert({model: m}); + new CMS.Views.Notification({model: m}); return m; }; diff --git a/cms/templates/base.html b/cms/templates/base.html index f14e2fa447..34637b03c2 100644 --- a/cms/templates/base.html +++ b/cms/templates/base.html @@ -53,15 +53,23 @@ <%text> -