diff --git a/app/pods/protected/characteristics/characteristic-form/component.js b/app/pods/protected/characteristics/characteristic-form/component.js
new file mode 100644
index 0000000..a53a469
--- /dev/null
+++ b/app/pods/protected/characteristics/characteristic-form/component.js
@@ -0,0 +1,13 @@
+import Ember from 'ember';
+
+export default Ember.Component.extend({
+ actions: {
+ save: function() {
+ this.sendAction('save');
+ },
+
+ cancel: function() {
+ this.sendAction('cancel');
+ },
+ }
+});
diff --git a/app/pods/protected/characteristics/characteristic-form/template.hbs b/app/pods/protected/characteristics/characteristic-form/template.hbs
new file mode 100644
index 0000000..b1d68c0
--- /dev/null
+++ b/app/pods/protected/characteristics/characteristic-form/template.hbs
@@ -0,0 +1,30 @@
+
diff --git a/app/pods/protected/characteristics/edit/controller.js b/app/pods/protected/characteristics/edit/controller.js
new file mode 100644
index 0000000..d0f2ec0
--- /dev/null
+++ b/app/pods/protected/characteristics/edit/controller.js
@@ -0,0 +1,30 @@
+import Ember from 'ember';
+
+export default Ember.Controller.extend({
+ actions: {
+ save: function() {
+ let characteristic = this.get('model');
+
+ if (characteristic.get('hasDirtyAttributes')) {
+ characteristic.save().then((characteristic) => {
+ this.transitionToRoute('protected.characteristics.show', characteristic);
+ }, (err) => {
+ this.get('flashMessages').error(err.responseJSON.error);
+ });
+ } else {
+ characteristic.deleteRecord();
+ this.transitionToRoute('protected.characteristics.show', characteristic);
+ }
+ },
+
+ cancel: function() {
+ let characteristic = this.get('model');
+
+ characteristic.get('errors').clear();
+ characteristic.rollbackAttributes();
+
+ this.transitionToRoute('protected.characteristics.show', characteristic);
+ },
+
+ },
+});
diff --git a/app/pods/protected/characteristics/edit/route.js b/app/pods/protected/characteristics/edit/route.js
new file mode 100644
index 0000000..3ab3562
--- /dev/null
+++ b/app/pods/protected/characteristics/edit/route.js
@@ -0,0 +1,15 @@
+import Ember from 'ember';
+import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
+
+export default Ember.Route.extend(AuthenticatedRouteMixin, {
+ model: function(params) {
+ return this.store.findRecord('characteristic', params.characteristic_id, { reload: true });
+ },
+
+ afterModel: function(model) {
+ if (!model.get('canEdit')) {
+ this.transitionTo('characteristics.show', model.get('id'));
+ }
+ },
+
+});
diff --git a/app/pods/protected/characteristics/edit/template.hbs b/app/pods/protected/characteristics/edit/template.hbs
new file mode 100644
index 0000000..3f1fe65
--- /dev/null
+++ b/app/pods/protected/characteristics/edit/template.hbs
@@ -0,0 +1,6 @@
+{{
+ protected/characteristics/characteristic-form
+ characteristic=model
+ save="save"
+ cancel="cancel"
+}}
diff --git a/app/pods/protected/characteristics/index/route.js b/app/pods/protected/characteristics/index/route.js
index cf8c61a..83aa3ef 100644
--- a/app/pods/protected/characteristics/index/route.js
+++ b/app/pods/protected/characteristics/index/route.js
@@ -5,4 +5,9 @@ export default Ember.Route.extend({
return this.store.findAll('characteristic');
},
+ setupController: function(controller, model) {
+ controller.set('model', model);
+ controller.set('metaData', this.store.metadataFor('characteristic'));
+ },
+
});
diff --git a/app/pods/protected/characteristics/index/template.hbs b/app/pods/protected/characteristics/index/template.hbs
index 76efee6..3430386 100644
--- a/app/pods/protected/characteristics/index/template.hbs
+++ b/app/pods/protected/characteristics/index/template.hbs
@@ -1,6 +1,8 @@
{{genus-name}} Characteristics
Total characteristics: {{model.length}}
+{{add-button label="Add Characteristic" link="protected.characteristics.new" canAdd=metaData.canAdd}}
+
diff --git a/app/pods/protected/characteristics/new/controller.js b/app/pods/protected/characteristics/new/controller.js
new file mode 100644
index 0000000..c211ec8
--- /dev/null
+++ b/app/pods/protected/characteristics/new/controller.js
@@ -0,0 +1,24 @@
+import Ember from 'ember';
+
+export default Ember.Controller.extend({
+ actions: {
+ save: function() {
+ let characteristic = this.get('model');
+
+ if (characteristic.get('hasDirtyAttributes')) {
+ characteristic.save().then((characteristic) => {
+ this.transitionToRoute('protected.characteristics.show', characteristic);
+ }, (err) => {
+ this.get('flashMessages').error(err.responseJSON.error);
+ });
+ } else {
+ this.transitionToRoute('protected.characteristics.index');
+ }
+ },
+
+ cancel: function() {
+ this.transitionToRoute('protected.characteristics.index');
+ },
+
+ },
+});
diff --git a/app/pods/protected/characteristics/new/route.js b/app/pods/protected/characteristics/new/route.js
new file mode 100644
index 0000000..6ddb337
--- /dev/null
+++ b/app/pods/protected/characteristics/new/route.js
@@ -0,0 +1,26 @@
+import Ember from 'ember';
+
+export default Ember.Route.extend({
+ beforeModel: function(transition) {
+ this._super(transition);
+ if (this.get('session.currentUser.role') === 'R') {
+ this.transitionTo('characteristics.index');
+ }
+ },
+
+ model: function() {
+ return this.store.createRecord('characteristic');
+ },
+
+ actions: {
+ willTransition: function(/*transition*/) {
+ let controller = this.get('controller');
+ let characteristic = controller.get('model');
+
+ if (characteristic.get('isNew')) {
+ characteristic.deleteRecord();
+ }
+ },
+ },
+
+});
diff --git a/app/pods/protected/characteristics/new/template.hbs b/app/pods/protected/characteristics/new/template.hbs
new file mode 100644
index 0000000..3f1fe65
--- /dev/null
+++ b/app/pods/protected/characteristics/new/template.hbs
@@ -0,0 +1,6 @@
+{{
+ protected/characteristics/characteristic-form
+ characteristic=model
+ save="save"
+ cancel="cancel"
+}}
diff --git a/app/pods/protected/characteristics/show/measurements-table/component.js b/app/pods/protected/characteristics/show/measurements-table/component.js
index 03ff60b..63d3165 100644
--- a/app/pods/protected/characteristics/show/measurements-table/component.js
+++ b/app/pods/protected/characteristics/show/measurements-table/component.js
@@ -1,6 +1,10 @@
import Ember from 'ember';
export default Ember.Component.extend({
+ measurementsPresent: function() {
+ return this.get('model.measurements.length') > 0;
+ }.property('model.measurements'),
+
measurementsTable: function() {
let measurements = this.get('model.measurements');
let table = [];
diff --git a/app/pods/protected/characteristics/show/measurements-table/template.hbs b/app/pods/protected/characteristics/show/measurements-table/template.hbs
index 2e838ec..1813ed8 100644
--- a/app/pods/protected/characteristics/show/measurements-table/template.hbs
+++ b/app/pods/protected/characteristics/show/measurements-table/template.hbs
@@ -1,3 +1,4 @@
+{{#if measurementsPresent}}
@@ -24,3 +25,6 @@
{{/each}}
+{{else}}
+No measurements on record.
+{{/if}}
diff --git a/app/pods/protected/characteristics/show/template.hbs b/app/pods/protected/characteristics/show/template.hbs
index 1097ace..ccdb9f4 100644
--- a/app/pods/protected/characteristics/show/template.hbs
+++ b/app/pods/protected/characteristics/show/template.hbs
@@ -7,12 +7,18 @@
{{! ROW 1 }}
-
+
- Characteristic Type
-
{{model.characteristicTypeName}}
+
+ - Sort Order
+ -
+ {{model.sortOrder}}
+
+
{{! ROW 2 }}
@@ -43,3 +49,9 @@
+{{#if model.canEdit}}
+
+ {{#link-to 'protected.characteristics.edit' model.id class="button-gray smaller"}}
+ Edit
+ {{/link-to}}
+{{/if}}
diff --git a/app/router.js b/app/router.js
index 42a594b..7398db7 100644
--- a/app/router.js
+++ b/app/router.js
@@ -24,7 +24,9 @@ Router.map(function() {
});
this.route('characteristics', function() {
+ this.route('new');
this.route('show', { path: ':characteristic_id' });
+ this.route('edit', { path: ':characteristic_id/edit' });
});
this.route('species', function() {