open-vault/ui/app/components/role-aws-edit.js

50 lines
1.2 KiB
JavaScript
Raw Normal View History

2018-04-03 14:16:57 +00:00
import RoleEdit from './role-edit';
import Ember from 'ember';
const { get, set } = Ember;
const SHOW_ROUTE = 'vault.cluster.secrets.backend.show';
export default RoleEdit.extend({
useARN: false,
init() {
this._super(...arguments);
const arn = get(this, 'model.arn');
if (arn) {
set(this, 'useARN', true);
}
},
actions: {
createOrUpdate(type, event) {
event.preventDefault();
const modelId = this.get('model.id');
// prevent from submitting if there's no key
// maybe do something fancier later
if (type === 'create' && Ember.isBlank(modelId)) {
return;
}
// clear the policy or arn before save depending on "useARN"
if (get(this, 'useARN')) {
set(this, 'model.policy', '');
} else {
set(this, 'model.arn', '');
}
this.persist('save', () => {
this.hasDataChanges();
this.transitionToRoute(SHOW_ROUTE, modelId);
});
},
codemirrorUpdated(attr, val, codemirror) {
codemirror.performLint();
const hasErrors = codemirror.state.lint.marked.length > 0;
if (!hasErrors) {
set(this.get('model'), attr, val);
}
},
},
});