diff options
author | Sam Rose <samrose3@gmail.com> | 2017-05-08 10:41:58 +0300 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2017-05-08 10:41:58 +0300 |
commit | 1ebd9dad8e4a3ade4fa829d1d5ac6cbc9825bf48 (patch) | |
tree | ea175b4ef388f79d8550a424ac5b46a535555664 /app/assets/javascripts/branches | |
parent | 1a5e84febeb3f2d63c019981e80c777195c37dd2 (diff) |
Add confirm delete protected branch modal
Diffstat (limited to 'app/assets/javascripts/branches')
-rw-r--r-- | app/assets/javascripts/branches/branches_delete_modal.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/app/assets/javascripts/branches/branches_delete_modal.js b/app/assets/javascripts/branches/branches_delete_modal.js new file mode 100644 index 00000000000..af8bcdc1794 --- /dev/null +++ b/app/assets/javascripts/branches/branches_delete_modal.js @@ -0,0 +1,36 @@ +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); + this.bindEvents(); + } + + bindEvents() { + this.$toggleBtns.on('click', this.setModalData.bind(this)); + this.$confirmInput.on('input', this.setDeleteDisabled.bind(this)); + } + + setModalData(e) { + this.branchName = e.currentTarget.dataset.branchName || ''; + this.deletePath = e.currentTarget.dataset.deletePath || ''; + this.updateModal(); + } + + setDeleteDisabled(e) { + this.$deleteBtn.attr('disabled', e.currentTarget.value !== this.branchName); + } + + updateModal() { + this.$branchName.text(this.branchName); + this.$confirmInput.val(''); + this.$deleteBtn.attr('href', this.deletePath); + this.$deleteBtn.attr('disabled', true); + } +} + +export default DeleteModal; |