UNPKG

ember-arcgis-page-layout

Version:

Page Layout infrastructure components

70 lines (62 loc) 1.95 kB
import Ember from 'ember'; import layout from './template'; export default Ember.Component.extend({ layout, init () { this._super.apply(this, arguments); // get the default colors from the model's original state // TODO: better to default text color to inherit, but colorpicker won't allow this.set('defaultColor', this.get('model.style.color') || '#000000'); this.set('defaultBgColor', this.get('model.style.background.color') || 'transparent'); }, didInsertElement () { // get references to the colorpicker text inputs this.$colorInput = this.$('input[name=sectionTextColor]'); this.$bgColorInput = this.$('input[name=sectionBgColor]'); // init tooltips this.$('[data-toggle="tooltip"]').tooltip(); }, color: Ember.computed('model.style.color', { get () { return this.get('model.style.color'); }, set (key, value) { return this._setColorValue(key, value); } }), bgColor: Ember.computed('model.style.background.color', { get () { return this.get('model.style.background.color'); }, set (key, value) { return this._setColorValue(key, value); } }), _setColorValue (key, value) { let $colorInput, defaultColor, modelProp; if (key === 'bgColor') { $colorInput = this.$bgColorInput; defaultColor = this.get('defaultBgColor'); modelProp = 'model.style.background.color'; } else { $colorInput = this.$colorInput; defaultColor = this.get('defaultColor'); modelProp = 'model.style.color'; } // if user has cleared out input, then set to default if ($colorInput.val() === '') { $colorInput.val(defaultColor); value = defaultColor; } // update the model this.set(modelProp, value); // flag the model as dirty this.send('modelChanged'); return value; }, actions: { modelChanged () { this.sendAction('onModelChanged'); } } });