Create and edit characteristics
This commit is contained in:
parent
fb296340c3
commit
de8ac653f6
14 changed files with 180 additions and 1 deletions
|
@ -0,0 +1,13 @@
|
|||
import Ember from 'ember';
|
||||
|
||||
export default Ember.Component.extend({
|
||||
actions: {
|
||||
save: function() {
|
||||
this.sendAction('save');
|
||||
},
|
||||
|
||||
cancel: function() {
|
||||
this.sendAction('cancel');
|
||||
},
|
||||
}
|
||||
});
|
|
@ -0,0 +1,30 @@
|
|||
<form class="grid-form" {{action 'save' on='submit'}}>
|
||||
<fieldset>
|
||||
<legend><em>{{characteristic.characteristicName}}</em></legend>
|
||||
<div data-row-span="1">
|
||||
<div data-field-span="1">
|
||||
<label>Characteristic Name</label>
|
||||
{{input value=characteristic.characteristicName}}
|
||||
</div>
|
||||
</div>
|
||||
<div data-row-span="2">
|
||||
<div data-field-span="1">
|
||||
<label>Characteristic Type</label>
|
||||
{{input value=characteristic.characteristicTypeName}}
|
||||
</div>
|
||||
<div data-field-span="1">
|
||||
<label>Sort Order</label>
|
||||
{{input value=characteristic.sortOrder}}
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
<br>
|
||||
<a class="button-red smaller" {{action 'cancel'}}>
|
||||
Cancel
|
||||
</a>
|
||||
{{#if characteristic.hasDirtyAttributes}}
|
||||
<button type="submit" class="button-green smaller">
|
||||
Save
|
||||
</button>
|
||||
{{/if}}
|
||||
</form>
|
30
app/pods/protected/characteristics/edit/controller.js
Normal file
30
app/pods/protected/characteristics/edit/controller.js
Normal file
|
@ -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);
|
||||
},
|
||||
|
||||
},
|
||||
});
|
15
app/pods/protected/characteristics/edit/route.js
Normal file
15
app/pods/protected/characteristics/edit/route.js
Normal file
|
@ -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'));
|
||||
}
|
||||
},
|
||||
|
||||
});
|
6
app/pods/protected/characteristics/edit/template.hbs
Normal file
6
app/pods/protected/characteristics/edit/template.hbs
Normal file
|
@ -0,0 +1,6 @@
|
|||
{{
|
||||
protected/characteristics/characteristic-form
|
||||
characteristic=model
|
||||
save="save"
|
||||
cancel="cancel"
|
||||
}}
|
|
@ -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'));
|
||||
},
|
||||
|
||||
});
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<h2>{{genus-name}} Characteristics</h2>
|
||||
<h3>Total characteristics: {{model.length}}</h3>
|
||||
|
||||
{{add-button label="Add Characteristic" link="protected.characteristics.new" canAdd=metaData.canAdd}}
|
||||
|
||||
<table class="flakes-table">
|
||||
<thead>
|
||||
<tr>
|
||||
|
|
24
app/pods/protected/characteristics/new/controller.js
Normal file
24
app/pods/protected/characteristics/new/controller.js
Normal file
|
@ -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');
|
||||
},
|
||||
|
||||
},
|
||||
});
|
26
app/pods/protected/characteristics/new/route.js
Normal file
26
app/pods/protected/characteristics/new/route.js
Normal file
|
@ -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();
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
});
|
6
app/pods/protected/characteristics/new/template.hbs
Normal file
6
app/pods/protected/characteristics/new/template.hbs
Normal file
|
@ -0,0 +1,6 @@
|
|||
{{
|
||||
protected/characteristics/characteristic-form
|
||||
characteristic=model
|
||||
save="save"
|
||||
cancel="cancel"
|
||||
}}
|
|
@ -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 = [];
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
{{#if measurementsPresent}}
|
||||
<table class="flakes-table">
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -24,3 +25,6 @@
|
|||
{{/each}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{else}}
|
||||
No measurements on record.
|
||||
{{/if}}
|
||||
|
|
|
@ -7,12 +7,18 @@
|
|||
|
||||
{{! ROW 1 }}
|
||||
<div class="grid-2 gutter-20">
|
||||
<dl class="span-2">
|
||||
<dl class="span-1">
|
||||
<dt>Characteristic Type</dt>
|
||||
<dd>
|
||||
{{model.characteristicTypeName}}
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="span-1">
|
||||
<dt>Sort Order</dt>
|
||||
<dd>
|
||||
{{model.sortOrder}}
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
{{! ROW 2 }}
|
||||
|
@ -43,3 +49,9 @@
|
|||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
{{#if model.canEdit}}
|
||||
<br>
|
||||
{{#link-to 'protected.characteristics.edit' model.id class="button-gray smaller"}}
|
||||
Edit
|
||||
{{/link-to}}
|
||||
{{/if}}
|
||||
|
|
|
@ -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() {
|
||||
|
|
Reference in a new issue