2018-03-27 19:54:05 +05:30
|
|
|
import Vue from 'vue';
|
|
|
|
import Translate from '~/vue_shared/translate';
|
2018-03-17 18:26:18 +05:30
|
|
|
import initLabels from '~/init_labels';
|
2018-03-27 19:54:05 +05:30
|
|
|
import eventHub from '../event_hub';
|
|
|
|
import PromoteLabelModal from '../components/promote_label_modal.vue';
|
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');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
const onRequestStarted = labelUrl => {
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
const onDeleteButtonClick = event => {
|
2018-03-27 19:54:05 +05:30
|
|
|
const button = event.currentTarget;
|
|
|
|
const modalProps = {
|
|
|
|
labelTitle: button.dataset.labelTitle,
|
|
|
|
labelColor: button.dataset.labelColor,
|
|
|
|
labelTextColor: button.dataset.labelTextColor,
|
|
|
|
url: button.dataset.url,
|
2018-05-01 15:08:00 +05:30
|
|
|
groupName: button.dataset.groupName,
|
2018-03-27 19:54:05 +05:30
|
|
|
};
|
|
|
|
eventHub.$once('promoteLabelModal.requestStarted', onRequestStarted);
|
|
|
|
eventHub.$emit('promoteLabelModal.props', modalProps);
|
|
|
|
};
|
|
|
|
|
|
|
|
const promoteLabelButtons = document.querySelectorAll('.js-promote-project-label-button');
|
2018-12-13 13:39:08 +05:30
|
|
|
promoteLabelButtons.forEach(button => {
|
2018-03-27 19:54:05 +05:30
|
|
|
button.addEventListener('click', onDeleteButtonClick);
|
|
|
|
});
|
|
|
|
|
|
|
|
eventHub.$once('promoteLabelModal.mounted', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
promoteLabelButtons.forEach(button => {
|
2018-03-27 19:54:05 +05:30
|
|
|
button.removeAttribute('disabled');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
const promoteLabelModal = document.getElementById('promote-label-modal');
|
|
|
|
let promoteLabelModalComponent;
|
|
|
|
|
|
|
|
if (promoteLabelModal) {
|
|
|
|
promoteLabelModalComponent = new Vue({
|
|
|
|
el: promoteLabelModal,
|
|
|
|
components: {
|
|
|
|
PromoteLabelModal,
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
modalProps: {
|
|
|
|
labelTitle: '',
|
|
|
|
labelColor: '',
|
|
|
|
labelTextColor: '',
|
|
|
|
url: '',
|
2018-05-01 15:08:00 +05:30
|
|
|
groupName: '',
|
2018-03-27 19:54:05 +05:30
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
eventHub.$on('promoteLabelModal.props', this.setModalProps);
|
|
|
|
eventHub.$emit('promoteLabelModal.mounted');
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
eventHub.$off('promoteLabelModal.props', this.setModalProps);
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
setModalProps(modalProps) {
|
|
|
|
this.modalProps = modalProps;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
render(createElement) {
|
|
|
|
return createElement('promote-label-modal', {
|
|
|
|
props: this.modalProps,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return promoteLabelModalComponent;
|
|
|
|
};
|
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', initLabelIndex);
|