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({
|
export default Ember.Component.extend({
|
||||||
classNames: ['grid-1'],
|
classNames: ['grid-1'],
|
||||||
isEditing: false,
|
isEditing: false,
|
||||||
isNew: false,
|
|
||||||
actions: {
|
actions: {
|
||||||
editStrain: function() {
|
save: function() {
|
||||||
this.get('strain').get('errors').clear();
|
this.sendAction('save');
|
||||||
if (this.get('isNew')) {
|
},
|
||||||
this.get('strain').destroyRecord().then(this.sendAction());
|
cancel: function() {
|
||||||
}
|
this.sendAction('cancel');
|
||||||
this.toggleProperty('isEditing');
|
|
||||||
this.get('strain').rollback();
|
|
||||||
},
|
},
|
||||||
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')
|
species: this.store.findAll('species')
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
actions: {
|
setupController: function(controller, models) {
|
||||||
cancelStrain: function() {
|
controller.setProperties(models);
|
||||||
this.transitionTo('strains.index');
|
},
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,5 +6,8 @@ export default Ember.Route.extend({
|
||||||
strain: this.store.find('strain', params.strain_id),
|
strain: this.store.find('strain', params.strain_id),
|
||||||
species: this.store.findAll('species')
|
species: this.store.findAll('species')
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
|
setupController: function(controller, models) {
|
||||||
|
controller.setProperties(models);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
{{/link-to}}
|
{{/link-to}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
{{#if (can "edit species" species)}}
|
{{#if (can "edit species" species)}}
|
||||||
|
<br>
|
||||||
{{#link-to 'strains.new' class="button-gray smaller"}}
|
{{#link-to 'strains.new' class="button-gray smaller"}}
|
||||||
Add Strain
|
Add Strain
|
||||||
{{/link-to}}
|
{{/link-to}}
|
||||||
|
|
|
@ -120,11 +120,11 @@
|
||||||
<div class="grid-4">
|
<div class="grid-4">
|
||||||
<div class="span-1">
|
<div class="span-1">
|
||||||
{{! Does nothing ATM }}
|
{{! 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}}
|
{{#if isEditing}}Cancel{{else}}Edit{{/if}}
|
||||||
</a>
|
</a>
|
||||||
{{#if isEditing}}
|
{{#if isEditing}}
|
||||||
<a class="button-green smaller" {{action 'saveStrain'}}>
|
<a class="button-green smaller" {{action 'save'}}>
|
||||||
Save
|
Save
|
||||||
</a>
|
</a>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
{{
|
{{
|
||||||
strains/strain-details
|
strains/strain-details
|
||||||
strain=model.strain
|
strain=strain
|
||||||
species=model.species
|
species=species
|
||||||
isEditing=true
|
isEditing=true
|
||||||
isNew=true
|
save="save"
|
||||||
action="cancelStrain"
|
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">
|
<div class="measurements-container">
|
||||||
{{outlet}}
|
{{outlet}}
|
||||||
|
|
Reference in a new issue