debian-mirror-gitlab/app/assets/javascripts/pages/projects/labels/index/index.js

82 lines
2.3 KiB
JavaScript
Raw Normal View History

2018-03-27 19:54:05 +05:30
import Vue from 'vue';
2018-03-17 18:26:18 +05:30
import initLabels from '~/init_labels';
2021-03-11 19:13:27 +05:30
import { BV_SHOW_MODAL } from '~/lib/utils/constants';
import Translate from '~/vue_shared/translate';
2018-03-27 19:54:05 +05:30
import PromoteLabelModal from '../components/promote_label_modal.vue';
2021-03-11 19:13:27 +05:30
import eventHub from '../event_hub';
2018-03-17 18:26:18 +05:30
2018-03-27 19:54:05 +05:30
Vue.use(Translate);
const initLabelIndex = () => {
initLabels();
const onRequestFinished = ({ labelUrl, successful }) => {
2018-12-13 13:39:08 +05:30
const button = document.querySelector(
`.js-promote-project-label-button[data-url="${labelUrl}"]`,
);
2018-03-27 19:54:05 +05:30
if (!successful) {
button.removeAttribute('disabled');
}
};
2021-03-08 18:12:59 +05:30
const onRequestStarted = (labelUrl) => {
2018-12-13 13:39:08 +05:30
const button = document.querySelector(
`.js-promote-project-label-button[data-url="${labelUrl}"]`,
);
2018-03-27 19:54:05 +05:30
button.setAttribute('disabled', '');
eventHub.$once('promoteLabelModal.requestFinished', onRequestFinished);
};
const promoteLabelButtons = document.querySelectorAll('.js-promote-project-label-button');
2021-01-29 00:20:46 +05:30
return new Vue({
el: '#js-promote-label-modal',
data() {
return {
modalProps: {
labelTitle: '',
labelColor: '',
labelTextColor: '',
url: '',
groupName: '',
},
};
},
mounted() {
eventHub.$on('promoteLabelModal.props', this.setModalProps);
eventHub.$emit('promoteLabelModal.mounted');
2018-03-27 19:54:05 +05:30
2021-03-08 18:12:59 +05:30
promoteLabelButtons.forEach((button) => {
2021-01-29 00:20:46 +05:30
button.removeAttribute('disabled');
button.addEventListener('click', () => {
2021-03-11 19:13:27 +05:30
this.$root.$emit(BV_SHOW_MODAL, 'promote-label-modal');
2021-01-29 00:20:46 +05:30
eventHub.$once('promoteLabelModal.requestStarted', onRequestStarted);
2018-03-27 19:54:05 +05:30
2021-01-29 00:20:46 +05:30
this.setModalProps({
labelTitle: button.dataset.labelTitle,
labelColor: button.dataset.labelColor,
labelTextColor: button.dataset.labelTextColor,
url: button.dataset.url,
groupName: button.dataset.groupName,
});
2018-03-27 19:54:05 +05:30
});
2021-01-29 00:20:46 +05:30
});
},
beforeDestroy() {
eventHub.$off('promoteLabelModal.props', this.setModalProps);
},
methods: {
setModalProps(modalProps) {
this.modalProps = modalProps;
2018-03-27 19:54:05 +05:30
},
2021-01-29 00:20:46 +05:30
},
render(createElement) {
return createElement(PromoteLabelModal, {
props: this.modalProps,
});
},
});
2018-03-27 19:54:05 +05:30
};
2021-03-08 18:12:59 +05:30
initLabelIndex();