2022-02-01 03:14:04 +00:00
|
|
|
import Vue from 'vue';
|
|
|
|
import { sprintf } from '~/locale';
|
|
|
|
import { parseBoolean } from '~/lib/utils/common_utils';
|
|
|
|
import TransferGroupForm, { i18n } from './components/transfer_group_form.vue';
|
|
|
|
|
|
|
|
const prepareGroups = (rawGroups) => {
|
2022-02-01 18:17:05 +00:00
|
|
|
if (!rawGroups) {
|
2022-02-12 00:12:46 +00:00
|
|
|
return [];
|
2022-02-01 18:17:05 +00:00
|
|
|
}
|
|
|
|
|
2022-02-12 00:12:46 +00:00
|
|
|
return JSON.parse(rawGroups).map(({ id, text: humanName }) => ({
|
2022-02-01 03:14:04 +00:00
|
|
|
id,
|
|
|
|
humanName,
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
|
|
|
export default () => {
|
|
|
|
const el = document.querySelector('.js-transfer-group-form');
|
|
|
|
if (!el) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const {
|
|
|
|
targetFormId = null,
|
|
|
|
buttonText: confirmButtonText = '',
|
|
|
|
groupName = '',
|
2022-02-01 18:17:05 +00:00
|
|
|
parentGroups,
|
2022-02-01 03:14:04 +00:00
|
|
|
isPaidGroup,
|
|
|
|
} = el.dataset;
|
|
|
|
|
|
|
|
return new Vue({
|
|
|
|
el,
|
|
|
|
provide: {
|
2022-02-02 15:17:50 +00:00
|
|
|
confirmDangerMessage: sprintf(i18n.confirmationMessage, { group_name: groupName }),
|
2022-02-01 03:14:04 +00:00
|
|
|
},
|
|
|
|
render(createElement) {
|
|
|
|
return createElement(TransferGroupForm, {
|
|
|
|
props: {
|
2022-02-12 00:12:46 +00:00
|
|
|
groupNamespaces: prepareGroups(parentGroups),
|
2022-02-01 03:14:04 +00:00
|
|
|
isPaidGroup: parseBoolean(isPaidGroup),
|
|
|
|
confirmButtonText,
|
|
|
|
confirmationPhrase: groupName,
|
|
|
|
},
|
|
|
|
on: {
|
|
|
|
confirm: () => {
|
|
|
|
document.getElementById(targetFormId)?.submit();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|