consul/ui-v2/app/controllers/dc/intentions/edit.js

38 lines
1.3 KiB
JavaScript
Raw Normal View History

import Controller from '@ember/controller';
import { get, set } from '@ember/object';
2018-06-06 11:00:25 +00:00
import Changeset from 'ember-changeset';
import lookupValidator from 'ember-changeset-validations';
import validations from 'consul-ui/validations/intention';
export default Controller.extend({
setProperties: function(model) {
2018-06-06 11:00:25 +00:00
this.changeset = new Changeset(model.item, lookupValidator(validations), validations);
this._super({
...model,
...{
item: this.changeset,
SourceName: model.items.filterBy('Name', get(model.item, 'SourceName'))[0],
DestinationName: model.items.filterBy('Name', get(model.item, 'DestinationName'))[0],
},
});
},
actions: {
change: function(e, value, _target) {
2018-06-06 11:00:25 +00:00
// normalize back to standard event
const target = e.target || { ..._target, ...{ name: e, value: value } };
switch (target.name) {
case 'Action':
set(this.changeset, target.name, target.value);
2018-06-06 11:00:25 +00:00
console.log(target.name, target.value, get(this.changeset, target.name));
break;
case 'SourceName':
case 'DestinationName':
set(this.changeset, target.name, get(target.value, 'Name'));
set(this, target.name, target.value);
break;
}
},
},
});