DDAU (WIP)
This commit is contained in:
		
							parent
							
								
									c1ff0d57b4
								
							
						
					
					
						commit
						1ee0e0e5ed
					
				
					 5 changed files with 46 additions and 17 deletions
				
			
		|  | @ -16,7 +16,8 @@ export default Controller.extend(SaveModel, { | |||
|       }); | ||||
|     }, | ||||
| 
 | ||||
|     saveMeasurement: function(measurement) { | ||||
|     saveMeasurement: function(measurement, properties) { | ||||
|       measurement.setProperties(properties); | ||||
|       measurement.save().then(() => { | ||||
|         this.get('flashMessages').clearMessages(); | ||||
|       }, () => { | ||||
|  |  | |||
|  | @ -4,31 +4,47 @@ const { Component, computed } = Ember; | |||
| 
 | ||||
| export default Component.extend({ | ||||
|   tagName: 'tr', | ||||
| 
 | ||||
|   // Read-only attributes
 | ||||
|   isEditing: false, | ||||
|   allCharacteristics: null, | ||||
|   measurement: null, | ||||
|   isDirty: null, | ||||
| 
 | ||||
|   // Actions
 | ||||
|   "save-measurement": null, | ||||
|   "delete-measurement": null, | ||||
| 
 | ||||
|   oldCharacteristicId: function() { | ||||
|     const json = this.get('measurement').toJSON(); | ||||
|     return json.characteristic; | ||||
|   }.property(), | ||||
|   // Property mapping
 | ||||
|   propertiesList: ['characteristic', 'value', 'notes'], | ||||
|   characteristic: null, | ||||
|   value: null, | ||||
|   notes: null, | ||||
| 
 | ||||
|   rowChanged: computed('measurement.notes', 'measurement.value', 'measurement.characteristic.id', function() { | ||||
|     return this.get('measurement.hasDirtyAttributes') || | ||||
|       this.get('oldCharacteristicId') !== this.get('measurement.characteristic.id'); | ||||
|   resetOnInit: Ember.on('init', function() { | ||||
|     this.get('propertiesList').forEach((field) => { | ||||
|       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: { | ||||
|     edit: function() { | ||||
|       this.toggleProperty('isEditing'); | ||||
|     }, | ||||
| 
 | ||||
|     save: function() { | ||||
|       this.attrs['save-measurement'](this.get('measurement')); | ||||
|       this.attrs['save-measurement'](this.get('measurement'), this.getProperties(this.get('propertiesList'))); | ||||
|       this.toggleProperty('isEditing'); | ||||
|     }, | ||||
| 
 | ||||
|  | @ -36,5 +52,17 @@ export default Component.extend({ | |||
|       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); | ||||
|     }, | ||||
| 
 | ||||
|   }, | ||||
| }); | ||||
|  |  | |||
|  | @ -5,19 +5,19 @@ | |||
|       select-2 | ||||
|       multiple=false | ||||
|       content=allCharacteristics | ||||
|       value=measurement.characteristic | ||||
|       value=characteristic | ||||
|       optionLabelPath="characteristicName" | ||||
|     }} | ||||
|   </td> | ||||
|   <td> | ||||
|     {{input value=measurement.value}} | ||||
|     {{one-way-input type="text" class="measurement-value" value=value update=(action "valueDidChange")}} | ||||
|   </td> | ||||
|   <td> | ||||
|     {{input value=measurement.notes}} | ||||
|     {{one-way-input type="text" class="measurement-notes" value=notes update=(action "notesDidChange")}} | ||||
|   </td> | ||||
|   {{#if canEdit}} | ||||
|     <td> | ||||
|       {{#if rowChanged}} | ||||
|       {{#if isDirty}} | ||||
|       <button class="button-green smaller" {{action 'save'}}> | ||||
|         Save | ||||
|       </button> | ||||
|  |  | |||
|  | @ -43,8 +43,8 @@ export default Component.extend({ | |||
|       this.set('sortAsc', true); | ||||
|     }, | ||||
| 
 | ||||
|     saveMeasurement: function(measurement) { | ||||
|       return this.attrs['save-measurement'](measurement); | ||||
|     saveMeasurement: function(measurement, properties) { | ||||
|       return this.attrs['save-measurement'](measurement, properties); | ||||
|     }, | ||||
| 
 | ||||
|     deleteMeasurement: function(measurement) { | ||||
|  |  | |||
|  | @ -62,8 +62,8 @@ export default Component.extend(SetupMetaData, { | |||
|       return this.attrs['add-characteristic'](); | ||||
|     }, | ||||
| 
 | ||||
|     saveMeasurement: function(measurement) { | ||||
|       return this.attrs['save-measurement'](measurement); | ||||
|     saveMeasurement: function(measurement, properties) { | ||||
|       return this.attrs['save-measurement'](measurement, properties); | ||||
|     }, | ||||
| 
 | ||||
|     deleteMeasurement: function(measurement) { | ||||
|  |  | |||
		Reference in a new issue
	
	 Matthew Dillon
						Matthew Dillon