Step one, move up to pod root
This commit is contained in:
parent
fa5b741e35
commit
48cd1f4f39
8 changed files with 3 additions and 4 deletions
|
@ -0,0 +1,49 @@
|
|||
import Ember from 'ember';
|
||||
import ajaxError from '../../../../../utils/ajax-error';
|
||||
|
||||
const { Component } = Ember;
|
||||
|
||||
export default Component.extend({
|
||||
tagName: 'tr',
|
||||
isEditing: false,
|
||||
|
||||
oldCharacteristicId: function() {
|
||||
let json = this.get('row').toJSON();
|
||||
return json.characteristic;
|
||||
}.property(),
|
||||
|
||||
rowChanged: Ember.computed('row.notes', 'row.value', 'row.characteristic.id', function() {
|
||||
return this.get('row.hasDirtyAttributes') ||
|
||||
this.get('oldCharacteristicId') !== this.get('row.characteristic.id');
|
||||
}),
|
||||
|
||||
actions: {
|
||||
edit: function() {
|
||||
// The parent table fetches all of the characteristics ahead of time
|
||||
this.set('characteristics', this.store.peekAll('characteristic'));
|
||||
this.toggleProperty('isEditing');
|
||||
},
|
||||
|
||||
save: function() {
|
||||
if (this.get('rowChanged')) {
|
||||
this.get('row').save().then(() => {
|
||||
this.get('flashMessages').clearMessages();
|
||||
this.toggleProperty('isEditing');
|
||||
}, () => {
|
||||
ajaxError(this.get('row.errors'), this.get('flashMessages'));
|
||||
});
|
||||
} else {
|
||||
this.toggleProperty('isEditing');
|
||||
}
|
||||
},
|
||||
|
||||
delete: function() {
|
||||
let char = this.get('row.characteristic');
|
||||
if (char.get('isNew')) {
|
||||
char.destroyRecord();
|
||||
}
|
||||
this.get('row').destroyRecord();
|
||||
}
|
||||
|
||||
},
|
||||
});
|
|
@ -0,0 +1,54 @@
|
|||
{{#if isEditing}}
|
||||
<td></td>
|
||||
<td>
|
||||
{{
|
||||
select-2
|
||||
multiple=false
|
||||
content=characteristics
|
||||
value=row.characteristic
|
||||
optionLabelPath="characteristicName"
|
||||
}}
|
||||
</td>
|
||||
<td>
|
||||
{{input value=row.value}}
|
||||
</td>
|
||||
<td>
|
||||
{{input value=row.notes}}
|
||||
</td>
|
||||
{{#if canEdit}}
|
||||
<td>
|
||||
{{#if rowChanged}}
|
||||
<button class="button-green smaller" {{action 'save'}}>
|
||||
Save
|
||||
</button>
|
||||
{{else}}
|
||||
<button class="button-gray smaller" {{action 'save'}}>
|
||||
Cancel
|
||||
</button>
|
||||
{{/if}}
|
||||
</td>
|
||||
{{/if}}
|
||||
{{else}}
|
||||
<td>
|
||||
{{{row.characteristic.characteristicTypeName}}}
|
||||
</td>
|
||||
<td>
|
||||
{{#link-to 'protected.characteristics.show' row.characteristic.id}}
|
||||
{{{row.characteristic.characteristicName}}}
|
||||
{{/link-to}}
|
||||
</td>
|
||||
<td>
|
||||
{{row.value}}
|
||||
</td>
|
||||
<td>
|
||||
{{row.notes}}
|
||||
</td>
|
||||
{{#if canEdit}}
|
||||
<td>
|
||||
<button class="button-gray smaller" {{action 'edit'}}>
|
||||
Edit
|
||||
</button>
|
||||
{{delete-button delete=(action 'delete')}}
|
||||
</td>
|
||||
{{/if}}
|
||||
{{/if}}
|
Reference in a new issue