Pulling stuff back out of strain component
This commit is contained in:
parent
7260b95937
commit
033ff530d2
9 changed files with 67 additions and 24 deletions
|
@ -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'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
21
app/controllers/strains/new.js
Normal file
21
app/controllers/strains/new.js
Normal file
|
@ -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');
|
||||
}
|
||||
}
|
||||
});
|
19
app/controllers/strains/show.js
Normal file
19
app/controllers/strains/show.js
Normal file
|
@ -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');
|
||||
}
|
||||
}
|
||||
});
|
|
@ -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);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
{{/link-to}}
|
||||
{{/each}}
|
||||
{{#if (can "edit species" species)}}
|
||||
<br>
|
||||
{{#link-to 'strains.new' class="button-gray smaller"}}
|
||||
Add Strain
|
||||
{{/link-to}}
|
||||
|
|
|
@ -120,11 +120,11 @@
|
|||
<div class="grid-4">
|
||||
<div class="span-1">
|
||||
{{! Does nothing ATM }}
|
||||
<a {{bind-attr class=":smaller isEditing:button-red:button-gray"}} {{action 'editStrain'}}>
|
||||
<a {{bind-attr class=":smaller isEditing:button-red:button-gray"}} {{action 'cancel'}}>
|
||||
{{#if isEditing}}Cancel{{else}}Edit{{/if}}
|
||||
</a>
|
||||
{{#if isEditing}}
|
||||
<a class="button-green smaller" {{action 'saveStrain'}}>
|
||||
<a class="button-green smaller" {{action 'save'}}>
|
||||
Save
|
||||
</a>
|
||||
{{/if}}
|
||||
|
|
|
@ -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"
|
||||
}}
|
||||
|
|
|
@ -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"
|
||||
}}
|
||||
|
||||
<div class="measurements-container">
|
||||
{{outlet}}
|
||||
|
|
Reference in a new issue