debian-mirror-gitlab/app/assets/javascripts/init_confirm_danger.js

53 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-12-11 22:18:48 +05:30
import Vue from 'vue';
2022-03-02 08:16:31 +05:30
import { pickBy } from 'lodash';
2021-12-11 22:18:48 +05:30
import { parseBoolean } from './lib/utils/common_utils';
import ConfirmDanger from './vue_shared/components/confirm_danger/confirm_danger.vue';
export default () => {
const el = document.querySelector('.js-confirm-danger');
if (!el) return null;
const {
removeFormId = null,
phrase,
buttonText,
2022-01-26 12:08:38 +05:30
buttonClass = '',
2021-12-11 22:18:48 +05:30
buttonTestid = null,
2022-03-02 08:16:31 +05:30
buttonVariant = null,
2021-12-11 22:18:48 +05:30
confirmDangerMessage,
2022-03-02 08:16:31 +05:30
confirmButtonText = null,
2021-12-11 22:18:48 +05:30
disabled = false,
2022-03-02 08:16:31 +05:30
additionalInformation,
htmlConfirmationMessage,
2021-12-11 22:18:48 +05:30
} = el.dataset;
return new Vue({
el,
2022-03-02 08:16:31 +05:30
provide: pickBy(
{
htmlConfirmationMessage,
confirmDangerMessage,
additionalInformation,
confirmButtonText,
},
(v) => Boolean(v),
),
2021-12-11 22:18:48 +05:30
render: (createElement) =>
createElement(ConfirmDanger, {
props: {
phrase,
buttonText,
2022-01-26 12:08:38 +05:30
buttonClass,
2022-03-02 08:16:31 +05:30
buttonVariant,
2021-12-11 22:18:48 +05:30
buttonTestid,
disabled: parseBoolean(disabled),
},
on: {
confirm: () => {
if (removeFormId) document.getElementById(removeFormId)?.submit();
},
},
}),
});
};