Refactor strain form and edit strain

This commit is contained in:
Matthew Dillon 2015-11-10 12:57:12 -07:00
parent 04486880a0
commit 29c507af6b
5 changed files with 122 additions and 69 deletions

View file

@ -1,21 +1,89 @@
import Ember from 'ember';
import SetupMetaData from '../../../../mixins/setup-metadata';
const { Component } = Ember;
export default Component.extend(SetupMetaData, {
// Read-only attributes
strain: null,
isNew: null,
isDirty: false,
speciesList: null,
// Actions
"on-save": null,
"on-cancel": null,
"on-update": null,
// Property mapping
propertiesList: ['strainName', 'typeStrain', 'species', 'isolatedFrom', 'accessionNumbers', 'genbank', 'wholeGenomeSequence', 'notes'],
strainName: null,
typeStrain: null,
species: null,
isolatedFrom: null,
accessionNumbers: null,
genbank: null,
wholeGenomeSequence: null,
notes: null,
resetOnInit: Ember.on('init', function() {
this.get('propertiesList').forEach((field) => {
const valueInStrain = this.get('strain').get(field);
this.set(field, valueInStrain);
});
// Read-only attributes
this.set('isNew', this.get('strain.isNew'));
}),
updateField: function(property, value) {
this.set(property, value);
// Manually compare against passed in value
if (this.get('strain').get(property) !== value) {
this.set('isDirty', true);
} else {
this.set('isDirty', false);
}
},
export default Ember.Component.extend({
actions: {
save: function() {
this.sendAction('save');
return this.attrs['on-save'](this.getProperties(this.get('propertiesList')));
},
cancel: function() {
this.sendAction('cancel');
return this.attrs['on-cancel']();
},
strainNameDidChange: function(value) {
this.updateField('strainName', value);
},
typeStrainDidChange: function() {
this.updateField('typeStrain', !this.get('typeStrain'));
},
speciesDidChange: function(value) {
this.updateField('species', value);
},
isolatedFromDidChange: function(value) {
this.set('strain.isolatedFrom', value);
this.updateField('isolatedFrom', value);
},
accessionNumbersNameDidChange: function(value) {
this.updateField('accessionNumbers', value);
},
genbankDidChange: function(value) {
this.updateField('genbank', value);
},
wholeGenomeSequenceDidChange: function(value) {
this.updateField('wholeGenomeSequence', value);
},
notesDidChange: function(value) {
this.set('strain.notes', value);
this.updateField('strain.notes', value);
},
},
});

View file

@ -1,51 +1,51 @@
<form class="grid-form" {{action 'save' on='submit'}}>
<fieldset>
<legend><em>{{strain.strainName}}</em></legend>
<legend><em>{{strainName}}</em></legend>
<div data-row-span="2">
<div data-field-span="1">
<label>Strain Name</label>
{{input value=strain.strainName class="strain-name"}}
{{one-way-input type="text" class="strain-name" value=strainName update=(action "strainNameDidChange")}}
</div>
<div data-field-span="1">
<label>Type Strain?</label>
{{input type="checkbox" checked=strain.typeStrain}} {{if strain.typeStrain 'Yes' 'No'}}
<input type="checkbox" checked={{typeStrain}} value="{{typeStrain}}" onchange={{action "typeStrainDidChange"}}>
{{if typeStrain 'Yes' 'No'}}
</div>
</div>
<div data-row-span="2">
<div data-field-span="2">
<label>Species</label>
{{
select-2
content=species
optionLabelPath="speciesName"
value=strain.species
}}
<select onchange={{action "speciesDidChange" value="target.value"}}>
{{#each speciesList as |speciesChoice|}}
<option value={{speciesChoice}} selected={{equal species speciesChoice}}>{{speciesChoice.speciesName}}</option>
{{/each}}
</select>
</div>
</div>
<div data-row-span="2">
<div data-field-span="2">
<label>Isolated From</label>
{{text-editor value=strain.isolatedFrom update=(action "isolatedFromDidChange")}}
{{text-editor value=isolatedFrom update=(action "isolatedFromDidChange")}}
</div>
</div>
<div data-row-span="3">
<div data-field-span="1">
<label>Accession Numbers</label>
{{input value=strain.accessionNumbers}}
{{one-way-input type="text" class="accession-numbers" value=accessionNumbers update=(action "accessionNumbersNameDidChange")}}
</div>
<div data-field-span="1">
<label>GenBank</label>
{{input value=strain.genbank}}
{{one-way-input type="text" class="genbank" value=genbank update=(action "genbankDidChange")}}
</div>
<div data-field-span="1">
<label>Whole Genome Sequence</label>
{{input value=strain.wholeGenomeSequence}}
{{one-way-input type="text" class="whole-genome-sequenc" value=wholeGenomeSequence update=(action "wholeGenomeSequenceDidChange")}}
</div>
</div>
<div data-row-span="2">
<div data-field-span="2">
<label>Notes</label>
{{text-editor value=strain.notes update=(action "notesDidChange")}}
{{text-editor value=notes update=(action "notesDidChange")}}
</div>
</div>
</fieldset>
@ -61,7 +61,7 @@
<a class="button-red smaller" {{action 'cancel'}}>
Cancel
</a>
{{#if strain.hasDirtyAttributes}}
{{#if isDirty}}
<button type="submit" class="button-green smaller save-strain">
Save
</button>