Strain-details: controller -> component

This commit is contained in:
Matthew Dillon 2015-06-01 09:39:56 -08:00
parent 20765e5dac
commit c5b28f7204
6 changed files with 158 additions and 152 deletions

View file

@ -0,0 +1,15 @@
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ['grid-1'],
isEditing: false,
actions: {
editStrain: function() {
this.get('strain').get('errors').clear();
this.toggleProperty('isEditing');
},
saveStrain: function() {
this.get('strain').save().then(this.toggleProperty('isEditing'));
}
}
});

View file

@ -1,14 +0,0 @@
import Ember from 'ember';
export default Ember.Controller.extend({
isEditing: false,
actions: {
editStrain: function() {
this.get('model').get("errors").clear();
this.toggleProperty('isEditing');
},
saveStrain: function() {
this.get('model').save().then(this.toggleProperty('isEditing'));
}
}
});

View file

@ -0,0 +1,121 @@
<div class="span-1">
<fieldset {{bind-attr class=":flakes-information-box isEditing"}}>
<legend>
Strain
{{#if isEditing}}
{{input value=strain.strainName}}
{{else}}
{{strain.strainName}}
{{/if}}
{{display-errors a=strain.errors.strainName}}
</legend>
{{! ROW 1 }}
<div class="grid-4">
<dl class="span-2">
<dt>Species</dt>
<dd><em>{{strain.speciesName}}</em></dd>
</dl>
<dl class="span-2">
<dt>Type Strain?</dt>
<dd>
{{#if isEditing}}
{{input type="checkbox" checked=strain.typeStrain}}
{{/if}}
{{if strain.typeStrain 'Yes' 'No'}}
{{display-errors a=strain.errors.typeStrain}}
</dd>
</dl>
</div>
{{! ROW 2 }}
<div class="grid-4">
<dl class="span-2">
<dt>Accession Numbers</dt>
<dd>
{{#if isEditing}}
{{input value=strain.accessionNumbers}}
{{else}}
{{strain.accessionNumbers}}
{{/if}}
{{display-errors a=strain.errors.accessionNumbers}}
</dd>
</dl>
<dl class="span-2">
<dt>Genbank</dt>
<dd>
{{#if isEditing}}
{{input value=strain.genbank}}
{{else}}
{{strain.genbank}}
{{/if}}
{{display-errors a=strain.errors.genbank}}
</dd>
</dl>
</div>
{{! ROW 3 }}
<div class="grid-4">
<dl class="span-4">
<dt>Isolated From</dt>
<dd>
{{#if isEditing}}
{{textarea value=strain.isolatedFrom cols="70" rows="3"}}
{{else}}
{{strain.isolatedFrom}}
{{/if}}
{{display-errors a=strain.errors.isolatedFrom}}
</dd>
</dl>
</div>
{{! ROW 4 }}
<div class="grid-4">
<dl class="span-4">
<dt>Notes</dt>
<dd>
{{#if isEditing}}
{{textarea value=strain.notes cols="70" rows="3"}}
{{else}}
{{strain.notes}}
{{/if}}
{{display-errors a=strain.errors.notes}}
</dd>
</dl>
</div>
{{! ROW 5 }}
<div class="grid-4">
<dl class="span-1">
<dt>Record Created</dt>
<dd>{{null-time strain.createdAt 'LL'}}</dd>
</dl>
<dl class="span-1">
<dt>Record Updated</dt>
<dd>{{null-time strain.updatedAt 'LL'}}</dd>
</dl>
<dl class="span-1">
<dt>Record Deleted</dt>
<dd>{{null-time strain.deletedAt 'LL'}}</dd>
</dl>
<dl class="span-1"></dl>
</div>
{{! ROW 6 }}
{{#if (can "edit strain" strain)}}
<div class="grid-4">
<div class="span-1">
{{! Does nothing ATM }}
<a {{bind-attr class=":smaller isEditing:button-red:button-gray"}} {{action 'editStrain'}}>
{{#if isEditing}}Cancel{{else}}Edit{{/if}}
</a>
{{#if isEditing}}
<a class="button-green smaller" {{action 'saveStrain'}}>
Save
</a>
{{/if}}
</div>
</div>
{{/if}}
</fieldset>
</div>

View file

@ -1,126 +1,4 @@
<div class="grid-1">
<div class="span-1">
<fieldset {{bind-attr class=":flakes-information-box isEditing"}}>
<legend>
Strain
{{#if isEditing}}
{{input value=model.strainName}}
{{else}}
{{model.strainName}}
{{/if}}
{{display-errors a=model.errors.strainName}}
</legend>
{{! ROW 1 }}
<div class="grid-4">
<dl class="span-2">
<dt>Species</dt>
<dd><em>{{model.speciesName}}</em></dd>
</dl>
<dl class="span-2">
<dt>Type Strain?</dt>
<dd>
{{#if isEditing}}
{{input type="checkbox" checked=model.typeStrain}}
{{/if}}
{{if model.typeStrain 'Yes' 'No'}}
{{display-errors a=model.errors.typeStrain}}
</dd>
</dl>
</div>
{{! ROW 2 }}
<div class="grid-4">
<dl class="span-2">
<dt>Accession Numbers</dt>
<dd>
{{#if isEditing}}
{{input value=model.accessionNumbers}}
{{else}}
{{model.accessionNumbers}}
{{/if}}
{{display-errors a=model.errors.accessionNumbers}}
</dd>
</dl>
<dl class="span-2">
<dt>Genbank</dt>
<dd>
{{#if isEditing}}
{{input value=model.genbank}}
{{else}}
{{model.genbank}}
{{/if}}
{{display-errors a=model.errors.genbank}}
</dd>
</dl>
</div>
{{! ROW 3 }}
<div class="grid-4">
<dl class="span-4">
<dt>Isolated From</dt>
<dd>
{{#if isEditing}}
{{textarea value=model.isolatedFrom cols="70" rows="3"}}
{{else}}
{{model.isolatedFrom}}
{{/if}}
{{display-errors a=model.errors.isolatedFrom}}
</dd>
</dl>
</div>
{{! ROW 4 }}
<div class="grid-4">
<dl class="span-4">
<dt>Notes</dt>
<dd>
{{#if isEditing}}
{{textarea value=model.notes cols="70" rows="3"}}
{{else}}
{{model.notes}}
{{/if}}
{{display-errors a=model.errors.notes}}
</dd>
</dl>
</div>
{{! ROW 5 }}
<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>
{{! ROW 6 }}
{{#if (can "edit strain" model)}}
<div class="grid-4">
<div class="span-1">
{{! Does nothing ATM }}
<a {{bind-attr class=":smaller isEditing:button-red:button-gray"}} {{action 'editStrain'}}>
{{#if isEditing}}Cancel{{else}}Edit{{/if}}
</a>
{{#if isEditing}}
<a class="button-green smaller" {{action 'saveStrain'}}>
Save
</a>
{{/if}}
</div>
</div>
{{/if}}
</fieldset>
</div>
</div>
{{strains/strain-details strain=model}}
<div class="measurements-container">
{{outlet}}

View file

@ -0,0 +1,21 @@
import {
moduleForComponent,
test
} from 'ember-qunit';
moduleForComponent('strains/strain-details', {
// Specify the other units that are required for this test
// needs: ['component:foo', 'helper:bar']
});
test('it renders', function(assert) {
assert.expect(2);
// Creates the component instance
var component = this.subject();
assert.equal(component._state, 'preRender');
// Renders the component to the page
this.render();
assert.equal(component._state, 'inDOM');
});

View file

@ -1,15 +0,0 @@
import {
moduleFor,
test
} from 'ember-qunit';
moduleFor('controller:strains/show', {
// Specify the other units that are required for this test.
// needs: ['controller:foo']
});
// Replace this with your real tests.
test('it exists', function(assert) {
var controller = this.subject();
assert.ok(controller);
});