Skip to content

Instantly share code, notes, and snippets.

@GCheung55
Forked from hotsoft-desenv4/marcas-form.js
Last active May 29, 2020 00:48
Show Gist options
  • Save GCheung55/e7951c16334b68566eda14f55147f80d to your computer and use it in GitHub Desktop.
Save GCheung55/e7951c16334b68566eda14f55147f80d to your computer and use it in GitHub Desktop.
//app/components/marcas/marcas-form.js
import Component from '@ember/component';
export default Component.extend({
//https://guides.emberjs.com/v3.3.0/components/triggering-changes-with-actions/
//https://github.com/ember-cli/eslint-plugin-ember/blob/master/docs/rules/closure-actions.md
// Noop, needs to be overriden
onSave() {},
actions: {
saveMarca(marca) {
marca.save().then(() => {
return this.onSave();
});
}
}
});
//app/routes/marcas/new.js
import Component from '@ember/component';
export default Component.extend({
actions: {
deleteMarca(marca) {
marca.destroyRecord();
}
}
});
//app/routes/marcas/new.js
import Controller from '@ember/controller';
export default Controller.extend({
actions: {
redirectTo() {
return this.transitionTo('marca');
}
}
});
{{!--app/templates/marcas/new.hbs --}}
<h2>Criar nova marca</h2>
{{!-- https://github.com/ember-cli/eslint-plugin-ember/blob/master/docs/rules/closure-actions.md --}}
{{marcas/marcas-form
model="model"
onSave=(action "redirectTo")
}}
//app/routes/marcas/new.js
import Route from '@ember/routing/route';
export default Route.extend({
model() {
return this.store.createRecord('marca');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment