Rough in detail view for characteristics

This commit is contained in:
Matthew Dillon 2015-09-04 10:47:32 -07:00
parent f59de829ee
commit ceccf6e536
9 changed files with 77 additions and 7 deletions

View file

@ -0,0 +1,6 @@
import Ember from 'ember';
export default Ember.Controller.extend({
sortParams: ['characteristicTypeName', 'sortOrder', 'characteristicName'],
sortedCharacteristics: Ember.computed.sort('model', 'sortParams'),
});

View file

@ -0,0 +1,28 @@
import Ember from 'ember';
export default Ember.Component.extend({
tagName: 'tr',
actions: {
edit: function() {
this.set('characteristicName', this.get('row.characteristicName'));
this.set('characteristicTypeName', this.get('row.characteristicTypeName'));
this.set('sortOrder', this.get('row.sortOrder'));
this.toggleProperty('isEditing');
},
save: function() {
if (this.get('characteristicName') !== this.get('row.characteristicName') ||
this.get('characteristicTypeName') !== this.get('row.characteristicTypeName') ||
this.get('sortOrder') !== this.get('row.sortOrder')) {
this.set('row.characteristicName', this.get('characteristicName'));
this.set('row.characteristicTypeName', this.get('characteristicTypeName'));
this.set('row.sortOrder', this.get('sortOrder'));
this.get('row').save();
}
this.toggleProperty('isEditing');
},
}
});

View file

@ -0,0 +1,15 @@
{{#if isEditing}}
<td>{{input value=characteristicName}}</td>
<td>{{input value=characteristicTypeName}}</td>
<td>{{input value=sortOrder}}</td>
<td {{action 'save'}}>Save</td>
{{else}}
<td>{{row.characteristicName}}</td>
<td>{{row.characteristicTypeName}}</td>
<td>{{row.sortOrder}}</td>
{{#if row.canEdit}}
<td {{action 'edit'}}>Edit</td>
{{else}}
<td></td>
{{/if}}
{{/if}}

View file

@ -0,0 +1,8 @@
import Ember from 'ember';
export default Ember.Route.extend({
model: function() {
return this.store.findAll('characteristic');
},
});

View file

@ -0,0 +1,25 @@
<h2>{{genus-name}} Characteristics</h2>
<h3>Total characteristics: {{model.length}}</h3>
<table class="flakes-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Sort Order</th>
</tr>
</thead>
<tbody>
{{#each sortedCharacteristics as |row|}}
<tr>
<td>
{{#link-to 'protected.characteristics.show' row}}
{{row.characteristicName}}
{{/link-to}}
</td>
<td>{{row.characteristicTypeName}}</td>
<td>{{row.sortOrder}}</td>
</tr>
{{/each}}
</tbody>
</table>