diff options
author | Luke "Jared" Bennett <lbennett@gitlab.com> | 2017-07-07 16:51:34 +0300 |
---|---|---|
committer | Luke "Jared" Bennett <lbennett@gitlab.com> | 2017-07-07 16:57:28 +0300 |
commit | 78dd2f056fac9077c85c4e1b3d9d42abaa7aed05 (patch) | |
tree | 7763c6bdf543fa21c67ea3b46e1f70b1928a222b /app/assets/javascripts | |
parent | f0f94278d80f06f01808f6301a1a43d5ab06cef2 (diff) |
Added issuables_helper.js, tidied up droplab-dropdown JS, fixed filtered search specs
Diffstat (limited to 'app/assets/javascripts')
-rw-r--r-- | app/assets/javascripts/helpers/issuables_helper.js | 21 | ||||
-rw-r--r-- | app/assets/javascripts/issue.js | 36 | ||||
-rw-r--r-- | app/assets/javascripts/merge_request.js | 22 |
3 files changed, 33 insertions, 46 deletions
diff --git a/app/assets/javascripts/helpers/issuables_helper.js b/app/assets/javascripts/helpers/issuables_helper.js new file mode 100644 index 00000000000..68fd8c74bea --- /dev/null +++ b/app/assets/javascripts/helpers/issuables_helper.js @@ -0,0 +1,21 @@ +import CloseReopenReportToggle from '../close_reopen_report_toggle'; + +export default function initCloseReopenReport() { + const container = document.querySelector('.js-issuable-close-dropdown'); + + if (!container) return undefined; + + const dropdownTrigger = container.querySelector('.js-issuable-close-toggle'); + const dropdownList = container.querySelector('.js-issuable-close-menu'); + const button = container.querySelector('.js-issuable-close-button'); + + const closeReopenReportToggle = new CloseReopenReportToggle({ + dropdownTrigger, + dropdownList, + button, + }); + + closeReopenReportToggle.initDroplab(); + + return closeReopenReportToggle; +} diff --git a/app/assets/javascripts/issue.js b/app/assets/javascripts/issue.js index 91e696f5320..912da6ed6c1 100644 --- a/app/assets/javascripts/issue.js +++ b/app/assets/javascripts/issue.js @@ -6,7 +6,7 @@ import '~/lib/utils/text_utility'; import './flash'; import './task_list'; import CreateMergeRequestDropdown from './create_merge_request_dropdown'; -import CloseReopenReportToggle from './close_reopen_report_toggle'; +import initCloseReopenReport from './helpers/issuables_helper'; class Issue { constructor() { @@ -29,12 +29,10 @@ class Issue { Issue.initMergeRequests(); Issue.initRelatedBranches(); - this.initCloseReopenReport(); + this.closeButtons = $('a.btn-close'); + this.reopenButtons = $('a.btn-reopen'); - if (!this.closeReopenReportToggle) { - this.closeButtons = $('a.btn-close'); - this.reopenButtons = $('a.btn-reopen'); - } + this.initCloseReopenReport(); if (Issue.createMrDropdownWrap) { this.createMergeRequestDropdown = new CreateMergeRequestDropdown(Issue.createMrDropdownWrap); @@ -100,21 +98,10 @@ class Issue { } initCloseReopenReport() { - const container = document.querySelector('.js-issuable-close-dropdown'); - - if (!container) return; - - const dropdownTrigger = container.querySelector('.js-issuable-close-toggle'); - const dropdownList = container.querySelector('.js-issuable-close-menu'); - const button = container.querySelector('.js-issuable-close-button'); + this.closeReopenReportToggle = initCloseReopenReport(); - this.closeReopenReportToggle = new CloseReopenReportToggle({ - dropdownTrigger, - dropdownList, - button, - }); - - this.closeReopenReportToggle.initDroplab(); + this.closeButtons = this.closeButtons.not('.issuable-close-button'); + this.reopenButtons = this.reopenButtons.not('.issuable-close-button'); } disableCloseReopenButton($button, shouldDisable) { @@ -126,12 +113,9 @@ class Issue { } toggleCloseReopenButton(isClosed) { - if (this.closeReopenReportToggle) { - this.closeReopenReportToggle.updateButton(isClosed); - } else { - this.closeButtons.toggleClass('hidden', isClosed); - this.reopenButtons.toggleClass('hidden', !isClosed); - } + if (this.closeReopenReportToggle) this.closeReopenReportToggle.updateButton(isClosed); + this.closeButtons.toggleClass('hidden', isClosed); + this.reopenButtons.toggleClass('hidden', !isClosed); } static submitNoteForm(form) { diff --git a/app/assets/javascripts/merge_request.js b/app/assets/javascripts/merge_request.js index 10860d1363f..938c7446a06 100644 --- a/app/assets/javascripts/merge_request.js +++ b/app/assets/javascripts/merge_request.js @@ -4,7 +4,7 @@ import 'vendor/jquery.waitforimages'; import './task_list'; import './merge_request_tabs'; -import CloseReopenReportToggle from './close_reopen_report_toggle'; +import initCloseReopenReport from './helpers/issuables_helper'; (function() { this.MergeRequest = (function() { @@ -26,7 +26,7 @@ import CloseReopenReportToggle from './close_reopen_report_toggle'; this.initTabs(); this.initMRBtnListeners(); this.initCommitMessageListeners(); - this.initCloseReopenReport(); + this.closeReopenReportToggle = initCloseReopenReport(); if ($("a.btn-close").length) { this.taskList = new gl.TaskList({ @@ -127,24 +127,6 @@ import CloseReopenReportToggle from './close_reopen_report_toggle'; $el.text(gl.text.addDelimiter(count)); }; - MergeRequest.prototype.initCloseReopenReport = function () { - const container = document.querySelector('.js-issuable-close-dropdown'); - - if (!container) return; - - const dropdownTrigger = container.querySelector('.js-issuable-close-toggle'); - const dropdownList = container.querySelector('.js-issuable-close-menu'); - const button = container.querySelector('.js-issuable-close-button'); - - this.closeReopenReportToggle = new CloseReopenReportToggle({ - dropdownTrigger, - dropdownList, - button, - }); - - this.closeReopenReportToggle.initDroplab(); - }; - return MergeRequest; })(); }).call(window); |