This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
const { run } = Ember; | |
import { moduleForModel, test } from 'ember-qunit'; | |
import startMirage from '../../helpers/setup-mirage-for-integration'; | |
import Pretender from 'pretender'; | |
let expense, store, user, serverz; | |
moduleForModel('expense', 'Unit | Model | expense', { | |
// belongsTo User w/ validation from ember-cp-validations |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* app/routes/application.js */ | |
cancel(model, transitionToRoute) { | |
// relationshipsIsDirty is custom. hasDirtyAttributes comes with Ember Data | |
if (model.get('hasDirtyAttributes') || model.get('relationshipsIsDirty')) { | |
Ember.$('#crud').openModal(); | |
// other stuff....attach the model and transitionToRoute to a transition service to be used when user clicks yes/no in modal | |
} else { | |
if (model.get('isNew')) { | |
model.deleteRecord(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* app/routes/application.js */ | |
cancel(model, transitionToRoute) { | |
// relationshipsIsDirty is custom. hasDirtyAttributes comes with Ember Data | |
if (model.get('hasDirtyAttributes') || model.get('relationshipsIsDirty')) { | |
Ember.$('#crud').openModal(); | |
// other stuff....attach the model and transitionToRoute to a transition service to be used when user clicks yes/no in modal | |
} else { | |
if (model.get('isNew')) { | |
model.deleteRecord(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default DS.Model.extend(DirtyCheck, SaveRelated, Rollback, { | |
interests: hasMany(), | |
interestsIds: attr(), | |
location: belongsTo(), | |
locationId: attr(), | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* app/mixins/dirty-check.js */ | |
import Ember from ‘ember’; | |
var RelationshipDirtyCheck = Ember.Mixin.create({ | |
relationshipDirtyCheck: Ember.computed(‘location’, ‘locationId’, ‘interests.[]’, ‘interestsIds’, function() { | |
const model = this; | |
let _dirty = false; | |
this.eachRelationship((name, meta) => { | |
if (meta.kind === ‘belongsTo’){ | |
if (model.get(name) && model.get(name).get(‘id’) !== this.get(`${name}Id`)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* app/serializers/application.js */ | |
normalizeFindRecordResponse(store, primaryModelClass, payload) { | |
const _p = payload.data; | |
const relationships = _p.relationships; | |
if (relationships) { | |
Object.keys(_p.relationships).forEach((related_key) => { | |
// m2m | |
if (Array.isArray(relationships[related_key].data)) { | |
_p.attributes[`${related_key}-ids`] = relationships[related_key].data.mapBy(‘id’); | |
// belongs_to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
actions: { | |
someAction() { | |
console.log('Clicked!'); | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
didInsertElement() { | |
this.destroy(); | |
} | |
}); |