github.com/DerekStrickland/consul@v1.4.5/ui-v2/app/controllers/dc/kv/edit.js (about) 1 import Controller from '@ember/controller'; 2 import { get, set } from '@ember/object'; 3 import { inject as service } from '@ember/service'; 4 5 import Changeset from 'ember-changeset'; 6 import validations from 'consul-ui/validations/kv'; 7 import lookupValidator from 'ember-changeset-validations'; 8 export default Controller.extend({ 9 json: true, 10 encoder: service('btoa'), 11 setProperties: function(model) { 12 // TODO: Potentially save whether json has been clicked to the model, 13 // setting set(this, 'json', true) here will force the form to always default to code=on 14 // even if the user has selected code=off on another KV 15 // ideally we would save the value per KV, but I'd like to not do that on the model 16 // a set(this, 'json', valueFromSomeStorageJustForThisKV) would be added here 17 this.changeset = new Changeset(model.item, lookupValidator(validations), validations); 18 this._super({ 19 ...model, 20 ...{ 21 item: this.changeset, 22 }, 23 }); 24 }, 25 actions: { 26 change: function(e) { 27 const target = e.target || { name: 'value', value: e }; 28 var parent; 29 switch (target.name) { 30 case 'additional': 31 parent = get(this, 'parent.Key'); 32 set(this.changeset, 'Key', `${parent !== '/' ? parent : ''}${target.value}`); 33 break; 34 case 'json': 35 set(this, 'json', !get(this, 'json')); 36 break; 37 case 'value': 38 set(this, 'item.Value', get(this, 'encoder').execute(target.value)); 39 break; 40 } 41 }, 42 }, 43 });