debian-mirror-gitlab/app/assets/javascripts/branches/branches_delete_modal.js

54 lines
1.5 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2017-09-10 17:25:29 +05:30
const MODAL_SELECTOR = '#modal-delete-branch';
class DeleteModal {
constructor() {
this.$modal = $(MODAL_SELECTOR);
this.$toggleBtns = $(`[data-target="${MODAL_SELECTOR}"]`);
this.$branchName = $('.js-branch-name', this.$modal);
this.$confirmInput = $('.js-delete-branch-input', this.$modal);
this.$deleteBtn = $('.js-delete-branch', this.$modal);
2018-03-17 18:26:18 +05:30
this.$notMerged = $('.js-not-merged', this.$modal);
2017-09-10 17:25:29 +05:30
this.bindEvents();
}
bindEvents() {
this.$toggleBtns.on('click', this.setModalData.bind(this));
this.$confirmInput.on('input', this.setDeleteDisabled.bind(this));
2018-10-15 14:42:47 +05:30
this.$deleteBtn.on('click', this.setDisableDeleteButton.bind(this));
2017-09-10 17:25:29 +05:30
}
setModalData(e) {
2018-03-17 18:26:18 +05:30
const branchData = e.currentTarget.dataset;
this.branchName = branchData.branchName || '';
this.deletePath = branchData.deletePath || '';
2019-09-04 21:01:54 +05:30
this.isMerged = Boolean(branchData.isMerged);
2017-09-10 17:25:29 +05:30
this.updateModal();
}
setDeleteDisabled(e) {
this.$deleteBtn.attr('disabled', e.currentTarget.value !== this.branchName);
}
2018-10-15 14:42:47 +05:30
setDisableDeleteButton(e) {
if (this.$deleteBtn.is('[disabled]')) {
e.preventDefault();
e.stopPropagation();
return false;
}
return true;
}
2017-09-10 17:25:29 +05:30
updateModal() {
this.$branchName.text(this.branchName);
this.$confirmInput.val('');
this.$deleteBtn.attr('href', this.deletePath);
this.$deleteBtn.attr('disabled', true);
2018-03-17 18:26:18 +05:30
this.$notMerged.toggleClass('hidden', this.isMerged);
2017-09-10 17:25:29 +05:30
}
}
export default DeleteModal;