Message action callbacks have model set to this

This commit is contained in:
David Baumgold
2013-05-10 14:43:14 -04:00
parent f5f7cf705f
commit 1333717871
4 changed files with 10 additions and 9 deletions

View File

@@ -13,19 +13,20 @@ CMS.Models.SystemFeedback = Backbone.Model.extend({
"primary": {
"text": "Save",
"class": "action-save",
"click": function(model) {
"click": function() {
// do something when Save is clicked
// `this` refers to the model
}
},
"secondary": [
{
"text": "Cancel",
"class": "action-cancel",
"click": function(model) {}
"click": function() {}
}, {
"text": "Discard Changes",
"class": "action-discard",
"click": function(model) {}
"click": function() {}
}
]
}

View File

@@ -26,7 +26,7 @@ CMS.Views.SystemFeedback = Backbone.View.extend({
primaryClick: function() {
var primary = this.model.get("actions").primary;
if(primary.click) {
primary.click(this.model);
primary.click.call(this.model);
}
},
secondaryClick: function(e) {
@@ -38,7 +38,7 @@ CMS.Views.SystemFeedback = Backbone.View.extend({
var i = _.indexOf(this.$(".action-secondary"), e.target);
var secondary = this.model.get("actions").secondary[i];
if(secondary.click) {
secondary.click(this.model);
secondary.click.call(this.model);
}
}
});

View File

@@ -117,8 +117,8 @@ $(document).ajaxError(function(event, jqXHR, ajaxSettings, thrownError) {
"actions": {
"primary": {
"text": "Dismiss",
"click": function(model) {
model.hide();
"click": function() {
this.hide();
}
}
}

View File

@@ -248,8 +248,8 @@ CMS.Views.SectionEdit = Backbone.View.extend({
actions: {
primary: {
text: "Dismiss",
click: function(model) {
model.hide()
click: function() {
this.hide()
}
}
}