DDAU (WIP)

This commit is contained in:
Matthew Dillon 2015-11-10 21:21:59 -07:00
parent c1ff0d57b4
commit 1ee0e0e5ed
5 changed files with 46 additions and 17 deletions

View file

@ -16,7 +16,8 @@ export default Controller.extend(SaveModel, {
}); });
}, },
saveMeasurement: function(measurement) { saveMeasurement: function(measurement, properties) {
measurement.setProperties(properties);
measurement.save().then(() => { measurement.save().then(() => {
this.get('flashMessages').clearMessages(); this.get('flashMessages').clearMessages();
}, () => { }, () => {

View file

@ -4,31 +4,47 @@ const { Component, computed } = Ember;
export default Component.extend({ export default Component.extend({
tagName: 'tr', tagName: 'tr',
// Read-only attributes
isEditing: false, isEditing: false,
allCharacteristics: null, allCharacteristics: null,
measurement: null, measurement: null,
isDirty: null,
// Actions // Actions
"save-measurement": null, "save-measurement": null,
"delete-measurement": null, "delete-measurement": null,
oldCharacteristicId: function() { // Property mapping
const json = this.get('measurement').toJSON(); propertiesList: ['characteristic', 'value', 'notes'],
return json.characteristic; characteristic: null,
}.property(), value: null,
notes: null,
rowChanged: computed('measurement.notes', 'measurement.value', 'measurement.characteristic.id', function() { resetOnInit: Ember.on('init', function() {
return this.get('measurement.hasDirtyAttributes') || this.get('propertiesList').forEach((field) => {
this.get('oldCharacteristicId') !== this.get('measurement.characteristic.id'); const valueInMeasurement = this.get('measurement').get(field);
this.set(field, valueInMeasurement);
});
}), }),
updateField: function(property, value) {
this.set(property, value);
// Manually compare against passed in value
if (this.get('measurement').get(property) !== value) {
this.set('isDirty', true);
} else {
this.set('isDirty', false);
}
},
actions: { actions: {
edit: function() { edit: function() {
this.toggleProperty('isEditing'); this.toggleProperty('isEditing');
}, },
save: function() { save: function() {
this.attrs['save-measurement'](this.get('measurement')); this.attrs['save-measurement'](this.get('measurement'), this.getProperties(this.get('propertiesList')));
this.toggleProperty('isEditing'); this.toggleProperty('isEditing');
}, },
@ -36,5 +52,17 @@ export default Component.extend({
this.attrs['delete-measurement'](this.get('measurement')); this.attrs['delete-measurement'](this.get('measurement'));
}, },
characteristicDidChange: function(value) {
this.updateField('characteristic', value);
},
valueDidChange: function(value) {
this.updateField('value', value);
},
notesDidChange: function(value) {
this.updateField('notes', value);
},
}, },
}); });

View file

@ -5,19 +5,19 @@
select-2 select-2
multiple=false multiple=false
content=allCharacteristics content=allCharacteristics
value=measurement.characteristic value=characteristic
optionLabelPath="characteristicName" optionLabelPath="characteristicName"
}} }}
</td> </td>
<td> <td>
{{input value=measurement.value}} {{one-way-input type="text" class="measurement-value" value=value update=(action "valueDidChange")}}
</td> </td>
<td> <td>
{{input value=measurement.notes}} {{one-way-input type="text" class="measurement-notes" value=notes update=(action "notesDidChange")}}
</td> </td>
{{#if canEdit}} {{#if canEdit}}
<td> <td>
{{#if rowChanged}} {{#if isDirty}}
<button class="button-green smaller" {{action 'save'}}> <button class="button-green smaller" {{action 'save'}}>
Save Save
</button> </button>

View file

@ -43,8 +43,8 @@ export default Component.extend({
this.set('sortAsc', true); this.set('sortAsc', true);
}, },
saveMeasurement: function(measurement) { saveMeasurement: function(measurement, properties) {
return this.attrs['save-measurement'](measurement); return this.attrs['save-measurement'](measurement, properties);
}, },
deleteMeasurement: function(measurement) { deleteMeasurement: function(measurement) {

View file

@ -62,8 +62,8 @@ export default Component.extend(SetupMetaData, {
return this.attrs['add-characteristic'](); return this.attrs['add-characteristic']();
}, },
saveMeasurement: function(measurement) { saveMeasurement: function(measurement, properties) {
return this.attrs['save-measurement'](measurement); return this.attrs['save-measurement'](measurement, properties);
}, },
deleteMeasurement: function(measurement) { deleteMeasurement: function(measurement) {