Make abstract view, make Alert inherit from it
This commit is contained in:
@@ -1,17 +1,42 @@
|
||||
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"
|
||||
});
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
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">
|
||||
|
||||
Reference in New Issue
Block a user