Species edit refactor
This commit is contained in:
parent
cdc825cc6a
commit
45223fd57f
16 changed files with 181 additions and 160 deletions
29
app/pods/species/edit/controller.js
Normal file
29
app/pods/species/edit/controller.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
import Ember from 'ember';
|
||||
|
||||
export default Ember.Controller.extend({
|
||||
actions: {
|
||||
save: function() {
|
||||
let species = this.get('model');
|
||||
|
||||
if (species.get('isDirty')) {
|
||||
species.save().then((species) => {
|
||||
this.transitionToRoute('species.show', species.get('id'));
|
||||
}, (err) => {
|
||||
this.get('flashMessages').error(err.responseJSON.error);
|
||||
});
|
||||
} else {
|
||||
this.transitionToRoute('species.show', species.get('id'));
|
||||
}
|
||||
},
|
||||
|
||||
cancel: function() {
|
||||
let species = this.get('model');
|
||||
|
||||
species.get('errors').clear();
|
||||
species.rollback();
|
||||
|
||||
this.transitionToRoute('species.show', species.get('id'));
|
||||
},
|
||||
|
||||
},
|
||||
});
|
4
app/pods/species/edit/route.js
Normal file
4
app/pods/species/edit/route.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
import Ember from 'ember';
|
||||
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
|
||||
|
||||
export default Ember.Route.extend(AuthenticatedRouteMixin, {});
|
6
app/pods/species/edit/template.hbs
Normal file
6
app/pods/species/edit/template.hbs
Normal file
|
@ -0,0 +1,6 @@
|
|||
{{
|
||||
forms/species-form
|
||||
species=model
|
||||
save="save"
|
||||
cancel="cancel"
|
||||
}}
|
|
@ -5,10 +5,11 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
|||
model: function() {
|
||||
return Ember.RSVP.hash({
|
||||
species: this.store.findAll('species'),
|
||||
strains: this.store.findAll('strain'),
|
||||
});
|
||||
},
|
||||
|
||||
setupController: function(controller, model) {
|
||||
controller.setProperties(model);
|
||||
setupController: function(controller, models) {
|
||||
controller.setProperties(models);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<h2>{{genus-name}} Species</h2>
|
||||
<h3>Total species: {{species.length}}</h3>
|
||||
<h3>Total species: {{model.length}}</h3>
|
||||
|
||||
{{add-button label="Add Species" link="species.new"}}
|
||||
|
||||
|
@ -11,17 +11,17 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#each sortedSpecies as |row|}}
|
||||
{{#each sortedSpecies as |species|}}
|
||||
<tr>
|
||||
<td>
|
||||
<em>
|
||||
{{#link-to 'species.show' row}}
|
||||
{{row.speciesName}}
|
||||
{{#link-to 'species.show' species}}
|
||||
{{species.speciesName}}
|
||||
{{/link-to}}
|
||||
</em>
|
||||
</td>
|
||||
<td>
|
||||
{{#each row.strains as |strain index|}}
|
||||
{{#each species.strains as |strain index|}}
|
||||
{{if index ","}}
|
||||
{{#link-to 'strains.show' strain.id}}
|
||||
{{{strain.strainNameMU}}}
|
||||
|
|
|
@ -1,21 +1,30 @@
|
|||
import Ember from 'ember';
|
||||
|
||||
export default Ember.Controller.extend({
|
||||
isEditing: true,
|
||||
actions: {
|
||||
save: function() {
|
||||
var species = this.get('model');
|
||||
let species = this.get('model');
|
||||
|
||||
if (species.get('isDirty')) {
|
||||
species.save();
|
||||
species.save().then((species) => {
|
||||
this.transitionToRoute('species.show', species.get('id'));
|
||||
}, (err) => {
|
||||
this.get('flashMessages').error(err.responseJSON.error);
|
||||
});
|
||||
} else {
|
||||
this.transitionToRoute('species.index');
|
||||
}
|
||||
this.transitionToRoute('species.index');
|
||||
},
|
||||
|
||||
cancel: function() {
|
||||
var species = this.get('model');
|
||||
let species = this.get('model');
|
||||
|
||||
if (species.get('isNew')) {
|
||||
species.deleteRecord();
|
||||
}
|
||||
|
||||
this.transitionToRoute('species.index');
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
},
|
||||
});
|
||||
|
|
|
@ -5,9 +5,5 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
|||
model: function() {
|
||||
return this.store.createRecord('species');
|
||||
},
|
||||
actions: {
|
||||
cancelSpecies: function() {
|
||||
this.transitionTo('species.index');
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
{{
|
||||
species-details
|
||||
forms/species-form
|
||||
species=model
|
||||
isEditing=true
|
||||
save="save"
|
||||
cancel="cancel"
|
||||
}}
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
import Ember from 'ember';
|
||||
|
||||
export default Ember.Controller.extend({
|
||||
isEditing: false,
|
||||
actions: {
|
||||
save: function() {
|
||||
var species = this.get('model');
|
||||
if (species.get('isDirty')) {
|
||||
species.save();
|
||||
}
|
||||
this.toggleProperty('isEditing');
|
||||
},
|
||||
cancel: function() {
|
||||
if (this.get('isEditing')) {
|
||||
var species = this.get('model');
|
||||
species.get('errors').clear();
|
||||
species.rollback();
|
||||
}
|
||||
this.toggleProperty('isEditing');
|
||||
}
|
||||
}
|
||||
});
|
|
@ -1,7 +1,57 @@
|
|||
{{
|
||||
species-details
|
||||
species=model
|
||||
isEditing=isEditing
|
||||
save="save"
|
||||
cancel="cancel"
|
||||
}}
|
||||
<div class="grid-1">
|
||||
<div class="span-1">
|
||||
<fieldset class="flakes-information-box {{if isEditing 'is-editing'}}">
|
||||
<legend>
|
||||
Species <em>{{model.speciesName}}</em>
|
||||
</legend>
|
||||
|
||||
{{! ROW 1 }}
|
||||
<div class="grid-4">
|
||||
<dl class="span-2">
|
||||
<dt>Strains</dt>
|
||||
<dd>
|
||||
{{#each model.strains as |strain index|}}
|
||||
{{if index ","}}
|
||||
{{#link-to 'strains.show' strain.id}}
|
||||
{{{strain.strainNameMU}}}
|
||||
{{/link-to}}
|
||||
{{/each}}
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="span-2">
|
||||
<dt>Type Species?</dt>
|
||||
<dd>
|
||||
{{if model.typeSpecies 'Yes' 'No'}}
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
{{! ROW 2 }}
|
||||
<div class="grid-4">
|
||||
<dl class="span-4">
|
||||
<dt>Etymology</dt>
|
||||
<dd>
|
||||
{{model.etymology}}
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
{{! ROW 3 }}
|
||||
<div class="grid-4">
|
||||
<dl class="span-1">
|
||||
<dt>Record Created</dt>
|
||||
<dd>{{null-time model.createdAt 'LL'}}</dd>
|
||||
</dl>
|
||||
<dl class="span-1">
|
||||
<dt>Record Updated</dt>
|
||||
<dd>{{null-time model.updatedAt 'LL'}}</dd>
|
||||
</dl>
|
||||
<dl class="span-1">
|
||||
<dt>Record Deleted</dt>
|
||||
<dd>{{null-time model.deletedAt 'LL'}}</dd>
|
||||
</dl>
|
||||
<dl class="span-1"></dl>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Reference in a new issue