Commit 5c2116a4 by David Baumgold

Make abstract view, make Alert inherit from it

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