2021-12-09 09:11:03 +00:00
|
|
|
import $ from 'jquery';
|
2018-02-17 00:11:36 +00:00
|
|
|
import Vue from 'vue';
|
2021-12-09 09:11:03 +00:00
|
|
|
import initDatePicker from '~/behaviors/date_picker';
|
|
|
|
import GLForm from '~/gl_form';
|
2021-01-28 21:09:04 +00:00
|
|
|
import { BV_SHOW_MODAL } from '~/lib/utils/constants';
|
2021-12-09 09:11:03 +00:00
|
|
|
import Milestone from '~/milestones/milestone';
|
|
|
|
import Sidebar from '~/right_sidebar';
|
|
|
|
import MountMilestoneSidebar from '~/sidebar/mount_milestone_sidebar';
|
2021-02-14 18:09:20 +00:00
|
|
|
import Translate from '~/vue_shared/translate';
|
2021-12-09 09:11:03 +00:00
|
|
|
import ZenMode from '~/zen_mode';
|
2020-10-06 18:08:49 +00:00
|
|
|
import DeleteMilestoneModal from './components/delete_milestone_modal.vue';
|
2021-12-09 09:11:03 +00:00
|
|
|
import PromoteMilestoneModal from './components/promote_milestone_modal.vue';
|
2018-02-17 00:11:36 +00:00
|
|
|
import eventHub from './event_hub';
|
|
|
|
|
2021-12-09 09:11:03 +00:00
|
|
|
export function initForm(initGFM = true) {
|
|
|
|
new ZenMode(); // eslint-disable-line no-new
|
|
|
|
initDatePicker();
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new GLForm($('.milestone-form'), {
|
|
|
|
emojis: true,
|
|
|
|
members: initGFM,
|
|
|
|
issues: initGFM,
|
|
|
|
mergeRequests: initGFM,
|
|
|
|
epics: initGFM,
|
|
|
|
milestones: initGFM,
|
|
|
|
labels: initGFM,
|
|
|
|
snippets: initGFM,
|
|
|
|
vulnerabilities: initGFM,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function initShow() {
|
|
|
|
new Milestone(); // eslint-disable-line no-new
|
|
|
|
new Sidebar(); // eslint-disable-line no-new
|
|
|
|
new MountMilestoneSidebar(); // eslint-disable-line no-new
|
|
|
|
}
|
|
|
|
|
|
|
|
export function initPromoteMilestoneModal() {
|
|
|
|
Vue.use(Translate);
|
|
|
|
|
|
|
|
const promoteMilestoneModal = document.getElementById('promote-milestone-modal');
|
|
|
|
if (!promoteMilestoneModal) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Vue({
|
|
|
|
el: promoteMilestoneModal,
|
|
|
|
render(createElement) {
|
|
|
|
return createElement(PromoteMilestoneModal);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function initDeleteMilestoneModal() {
|
2018-02-17 00:11:36 +00:00
|
|
|
Vue.use(Translate);
|
|
|
|
|
|
|
|
const onRequestFinished = ({ milestoneUrl, successful }) => {
|
2018-10-10 06:41:22 +00:00
|
|
|
const button = document.querySelector(
|
|
|
|
`.js-delete-milestone-button[data-milestone-url="${milestoneUrl}"]`,
|
|
|
|
);
|
2018-02-17 00:11:36 +00:00
|
|
|
|
|
|
|
if (!successful) {
|
|
|
|
button.removeAttribute('disabled');
|
|
|
|
}
|
|
|
|
|
|
|
|
button.querySelector('.js-loading-icon').classList.add('hidden');
|
|
|
|
};
|
|
|
|
|
2020-10-06 18:08:49 +00:00
|
|
|
const deleteMilestoneButtons = document.querySelectorAll('.js-delete-milestone-button');
|
|
|
|
|
2020-12-23 21:10:24 +00:00
|
|
|
const onRequestStarted = (milestoneUrl) => {
|
2018-10-10 06:41:22 +00:00
|
|
|
const button = document.querySelector(
|
|
|
|
`.js-delete-milestone-button[data-milestone-url="${milestoneUrl}"]`,
|
|
|
|
);
|
2018-02-17 00:11:36 +00:00
|
|
|
button.setAttribute('disabled', '');
|
|
|
|
button.querySelector('.js-loading-icon').classList.remove('hidden');
|
|
|
|
eventHub.$once('deleteMilestoneModal.requestFinished', onRequestFinished);
|
|
|
|
};
|
|
|
|
|
|
|
|
return new Vue({
|
2020-10-06 18:08:49 +00:00
|
|
|
el: '#js-delete-milestone-modal',
|
2018-02-17 00:11:36 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
modalProps: {
|
|
|
|
milestoneId: -1,
|
|
|
|
milestoneTitle: '',
|
|
|
|
milestoneUrl: '',
|
|
|
|
issueCount: -1,
|
|
|
|
mergeRequestCount: -1,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
eventHub.$on('deleteMilestoneModal.props', this.setModalProps);
|
2020-12-23 21:10:24 +00:00
|
|
|
deleteMilestoneButtons.forEach((button) => {
|
2020-10-06 18:08:49 +00:00
|
|
|
button.removeAttribute('disabled');
|
|
|
|
button.addEventListener('click', () => {
|
2021-01-28 21:09:04 +00:00
|
|
|
this.$root.$emit(BV_SHOW_MODAL, 'delete-milestone-modal');
|
2020-10-06 18:08:49 +00:00
|
|
|
eventHub.$once('deleteMilestoneModal.requestStarted', onRequestStarted);
|
|
|
|
|
|
|
|
this.setModalProps({
|
|
|
|
milestoneId: parseInt(button.dataset.milestoneId, 10),
|
|
|
|
milestoneTitle: button.dataset.milestoneTitle,
|
|
|
|
milestoneUrl: button.dataset.milestoneUrl,
|
|
|
|
issueCount: parseInt(button.dataset.milestoneIssueCount, 10),
|
|
|
|
mergeRequestCount: parseInt(button.dataset.milestoneMergeRequestCount, 10),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-02-17 00:11:36 +00:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
setModalProps(modalProps) {
|
|
|
|
this.modalProps = modalProps;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
render(createElement) {
|
2020-10-06 18:08:49 +00:00
|
|
|
return createElement(DeleteMilestoneModal, {
|
2018-02-17 00:11:36 +00:00
|
|
|
props: this.modalProps,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
2021-12-09 09:11:03 +00:00
|
|
|
}
|