DeleteModel Mixin
This commit is contained in:
parent
cc85ee6f27
commit
3f5eb26a33
3 changed files with 31 additions and 9 deletions
15
app/mixins/delete-model.js
Normal file
15
app/mixins/delete-model.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
import Ember from 'ember';
|
||||
|
||||
const { Mixin } = Ember;
|
||||
|
||||
export default Mixin.create({
|
||||
transitionRoute: null,
|
||||
|
||||
actions: {
|
||||
delete: function() {
|
||||
this.get('model').destroyRecord().then(() => {
|
||||
this.transitionToRoute(this.get('transitionRoute'));
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
|
@ -1,14 +1,9 @@
|
|||
import Ember from 'ember';
|
||||
import DeleteModel from '../../../../mixins/delete-model';
|
||||
|
||||
const { Controller } = Ember;
|
||||
|
||||
export default Controller.extend({
|
||||
actions: {
|
||||
delete: function() {
|
||||
this.get('model').destroyRecord().then(() => {
|
||||
this.transitionToRoute('protected.species.index');
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
export default Controller.extend(DeleteModel, {
|
||||
// Required for DeleteModel mixin
|
||||
transitionRoute: 'protected.species.index',
|
||||
});
|
||||
|
|
12
tests/unit/mixins/delete-model-test.js
Normal file
12
tests/unit/mixins/delete-model-test.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
import Ember from 'ember';
|
||||
import DeleteModelMixin from '../../../mixins/delete-model';
|
||||
import { module, test } from 'qunit';
|
||||
|
||||
module('Unit | Mixin | delete model');
|
||||
|
||||
// Replace this with your real tests.
|
||||
test('it works', function(assert) {
|
||||
var DeleteModelObject = Ember.Object.extend(DeleteModelMixin);
|
||||
var subject = DeleteModelObject.create();
|
||||
assert.ok(subject);
|
||||
});
|
Reference in a new issue