From 033ff530d20ab1e08119050fcfa297b3243e2b62 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Wed, 3 Jun 2015 13:38:40 -0800 Subject: [PATCH] Pulling stuff back out of strain component --- app/components/strains/strain-details.js | 16 +++++--------- app/controllers/strains/new.js | 21 +++++++++++++++++++ app/controllers/strains/show.js | 19 +++++++++++++++++ app/routes/strains/new.js | 8 +++---- app/routes/strains/show.js | 5 ++++- .../components/species/species-details.hbs | 1 + .../components/strains/strain-details.hbs | 4 ++-- app/templates/strains/new.hbs | 8 +++---- app/templates/strains/show.hbs | 9 +++++++- 9 files changed, 67 insertions(+), 24 deletions(-) create mode 100644 app/controllers/strains/new.js create mode 100644 app/controllers/strains/show.js diff --git a/app/components/strains/strain-details.js b/app/components/strains/strain-details.js index cd48959..58afb31 100644 --- a/app/components/strains/strain-details.js +++ b/app/components/strains/strain-details.js @@ -3,18 +3,12 @@ import Ember from 'ember'; export default Ember.Component.extend({ classNames: ['grid-1'], isEditing: false, - isNew: false, actions: { - editStrain: function() { - this.get('strain').get('errors').clear(); - if (this.get('isNew')) { - this.get('strain').destroyRecord().then(this.sendAction()); - } - this.toggleProperty('isEditing'); - this.get('strain').rollback(); + save: function() { + this.sendAction('save'); + }, + cancel: function() { + this.sendAction('cancel'); }, - saveStrain: function() { - this.get('strain').save().then(this.toggleProperty('isEditing')); - } } }); diff --git a/app/controllers/strains/new.js b/app/controllers/strains/new.js new file mode 100644 index 0000000..1bd3e90 --- /dev/null +++ b/app/controllers/strains/new.js @@ -0,0 +1,21 @@ +import Ember from 'ember'; + +export default Ember.Controller.extend({ + isEditing: true, + actions: { + save: function() { + var strain = this.get('strain'); + if (strain.get('isDirty')) { + strain.save(); + } + this.transitionToRoute('strains.index'); + }, + cancel: function() { + var strain = this.get('strain'); + if (strain.get('isNew')) { + strain.deleteRecord(); + } + this.transitionToRoute('strains.index'); + } + } +}); diff --git a/app/controllers/strains/show.js b/app/controllers/strains/show.js new file mode 100644 index 0000000..1055631 --- /dev/null +++ b/app/controllers/strains/show.js @@ -0,0 +1,19 @@ +import Ember from 'ember'; + +export default Ember.Controller.extend({ + isEditing: false, + actions: { + save: function() { + var strain = this.get('strain'); + if (strain.get('isDirty')) { + strain.save(); + } + this.toggleProperty('isEditing'); + }, + cancel: function() { + this.get('strain').get('errors').clear(); + this.get('strain').rollback(); + this.toggleProperty('isEditing'); + } + } +}); diff --git a/app/routes/strains/new.js b/app/routes/strains/new.js index 6524edc..5b2778e 100644 --- a/app/routes/strains/new.js +++ b/app/routes/strains/new.js @@ -7,9 +7,7 @@ export default Ember.Route.extend({ species: this.store.findAll('species') }); }, - actions: { - cancelStrain: function() { - this.transitionTo('strains.index'); - } - } + setupController: function(controller, models) { + controller.setProperties(models); + }, }); diff --git a/app/routes/strains/show.js b/app/routes/strains/show.js index 88ee2c8..9d6dccf 100644 --- a/app/routes/strains/show.js +++ b/app/routes/strains/show.js @@ -6,5 +6,8 @@ export default Ember.Route.extend({ strain: this.store.find('strain', params.strain_id), species: this.store.findAll('species') }); - } + }, + setupController: function(controller, models) { + controller.setProperties(models); + }, }); diff --git a/app/templates/components/species/species-details.hbs b/app/templates/components/species/species-details.hbs index aee7091..cd61c64 100644 --- a/app/templates/components/species/species-details.hbs +++ b/app/templates/components/species/species-details.hbs @@ -21,6 +21,7 @@ {{/link-to}} {{/each}} {{#if (can "edit species" species)}} +
{{#link-to 'strains.new' class="button-gray smaller"}} Add Strain {{/link-to}} diff --git a/app/templates/components/strains/strain-details.hbs b/app/templates/components/strains/strain-details.hbs index ccb8f17..bb9e2b8 100644 --- a/app/templates/components/strains/strain-details.hbs +++ b/app/templates/components/strains/strain-details.hbs @@ -120,11 +120,11 @@
{{! Does nothing ATM }} - + {{#if isEditing}}Cancel{{else}}Edit{{/if}} {{#if isEditing}} - + Save {{/if}} diff --git a/app/templates/strains/new.hbs b/app/templates/strains/new.hbs index 5af443b..6c0f31d 100644 --- a/app/templates/strains/new.hbs +++ b/app/templates/strains/new.hbs @@ -1,8 +1,8 @@ {{ strains/strain-details - strain=model.strain - species=model.species + strain=strain + species=species isEditing=true - isNew=true - action="cancelStrain" + save="save" + cancel="cancel" }} diff --git a/app/templates/strains/show.hbs b/app/templates/strains/show.hbs index 8827328..c3af8fb 100644 --- a/app/templates/strains/show.hbs +++ b/app/templates/strains/show.hbs @@ -1,4 +1,11 @@ -{{strains/strain-details strain=model.strain species=model.species}} +{{ + strains/strain-details + strain=strain + species=species + isEditing=isEditing + save="save" + cancel="cancel" +}}
{{outlet}}