open-vault/ui/lib/kmip/addon/components/edit-form-kmip-role.js
Matthew Irish 68f3b90978
UI - kmip role edit form (#6973)
* extend edit form with a custom kmip role form

* adjust model fields and use new kmip role edit form

* customize serialize adapter hook for kmip/role

* refresh list routes in the list mixin

* style up kmip role edit form

* return a promise from preSave so that the queue helper waits to call save

* add serialize tests for the kmip/role adapter

* rename component to edit-form-kmip-role

* add tests for edit-form-kmip-role

* add some clarifying comments

* make input more realistic in tests

* remove delete toolbar
2019-06-25 15:57:50 -05:00

56 lines
1.6 KiB
JavaScript

import EditForm from 'core/components/edit-form';
import layout from '../templates/components/edit-form-kmip-role';
import { Promise } from 'rsvp';
export default EditForm.extend({
layout,
display: null,
init() {
this._super(...arguments);
let display = 'operationAll';
if (this.model.operationNone) {
display = 'operationNone';
}
if (!this.model.isNew && !this.model.operationNone && !this.model.operationAll) {
display = 'choose';
}
this.set('display', display);
},
actions: {
updateModel(val) {
// here we only want to toggle operation(None|All) because we don't want to clear the other options in
// the case where the user clicks back to "choose" before saving
if (val === 'operationAll') {
this.model.set('operationNone', false);
this.model.set('operationAll', true);
}
if (val === 'operationNone') {
this.model.set('operationNone', true);
this.model.set('operationAll', false);
}
},
preSave(model) {
let { display } = this;
return new Promise(function(resolve) {
if (display === 'choose') {
model.set('operationNone', null);
model.set('operationAll', null);
return resolve(model);
}
model.newFields.without('role').forEach(field => {
// this will set operationAll or operationNone to true
if (field === display) {
model.set(field, true);
} else {
model.set(field, null);
}
});
return resolve(model);
});
},
},
});