2017-05-15 18:12:43 -04:00
|
|
|
/* eslint-disable class-methods-use-this, no-new */
|
|
|
|
|
|
|
|
import IssuableBulkUpdateActions from './issuable_bulk_update_actions';
|
2017-12-28 15:07:05 -05:00
|
|
|
import MilestoneSelect from './milestone_select';
|
2017-10-30 14:59:16 -04:00
|
|
|
import issueStatusSelect from './issue_status_select';
|
2017-11-20 15:28:29 -05:00
|
|
|
import subscriptionSelect from './subscription_select';
|
2017-11-01 08:32:15 -04:00
|
|
|
import LabelsSelect from './labels_select';
|
2017-05-15 18:12:43 -04:00
|
|
|
|
|
|
|
const HIDDEN_CLASS = 'hidden';
|
|
|
|
const DISABLED_CONTENT_CLASS = 'disabled-content';
|
|
|
|
const SIDEBAR_EXPANDED_CLASS = 'right-sidebar-expanded issuable-bulk-update-sidebar';
|
|
|
|
const SIDEBAR_COLLAPSED_CLASS = 'right-sidebar-collapsed issuable-bulk-update-sidebar';
|
|
|
|
|
|
|
|
export default class IssuableBulkUpdateSidebar {
|
|
|
|
constructor() {
|
|
|
|
this.initDomElements();
|
|
|
|
this.bindEvents();
|
|
|
|
this.initDropdowns();
|
|
|
|
this.setupBulkUpdateActions();
|
|
|
|
}
|
|
|
|
|
|
|
|
initDomElements() {
|
2017-12-08 16:19:01 -05:00
|
|
|
this.$page = $('.layout-page');
|
2017-05-15 18:12:43 -04:00
|
|
|
this.$sidebar = $('.right-sidebar');
|
2017-06-21 03:33:39 -04:00
|
|
|
this.$sidebarInnerContainer = this.$sidebar.find('.issuable-sidebar');
|
2017-05-15 18:12:43 -04:00
|
|
|
this.$bulkEditCancelBtn = $('.js-bulk-update-menu-hide');
|
|
|
|
this.$bulkEditSubmitBtn = $('.update-selected-issues');
|
|
|
|
this.$bulkUpdateEnableBtn = $('.js-bulk-update-toggle');
|
|
|
|
this.$otherFilters = $('.issues-other-filters');
|
|
|
|
this.$checkAllContainer = $('.check-all-holder');
|
|
|
|
this.$issueChecks = $('.issue-check');
|
|
|
|
this.$issuesList = $('.selected_issue');
|
|
|
|
this.$issuableIdsInput = $('#update_issuable_ids');
|
|
|
|
}
|
|
|
|
|
|
|
|
bindEvents() {
|
|
|
|
this.$bulkUpdateEnableBtn.on('click', e => this.toggleBulkEdit(e, true));
|
|
|
|
this.$bulkEditCancelBtn.on('click', e => this.toggleBulkEdit(e, false));
|
|
|
|
this.$checkAllContainer.on('click', e => this.selectAll(e));
|
|
|
|
this.$issuesList.on('change', () => this.updateFormState());
|
|
|
|
this.$bulkEditSubmitBtn.on('click', () => this.prepForSubmit());
|
|
|
|
this.$checkAllContainer.on('click', () => this.updateFormState());
|
|
|
|
}
|
|
|
|
|
|
|
|
initDropdowns() {
|
|
|
|
new LabelsSelect();
|
|
|
|
new MilestoneSelect();
|
2017-10-30 14:59:16 -04:00
|
|
|
issueStatusSelect();
|
2017-11-20 15:28:29 -05:00
|
|
|
subscriptionSelect();
|
2017-05-15 18:12:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
setupBulkUpdateActions() {
|
|
|
|
IssuableBulkUpdateActions.setOriginalDropdownData();
|
|
|
|
}
|
|
|
|
|
|
|
|
updateFormState() {
|
|
|
|
const noCheckedIssues = !$('.selected_issue:checked').length;
|
|
|
|
|
|
|
|
this.toggleSubmitButtonDisabled(noCheckedIssues);
|
|
|
|
this.updateSelectedIssuableIds();
|
|
|
|
|
|
|
|
IssuableBulkUpdateActions.setOriginalDropdownData();
|
|
|
|
}
|
|
|
|
|
|
|
|
prepForSubmit() {
|
|
|
|
// if submit button is disabled, submission is blocked. This ensures we disable after
|
|
|
|
// form submission is carried out
|
|
|
|
setTimeout(() => this.$bulkEditSubmitBtn.disable());
|
|
|
|
this.updateSelectedIssuableIds();
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleBulkEdit(e, enable) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
this.toggleSidebarDisplay(enable);
|
|
|
|
this.toggleBulkEditButtonDisabled(enable);
|
|
|
|
this.toggleOtherFiltersDisabled(enable);
|
|
|
|
this.toggleCheckboxDisplay(enable);
|
2017-07-24 03:47:38 -04:00
|
|
|
}
|
|
|
|
|
2017-05-15 18:12:43 -04:00
|
|
|
updateSelectedIssuableIds() {
|
|
|
|
this.$issuableIdsInput.val(IssuableBulkUpdateSidebar.getCheckedIssueIds());
|
|
|
|
}
|
|
|
|
|
|
|
|
selectAll() {
|
|
|
|
const checkAllButtonState = this.$checkAllContainer.find('input').prop('checked');
|
|
|
|
|
|
|
|
this.$issuesList.prop('checked', checkAllButtonState);
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleSidebarDisplay(show) {
|
|
|
|
this.$page.toggleClass(SIDEBAR_EXPANDED_CLASS, show);
|
|
|
|
this.$page.toggleClass(SIDEBAR_COLLAPSED_CLASS, !show);
|
2017-06-21 03:33:39 -04:00
|
|
|
this.$sidebarInnerContainer.toggleClass(HIDDEN_CLASS, !show);
|
2017-05-15 18:12:43 -04:00
|
|
|
this.$sidebar.toggleClass(SIDEBAR_EXPANDED_CLASS, show);
|
|
|
|
this.$sidebar.toggleClass(SIDEBAR_COLLAPSED_CLASS, !show);
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleBulkEditButtonDisabled(disable) {
|
|
|
|
if (disable) {
|
|
|
|
this.$bulkUpdateEnableBtn.disable();
|
|
|
|
} else {
|
|
|
|
this.$bulkUpdateEnableBtn.enable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleCheckboxDisplay(show) {
|
|
|
|
this.$checkAllContainer.toggleClass(HIDDEN_CLASS, !show);
|
|
|
|
this.$issueChecks.toggleClass(HIDDEN_CLASS, !show);
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleOtherFiltersDisabled(disable) {
|
|
|
|
this.$otherFilters.toggleClass(DISABLED_CONTENT_CLASS, disable);
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleSubmitButtonDisabled(disable) {
|
|
|
|
if (disable) {
|
|
|
|
this.$bulkEditSubmitBtn.disable();
|
|
|
|
} else {
|
|
|
|
this.$bulkEditSubmitBtn.enable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static getCheckedIssueIds() {
|
|
|
|
const $checkedIssues = $('.selected_issue:checked');
|
|
|
|
|
|
|
|
if ($checkedIssues.length > 0) {
|
|
|
|
return $.map($checkedIssues, value => $(value).data('id'));
|
|
|
|
}
|
|
|
|
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|