Skip to content

Commit

Permalink
Merge pull request #7 from sir-dunxalot/develop
Browse files Browse the repository at this point in the history
Patch for context in save method
  • Loading branch information
Duncan Walker committed Mar 5, 2015
2 parents 24b3751 + 31ada7f commit f53e13c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
11 changes: 3 additions & 8 deletions addon/mixins/controllers/saving.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ export default Ember.Mixin.create(
validateAndSave: function() {
var _this = this;
var runCustomValidations = _this.runCustomValidations;
var save = _this.save;

var resolve = function() {
Ember.assert(
'You need to specify a save method on this controller',
save
typeof _this.save === 'function'
);

save();
_this.save();
};

var reject = function() {
Expand All @@ -52,11 +51,7 @@ export default Ember.Mixin.create(
if (runCustomValidations && !runCustomValidations.then) {
Ember.assert('runCustomValidations() must return a promise (e.g. return new Ember.RSVP.Promise()).');
} else if (runCustomValidations) {
runCustomValidations().then(function() {
resolve();
}, function() {
reject();
});
runCustomValidations().then(resolve, reject);
} else {

/* Else save with normal ember-validations checks */
Expand Down
4 changes: 4 additions & 0 deletions tests/dummy/app/resources/posts/new/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export default Ember.ObjectController.extend(
}
},

save: function() {
console.log(this);
},

cancel: function() {
this.transitionToRoute('index');
}
Expand Down

0 comments on commit f53e13c

Please sign in to comment.