diff --git a/app/controllers/strains/show.js b/app/controllers/strains/show.js new file mode 100644 index 0000000..125549e --- /dev/null +++ b/app/controllers/strains/show.js @@ -0,0 +1,14 @@ +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')); + } + } +}); diff --git a/app/styles/app.css b/app/styles/app.css index 1bd92ff..9d1b1df 100644 --- a/app/styles/app.css +++ b/app/styles/app.css @@ -6,6 +6,10 @@ cursor: pointer; } +.is-editing { + background-color: #FFFCE2; +} + /* BEGIN https://github.com/tobiasahlin/SpinKit */ .spinner { width: 40px; diff --git a/app/templates/strains/show.hbs b/app/templates/strains/show.hbs index c33b795..cc0393a 100644 --- a/app/templates/strains/show.hbs +++ b/app/templates/strains/show.hbs @@ -1,7 +1,16 @@
-
- Strain {{model.strainName}} +
+ + Strain + {{#if isEditing}} + {{input value=model.strainName}} + {{else}} + {{model.strainName}} + {{/if}} + {{display-errors a=model.errors.strainName}} + + {{! ROW 1 }}
@@ -10,34 +19,72 @@
Type Strain?
-
{{if model.typeStrain 'Yes' 'No'}}
+
+ {{#if isEditing}} + {{input type="checkbox" checked=model.typeStrain}} + {{/if}} + {{if model.typeStrain 'Yes' 'No'}} + {{display-errors a=model.errors.typeStrain}} +
+ {{! ROW 2 }}
Accession Numbers
-
{{model.accessionNumbers}}
+
+ {{#if isEditing}} + {{input value=model.accessionNumbers}} + {{else}} + {{model.accessionNumbers}} + {{/if}} + {{display-errors a=model.errors.accessionNumbers}} +
Genbank
-
{{model.genbank}}
+
+ {{#if isEditing}} + {{input value=model.genbank}} + {{else}} + {{model.genbank}} + {{/if}} + {{display-errors a=model.errors.genbank}} +
+ {{! ROW 3 }}
Isolated From
-
{{model.isolatedFrom}}
+
+ {{#if isEditing}} + {{textarea value=model.isolatedFrom cols="70" rows="3"}} + {{else}} + {{model.isolatedFrom}} + {{/if}} + {{display-errors a=model.errors.isolatedFrom}} +
+ {{! ROW 4 }}
Notes
-
{{model.notes}}
+
+ {{#if isEditing}} + {{textarea value=model.notes cols="70" rows="3"}} + {{else}} + {{model.notes}} + {{/if}} + {{display-errors a=model.errors.notes}} +
+ {{! ROW 5 }}
@@ -54,12 +101,20 @@
+ + {{! ROW 6 }} {{#if (can "edit strain" model)}} - {{! ROW 6 }}
{{! Does nothing ATM }} - Edit Strain + + {{#if isEditing}}Cancel{{else}}Edit{{/if}} + + {{#if isEditing}} + + Save + + {{/if}}
{{/if}} diff --git a/server/mocks/strains.js b/server/mocks/strains.js index e4fbe4c..f5e5e6c 100644 --- a/server/mocks/strains.js +++ b/server/mocks/strains.js @@ -100,9 +100,17 @@ module.exports = function(app) { var strains = STRAINS.filter(function(s) { return s.id == req.params.id; }); - res.send({ - 'strain': strains[0] - }); + if (strains.length === 0) { + res.status(422).send({ + 'errors':{ + "strainName": ["error1"], + "typeStrain": ["error2", "error3"], + "isolatedFrom": ["error4"] + } + }).end(); + } else { + res.status(204).end(); + } }); strainsRouter.delete('/:id', function(req, res) {