Commit 5c2116a4 by David Baumgold

Make abstract view, make Alert inherit from it

parent 5ff2adb8
CMS.Views.Alert = Backbone.View.extend({ CMS.Views.SystemFeedback = Backbone.View.extend({
template: _.template($("#alert-tpl").text()),
initialize: function() { initialize: function() {
this.setElement($("#page-alert")); this.setElement(document.getElementById(this.id));
this.listenTo(this.model, 'change', this.render); this.listenTo(this.model, 'change', this.render);
return this.render();
}, },
render: function() { render: function() {
this.$el.html(this.template(this.model.attributes)); this.$el.html(this.template(this.model.attributes));
return this; return this;
}, },
events: { events: {
"click .action-alert-close": "hide" "click .action-alert-close": "hide",
"click .action-primary": "primaryClick",
"click .action-secondary": "secondaryClick"
}, },
hide: function() { hide: function() {
this.model.set("shown", false); this.model.set("shown", false);
},
primaryClick: function() {
var primary = this.model.get("actions").primary;
if(primary.click) {
primary.click(this.model);
}
},
secondaryClick: function(e) {
var secondaryList = this.model.get("actions").secondary;
if(!secondaryList) {
return;
}
// which secondary action was clicked?
var i = _.indexOf(this.$(".action-secondary"), e.target);
var secondary = this.model.get("actions").secondary[i];
if(secondary.click) {
secondary.click(this.model);
}
} }
}); });
CMS.Views.Alert = CMS.Views.SystemFeedback.extend({
template: _.template($("#alert-tpl").text()),
id: "page-alert"
});
CMS.ServerError = function(model, error) { CMS.ServerError = function(model, error) {
var m = new CMS.Models.Alert({ var m = new CMS.Models.SystemFeedback({
"type": "error", "type": "error",
"title": "Server Error", "title": "Server Error",
"message": error.responseText, "message": error.responseText,
"close": true "close": true
}); });
new CMS.Views.Alert({model: m}).render(); new CMS.Views.Alert({model: m});
return m;
}; };
...@@ -94,8 +94,8 @@ ...@@ -94,8 +94,8 @@
</div> </div>
</script> </script>
</%text> </%text>
<script src="${static.url('js/models/alert.js')}"></script> <script src="${static.url('js/models/feedback.js')}"></script>
<script src="${static.url('js/views/alert.js')}"></script> <script src="${static.url('js/views/feedback.js')}"></script>
<!-- view --> <!-- view -->
<div class="wrapper wrapper-view"> <div class="wrapper wrapper-view">
......
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