debian-mirror-gitlab/app/assets/javascripts/pages/admin/users/index.js

66 lines
1.7 KiB
JavaScript
Raw Normal View History

2018-03-17 18:26:18 +05:30
import Vue from 'vue';
import Translate from '~/vue_shared/translate';
2019-12-21 20:55:43 +05:30
import ModalManager from './components/user_modal_manager.vue';
import DeleteUserModal from './components/delete_user_modal.vue';
import UserOperationConfirmationModal from './components/user_operation_confirmation_modal.vue';
2018-03-17 18:26:18 +05:30
import csrf from '~/lib/utils/csrf';
2019-12-21 20:55:43 +05:30
const MODAL_TEXTS_CONTAINER_SELECTOR = '#modal-texts';
const MODAL_MANAGER_SELECTOR = '#user-modal';
const ACTION_MODALS = {
deactivate: UserOperationConfirmationModal,
block: UserOperationConfirmationModal,
delete: DeleteUserModal,
'delete-with-contributions': DeleteUserModal,
};
function loadModalsConfigurationFromHtml(modalsElement) {
const modalsConfiguration = {};
if (!modalsElement) {
2020-04-22 19:07:51 +05:30
/* eslint-disable-next-line @gitlab/require-i18n-strings */
2019-12-21 20:55:43 +05:30
throw new Error('Modals content element not found!');
}
Array.from(modalsElement.children).forEach(node => {
const { modal, ...config } = node.dataset;
modalsConfiguration[modal] = {
title: node.dataset.title,
...config,
content: node.innerHTML,
};
});
return modalsConfiguration;
}
2018-03-17 18:26:18 +05:30
2018-03-27 19:54:05 +05:30
document.addEventListener('DOMContentLoaded', () => {
2018-03-17 18:26:18 +05:30
Vue.use(Translate);
2019-12-21 20:55:43 +05:30
const modalConfiguration = loadModalsConfigurationFromHtml(
document.querySelector(MODAL_TEXTS_CONTAINER_SELECTOR),
);
2018-03-17 18:26:18 +05:30
2019-12-21 20:55:43 +05:30
// eslint-disable-next-line no-new
new Vue({
el: MODAL_MANAGER_SELECTOR,
functional: true,
methods: {
show(...args) {
this.$refs.manager.show(...args);
},
2018-03-17 18:26:18 +05:30
},
2019-12-21 20:55:43 +05:30
render(h) {
return h(ModalManager, {
ref: 'manager',
2018-03-17 18:26:18 +05:30
props: {
2019-12-21 20:55:43 +05:30
modalConfiguration,
actionModals: ACTION_MODALS,
2018-03-17 18:26:18 +05:30
csrfToken: csrf.token,
},
});
},
});
2018-03-27 19:54:05 +05:30
});