open-vault/ui/lib/core/addon/components/model-wrap.js
Matthew Irish ddf8c20219
UI - add delete for the various kmip models (#7015)
* add menu-loader component to show menu loading button when the model relationship isPending

* list what keys we've got in api-path error

* fix spacing issue on error flash

* add an action on list-controller that bubbles to the list-route mixin to refresh the route

* empty store when creating scopes

* don't delete _requestQuery in the loop, do it after

* add scope deletion from the scope list

* add deleteRecord to kmip adapters

* add model-wrap component

* delete role from detail page and list

* add revoke credentials functionality

* fix comment

* treat all operations fields specially on kmip roles

* adjust kmip role edit form for new fields

* fix api-path test

* update document blocks for menu-loader and model-wrap components
2019-07-02 16:23:07 -05:00

38 lines
1.1 KiB
JavaScript

/**
* @module ModelWrap
* ModelWrap components provide a way to call methods on models directly from templates. This is done by yielding callMethod task to the wrapped component.
*
* @example
* ```js
* <ModelWrap as |m|>
<button onclick={{action (perform m.callMethod "save" model "Saved!" "Errored!" (transition-to "route")}}>
* </ModelWrap>
* ```
*
* @yields callMethod {Function}
*
*/
import { inject as service } from '@ember/service';
import Component from '@ember/component';
import { task } from 'ember-concurrency';
import layout from '../templates/components/model-wrap';
export default Component.extend({
layout,
flashMessages: service(),
tagName: '',
callMethod: task(function*(method, model, successMessage, failureMessage, successCallback = () => {}) {
let flash = this.get('flashMessages');
try {
yield model[method]();
flash.success(successMessage);
successCallback();
} catch (e) {
let errString = e.errors.join(' ');
flash.danger(failureMessage + ' ' + errString);
model.rollbackAttributes();
}
}),
});