2017-01-10 18:02:20 -05:00
|
|
|
/* eslint-disable no-useless-return, func-names, space-before-function-paren, wrap-iife, no-var, no-underscore-dangle, prefer-arrow-callback, max-len, one-var, no-unused-vars, one-var-declaration-per-line, prefer-template, no-new, consistent-return, object-shorthand, comma-dangle, no-shadow, no-param-reassign, brace-style, vars-on-top, quotes, no-lonely-if, no-else-return, dot-notation, no-empty, no-return-assign, camelcase, prefer-spread */
|
2016-12-14 00:26:26 -05:00
|
|
|
/* global Issuable */
|
|
|
|
/* global ListLabel */
|
2017-08-03 16:31:53 -04:00
|
|
|
import _ from 'underscore';
|
2017-05-15 18:12:43 -04:00
|
|
|
import IssuableBulkUpdateActions from './issuable_bulk_update_actions';
|
2017-08-02 05:27:24 -04:00
|
|
|
import DropdownUtils from './filtered_search/dropdown_utils';
|
2017-05-15 18:12:43 -04:00
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
(function() {
|
|
|
|
this.LabelsSelect = (function() {
|
2017-02-01 12:02:17 -05:00
|
|
|
function LabelsSelect(els) {
|
|
|
|
var _this, $els;
|
2016-07-24 16:45:11 -04:00
|
|
|
_this = this;
|
2017-02-01 12:02:17 -05:00
|
|
|
|
|
|
|
$els = $(els);
|
|
|
|
|
|
|
|
if (!els) {
|
|
|
|
$els = $('.js-label-select');
|
|
|
|
}
|
|
|
|
|
|
|
|
$els.each(function(i, dropdown) {
|
2016-12-15 18:02:45 -05:00
|
|
|
var $block, $colorPreview, $dropdown, $form, $loading, $selectbox, $sidebarCollapsedValue, $value, abilityName, defaultLabel, enableLabelCreateButton, issueURLSplit, issueUpdateURL, labelHTMLTemplate, labelNoneHTMLTemplate, labelUrl, namespacePath, projectPath, saveLabelData, selectedLabel, showAny, showNo, $sidebarLabelTooltip, initialSelected, $toggleText, fieldName, useId, propertyName, showMenuAbove, $container, $dropdownContainer;
|
2016-07-24 16:45:11 -04:00
|
|
|
$dropdown = $(dropdown);
|
2016-12-13 16:38:21 -05:00
|
|
|
$dropdownContainer = $dropdown.closest('.labels-filter');
|
2016-08-30 06:21:29 -04:00
|
|
|
$toggleText = $dropdown.find('.dropdown-toggle-text');
|
2016-09-22 12:07:57 -04:00
|
|
|
namespacePath = $dropdown.data('namespace-path');
|
|
|
|
projectPath = $dropdown.data('project-path');
|
2016-07-24 16:45:11 -04:00
|
|
|
labelUrl = $dropdown.data('labels');
|
|
|
|
issueUpdateURL = $dropdown.data('issueUpdate');
|
|
|
|
selectedLabel = $dropdown.data('selected');
|
|
|
|
if ((selectedLabel != null) && !$dropdown.hasClass('js-multiselect')) {
|
|
|
|
selectedLabel = selectedLabel.split(',');
|
|
|
|
}
|
|
|
|
showNo = $dropdown.data('show-no');
|
|
|
|
showAny = $dropdown.data('show-any');
|
2016-10-04 15:21:06 -04:00
|
|
|
showMenuAbove = $dropdown.data('showMenuAbove');
|
2016-07-24 16:45:11 -04:00
|
|
|
defaultLabel = $dropdown.data('default-label');
|
|
|
|
abilityName = $dropdown.data('ability-name');
|
|
|
|
$selectbox = $dropdown.closest('.selectbox');
|
|
|
|
$block = $selectbox.closest('.block');
|
2016-10-07 06:12:02 -04:00
|
|
|
$form = $dropdown.closest('form, .js-issuable-update');
|
2016-07-24 16:45:11 -04:00
|
|
|
$sidebarCollapsedValue = $block.find('.sidebar-collapsed-icon span');
|
2016-07-13 06:53:27 -04:00
|
|
|
$sidebarLabelTooltip = $block.find('.js-sidebar-labels-tooltip');
|
2016-07-24 16:45:11 -04:00
|
|
|
$value = $block.find('.value');
|
|
|
|
$loading = $block.find('.block-loading').fadeOut();
|
2016-08-30 06:21:29 -04:00
|
|
|
fieldName = $dropdown.data('field-name');
|
|
|
|
useId = $dropdown.is('.js-issuable-form-dropdown, .js-filter-bulk-update, .js-label-sidebar-dropdown');
|
|
|
|
propertyName = useId ? 'id' : 'title';
|
2016-09-27 11:23:15 -04:00
|
|
|
initialSelected = $selectbox
|
|
|
|
.find('input[name="' + $dropdown.data('field-name') + '"]')
|
|
|
|
.map(function () {
|
|
|
|
return this.value;
|
|
|
|
}).get();
|
2016-07-24 16:45:11 -04:00
|
|
|
if (issueUpdateURL != null) {
|
|
|
|
issueURLSplit = issueUpdateURL.split('/');
|
|
|
|
}
|
|
|
|
if (issueUpdateURL) {
|
|
|
|
labelHTMLTemplate = _.template('<% _.each(labels, function(label){ %> <a href="<%- ["",issueURLSplit[1], issueURLSplit[2],""].join("/") %>issues?label_name[]=<%- encodeURIComponent(label.title) %>"> <span class="label has-tooltip color-label" title="<%- label.description %>" style="background-color: <%- label.color %>; color: <%- label.text_color %>;"> <%- label.title %> </span> </a> <% }); %>');
|
|
|
|
labelNoneHTMLTemplate = '<span class="no-value">None</span>';
|
|
|
|
}
|
2016-08-08 10:43:07 -04:00
|
|
|
|
2016-08-18 06:38:12 -04:00
|
|
|
$sidebarLabelTooltip.tooltip();
|
|
|
|
|
2016-08-18 08:59:09 -04:00
|
|
|
if ($dropdown.closest('.dropdown').find('.dropdown-new-label').length) {
|
2016-09-22 12:07:57 -04:00
|
|
|
new gl.CreateLabelDropdown($dropdown.closest('.dropdown').find('.dropdown-new-label'), namespacePath, projectPath);
|
2016-08-18 08:59:09 -04:00
|
|
|
}
|
2016-08-08 10:43:07 -04:00
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
saveLabelData = function() {
|
|
|
|
var data, selected;
|
2016-08-30 06:21:29 -04:00
|
|
|
selected = $dropdown.closest('.selectbox').find("input[name='" + fieldName + "']").map(function() {
|
2016-07-24 16:45:11 -04:00
|
|
|
return this.value;
|
|
|
|
}).get();
|
2016-09-27 11:23:15 -04:00
|
|
|
|
|
|
|
if (_.isEqual(initialSelected, selected)) return;
|
|
|
|
initialSelected = selected;
|
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
data = {};
|
|
|
|
data[abilityName] = {};
|
|
|
|
data[abilityName].label_ids = selected;
|
|
|
|
if (!selected.length) {
|
|
|
|
data[abilityName].label_ids = [''];
|
|
|
|
}
|
2017-03-15 08:08:01 -04:00
|
|
|
$loading.removeClass('hidden').fadeIn();
|
2016-07-24 16:45:11 -04:00
|
|
|
$dropdown.trigger('loading.gl.dropdown');
|
|
|
|
return $.ajax({
|
|
|
|
type: 'PUT',
|
|
|
|
url: issueUpdateURL,
|
|
|
|
dataType: 'JSON',
|
|
|
|
data: data
|
|
|
|
}).done(function(data) {
|
2016-08-03 06:30:36 -04:00
|
|
|
var labelCount, template, labelTooltipTitle, labelTitles;
|
2016-07-24 16:45:11 -04:00
|
|
|
$loading.fadeOut();
|
|
|
|
$dropdown.trigger('loaded.gl.dropdown');
|
|
|
|
$selectbox.hide();
|
|
|
|
data.issueURLSplit = issueURLSplit;
|
|
|
|
labelCount = 0;
|
|
|
|
if (data.labels.length) {
|
|
|
|
template = labelHTMLTemplate(data);
|
|
|
|
labelCount = data.labels.length;
|
2016-10-04 10:52:35 -04:00
|
|
|
}
|
|
|
|
else {
|
2016-07-24 16:45:11 -04:00
|
|
|
template = labelNoneHTMLTemplate;
|
|
|
|
}
|
|
|
|
$value.removeAttr('style').html(template);
|
|
|
|
$sidebarCollapsedValue.text(labelCount);
|
2016-07-13 06:53:27 -04:00
|
|
|
|
|
|
|
if (data.labels.length) {
|
2016-08-03 06:30:36 -04:00
|
|
|
labelTitles = data.labels.map(function(label) {
|
|
|
|
return label.title;
|
|
|
|
});
|
2016-07-13 06:53:27 -04:00
|
|
|
|
2016-08-03 06:30:36 -04:00
|
|
|
if (labelTitles.length > 5) {
|
|
|
|
labelTitles = labelTitles.slice(0, 5);
|
|
|
|
labelTitles.push('and ' + (data.labels.length - 5) + ' more');
|
2016-07-13 06:53:27 -04:00
|
|
|
}
|
|
|
|
|
2016-08-03 06:30:36 -04:00
|
|
|
labelTooltipTitle = labelTitles.join(', ');
|
2016-10-04 10:52:35 -04:00
|
|
|
}
|
|
|
|
else {
|
2016-07-13 06:53:27 -04:00
|
|
|
labelTooltipTitle = '';
|
|
|
|
$sidebarLabelTooltip.tooltip('destroy');
|
|
|
|
}
|
|
|
|
|
|
|
|
$sidebarLabelTooltip
|
|
|
|
.attr('title', labelTooltipTitle)
|
|
|
|
.tooltip('fixTitle');
|
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
$('.has-tooltip', $value).tooltip({
|
|
|
|
container: 'body'
|
|
|
|
});
|
|
|
|
return $value.find('a').each(function(i) {
|
|
|
|
return setTimeout((function(_this) {
|
|
|
|
return function() {
|
|
|
|
return gl.animate.animate($(_this), 'pulse');
|
|
|
|
};
|
|
|
|
})(this), 200 * i);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2016-11-29 02:47:02 -05:00
|
|
|
$dropdown.glDropdown({
|
2016-10-04 15:21:06 -04:00
|
|
|
showMenuAbove: showMenuAbove,
|
2016-07-24 16:45:11 -04:00
|
|
|
data: function(term, callback) {
|
|
|
|
return $.ajax({
|
|
|
|
url: labelUrl
|
|
|
|
}).done(function(data) {
|
|
|
|
data = _.chain(data).groupBy(function(label) {
|
|
|
|
return label.title;
|
|
|
|
}).map(function(label) {
|
|
|
|
var color;
|
|
|
|
color = _.map(label, function(dup) {
|
|
|
|
return dup.color;
|
|
|
|
});
|
|
|
|
return {
|
|
|
|
id: label[0].id,
|
|
|
|
title: label[0].title,
|
|
|
|
color: color,
|
|
|
|
duplicate: color.length > 1
|
|
|
|
};
|
|
|
|
}).value();
|
|
|
|
if ($dropdown.hasClass('js-extra-options')) {
|
2016-08-30 06:21:29 -04:00
|
|
|
var extraData = [];
|
2016-07-24 16:45:11 -04:00
|
|
|
if (showNo) {
|
2016-08-30 06:21:29 -04:00
|
|
|
extraData.unshift({
|
2016-07-24 16:45:11 -04:00
|
|
|
id: 0,
|
|
|
|
title: 'No Label'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (showAny) {
|
2016-08-30 06:21:29 -04:00
|
|
|
extraData.unshift({
|
2016-07-24 16:45:11 -04:00
|
|
|
isAny: true,
|
|
|
|
title: 'Any Label'
|
|
|
|
});
|
|
|
|
}
|
2016-08-30 06:21:29 -04:00
|
|
|
if (extraData.length) {
|
|
|
|
extraData.push('divider');
|
|
|
|
data = extraData.concat(data);
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
|
|
|
}
|
2016-10-04 15:21:06 -04:00
|
|
|
|
|
|
|
callback(data);
|
|
|
|
if (showMenuAbove) {
|
|
|
|
$dropdown.data('glDropdown').positionMenuAbove();
|
|
|
|
}
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
renderRow: function(label, instance) {
|
2016-12-13 16:38:21 -05:00
|
|
|
var $a, $li, color, colorEl, indeterminate, removesAll, selectedClass, spacing, i, marked, dropdownName, dropdownValue;
|
2016-07-24 16:45:11 -04:00
|
|
|
$li = $('<li>');
|
|
|
|
$a = $('<a href="#">');
|
|
|
|
selectedClass = [];
|
2016-08-30 06:21:29 -04:00
|
|
|
removesAll = label.id <= 0 || (label.id == null);
|
2016-07-24 16:45:11 -04:00
|
|
|
if ($dropdown.hasClass('js-filter-bulk-update')) {
|
2016-11-29 02:47:02 -05:00
|
|
|
indeterminate = $dropdown.data('indeterminate') || [];
|
|
|
|
marked = $dropdown.data('marked') || [];
|
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
if (indeterminate.indexOf(label.id) !== -1) {
|
|
|
|
selectedClass.push('is-indeterminate');
|
|
|
|
}
|
2016-11-29 02:47:02 -05:00
|
|
|
|
|
|
|
if (marked.indexOf(label.id) !== -1) {
|
2016-07-26 23:32:10 -04:00
|
|
|
// Remove is-indeterminate class if the item will be marked as active
|
2016-07-24 16:45:11 -04:00
|
|
|
i = selectedClass.indexOf('is-indeterminate');
|
|
|
|
if (i !== -1) {
|
|
|
|
selectedClass.splice(i, 1);
|
|
|
|
}
|
|
|
|
selectedClass.push('is-active');
|
|
|
|
}
|
2016-11-29 02:47:02 -05:00
|
|
|
} else {
|
2016-12-13 16:38:21 -05:00
|
|
|
if (this.id(label)) {
|
|
|
|
dropdownName = $dropdown.data('fieldName');
|
|
|
|
dropdownValue = this.id(label).toString().replace(/'/g, '\\\'');
|
|
|
|
|
|
|
|
if ($form.find("input[type='hidden'][name='" + dropdownName + "'][value='" + dropdownValue + "']").length) {
|
|
|
|
selectedClass.push('is-active');
|
|
|
|
}
|
2016-11-29 02:47:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($dropdown.hasClass('js-multiselect') && removesAll) {
|
|
|
|
selectedClass.push('dropdown-clear-active');
|
|
|
|
}
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
|
|
|
if (label.duplicate) {
|
2017-08-02 05:27:24 -04:00
|
|
|
color = gl.DropdownUtils.duplicateLabelColor(label.color);
|
2016-10-04 10:52:35 -04:00
|
|
|
}
|
|
|
|
else {
|
2016-07-24 16:45:11 -04:00
|
|
|
if (label.color != null) {
|
|
|
|
color = label.color[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (color) {
|
|
|
|
colorEl = "<span class='dropdown-label-box' style='background: " + color + "'></span>";
|
2016-10-04 10:52:35 -04:00
|
|
|
}
|
|
|
|
else {
|
2016-07-24 16:45:11 -04:00
|
|
|
colorEl = '';
|
|
|
|
}
|
2016-07-26 23:32:10 -04:00
|
|
|
// We need to identify which items are actually labels
|
2016-07-24 16:45:11 -04:00
|
|
|
if (label.id) {
|
|
|
|
selectedClass.push('label-item');
|
|
|
|
$a.attr('data-label-id', label.id);
|
|
|
|
}
|
|
|
|
$a.addClass(selectedClass.join(' ')).html(colorEl + " " + label.title);
|
2016-07-26 23:32:10 -04:00
|
|
|
// Return generated html
|
2016-07-24 16:45:11 -04:00
|
|
|
return $li.html($a).prop('outerHTML');
|
|
|
|
},
|
|
|
|
search: {
|
|
|
|
fields: ['title']
|
|
|
|
},
|
|
|
|
selectable: true,
|
|
|
|
filterable: true,
|
2016-08-30 07:10:05 -04:00
|
|
|
selected: $dropdown.data('selected') || [],
|
2016-07-24 16:45:11 -04:00
|
|
|
toggleLabel: function(selected, el) {
|
2016-10-04 10:52:35 -04:00
|
|
|
var isSelected = el !== null ? el.hasClass('is-active') : false;
|
|
|
|
var title = selected.title;
|
|
|
|
var selectedLabels = this.selected;
|
2016-08-30 07:10:05 -04:00
|
|
|
|
2016-10-04 10:52:35 -04:00
|
|
|
if (selected.id === 0) {
|
|
|
|
this.selected = [];
|
|
|
|
return 'No Label';
|
|
|
|
}
|
|
|
|
else if (isSelected) {
|
2016-08-30 07:10:05 -04:00
|
|
|
this.selected.push(title);
|
2016-10-04 10:52:35 -04:00
|
|
|
}
|
|
|
|
else {
|
2016-08-30 07:10:05 -04:00
|
|
|
var index = this.selected.indexOf(title);
|
|
|
|
this.selected.splice(index, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selectedLabels.length === 1) {
|
|
|
|
return selectedLabels;
|
2016-10-04 10:52:35 -04:00
|
|
|
}
|
|
|
|
else if (selectedLabels.length) {
|
2016-08-30 07:10:05 -04:00
|
|
|
return selectedLabels[0] + " +" + (selectedLabels.length - 1) + " more";
|
2016-10-04 10:52:35 -04:00
|
|
|
}
|
|
|
|
else {
|
2016-07-24 16:45:11 -04:00
|
|
|
return defaultLabel;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
fieldName: $dropdown.data('field-name'),
|
|
|
|
id: function(label) {
|
2016-10-18 23:55:26 -04:00
|
|
|
if (label.id <= 0) return label.title;
|
2016-08-30 06:21:29 -04:00
|
|
|
|
|
|
|
if ($dropdown.hasClass('js-issuable-form-dropdown')) {
|
|
|
|
return label.id;
|
|
|
|
}
|
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
if ($dropdown.hasClass("js-filter-submit") && (label.isAny == null)) {
|
|
|
|
return label.title;
|
2016-10-04 10:52:35 -04:00
|
|
|
}
|
|
|
|
else {
|
2016-07-24 16:45:11 -04:00
|
|
|
return label.id;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
hidden: function() {
|
|
|
|
var isIssueIndex, isMRIndex, page, selectedLabels;
|
|
|
|
page = $('body').data('page');
|
|
|
|
isIssueIndex = page === 'projects:issues:index';
|
|
|
|
isMRIndex = page === 'projects:merge_requests:index';
|
|
|
|
$selectbox.hide();
|
2016-07-26 23:32:10 -04:00
|
|
|
// display:block overrides the hide-collapse rule
|
2016-07-24 16:45:11 -04:00
|
|
|
$value.removeAttr('style');
|
2016-08-30 06:21:29 -04:00
|
|
|
|
|
|
|
if ($dropdown.hasClass('js-issuable-form-dropdown')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-12 12:43:20 -04:00
|
|
|
if ($('html').hasClass('issue-boards-page')) {
|
2016-08-05 12:24:16 -04:00
|
|
|
return;
|
|
|
|
}
|
2016-07-24 16:45:11 -04:00
|
|
|
if ($dropdown.hasClass('js-multiselect')) {
|
|
|
|
if ($dropdown.hasClass('js-filter-submit') && (isIssueIndex || isMRIndex)) {
|
|
|
|
selectedLabels = $dropdown.closest('form').find("input:hidden[name='" + ($dropdown.data('fieldName')) + "']");
|
|
|
|
Issuable.filterResults($dropdown.closest('form'));
|
2016-10-04 10:52:35 -04:00
|
|
|
}
|
|
|
|
else if ($dropdown.hasClass('js-filter-submit')) {
|
2016-07-24 16:45:11 -04:00
|
|
|
$dropdown.closest('form').submit();
|
2016-10-04 10:52:35 -04:00
|
|
|
}
|
|
|
|
else {
|
2016-07-24 16:45:11 -04:00
|
|
|
if (!$dropdown.hasClass('js-filter-bulk-update')) {
|
|
|
|
saveLabelData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
multiSelect: $dropdown.hasClass('js-multiselect'),
|
2016-10-06 04:03:10 -04:00
|
|
|
vue: $dropdown.hasClass('js-issue-board-sidebar'),
|
2017-05-04 08:11:15 -04:00
|
|
|
clicked: function(options) {
|
|
|
|
const { $el, e, isMarking } = options;
|
|
|
|
const label = options.selectedObj;
|
|
|
|
|
2017-02-01 12:02:17 -05:00
|
|
|
var isIssueIndex, isMRIndex, page, boardsModel;
|
2017-04-20 07:11:51 -04:00
|
|
|
var fadeOutLoader = () => {
|
|
|
|
$loading.fadeOut();
|
|
|
|
};
|
2016-11-29 02:47:02 -05:00
|
|
|
|
|
|
|
page = $('body').data('page');
|
|
|
|
isIssueIndex = page === 'projects:issues:index';
|
|
|
|
isMRIndex = page === 'projects:merge_requests:index';
|
2016-08-30 06:21:29 -04:00
|
|
|
|
|
|
|
if ($dropdown.parent().find('.is-active:not(.dropdown-clear-active)').length) {
|
|
|
|
$dropdown.parent()
|
|
|
|
.find('.dropdown-clear-active')
|
2017-01-10 17:54:56 -05:00
|
|
|
.removeClass('is-active');
|
2016-08-30 06:21:29 -04:00
|
|
|
}
|
|
|
|
|
2017-01-16 16:56:53 -05:00
|
|
|
if ($dropdown.hasClass('js-issuable-form-dropdown')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($dropdown.hasClass('js-filter-bulk-update')) {
|
2016-11-29 02:47:02 -05:00
|
|
|
_this.enableBulkLabelDropdown();
|
2017-05-04 08:11:15 -04:00
|
|
|
_this.setDropdownData($dropdown, isMarking, label.id);
|
2016-07-24 16:45:11 -04:00
|
|
|
return;
|
|
|
|
}
|
2016-08-30 06:21:29 -04:00
|
|
|
|
2017-03-08 09:53:18 -05:00
|
|
|
if ($dropdown.closest('.add-issues-modal').length) {
|
2017-02-01 12:02:17 -05:00
|
|
|
boardsModel = gl.issueBoards.ModalStore.store.filter;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (boardsModel) {
|
2016-08-08 04:24:29 -04:00
|
|
|
if (label.isAny) {
|
2017-02-01 12:02:17 -05:00
|
|
|
boardsModel['label_name'] = [];
|
2017-03-08 09:53:18 -05:00
|
|
|
} else if ($el.hasClass('is-active')) {
|
2017-02-01 12:02:17 -05:00
|
|
|
boardsModel['label_name'].push(label.title);
|
2016-10-04 10:52:35 -04:00
|
|
|
}
|
2016-08-05 13:27:12 -04:00
|
|
|
|
2016-08-05 12:24:16 -04:00
|
|
|
e.preventDefault();
|
2016-08-05 10:42:27 -04:00
|
|
|
return;
|
2016-10-04 10:52:35 -04:00
|
|
|
}
|
|
|
|
else if ($dropdown.hasClass('js-filter-submit') && (isIssueIndex || isMRIndex)) {
|
2016-07-24 16:45:11 -04:00
|
|
|
if (!$dropdown.hasClass('js-multiselect')) {
|
|
|
|
selectedLabel = label.title;
|
|
|
|
return Issuable.filterResults($dropdown.closest('form'));
|
|
|
|
}
|
2016-10-04 10:52:35 -04:00
|
|
|
}
|
|
|
|
else if ($dropdown.hasClass('js-filter-submit')) {
|
2016-07-24 16:45:11 -04:00
|
|
|
return $dropdown.closest('form').submit();
|
2016-10-04 10:52:35 -04:00
|
|
|
}
|
2016-10-06 04:03:10 -04:00
|
|
|
else if ($dropdown.hasClass('js-issue-board-sidebar')) {
|
2016-10-05 07:20:59 -04:00
|
|
|
if ($el.hasClass('is-active')) {
|
|
|
|
gl.issueBoards.BoardsStore.detail.issue.labels.push(new ListLabel({
|
|
|
|
id: label.id,
|
|
|
|
title: label.title,
|
|
|
|
color: label.color[0],
|
|
|
|
textColor: '#fff'
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var labels = gl.issueBoards.BoardsStore.detail.issue.labels;
|
|
|
|
labels = labels.filter(function (selectedLabel) {
|
|
|
|
return selectedLabel.id !== label.id;
|
|
|
|
});
|
|
|
|
gl.issueBoards.BoardsStore.detail.issue.labels = labels;
|
|
|
|
}
|
|
|
|
|
|
|
|
$loading.fadeIn();
|
|
|
|
|
2016-10-20 03:54:33 -04:00
|
|
|
gl.issueBoards.BoardsStore.detail.issue.update($dropdown.attr('data-issue-update'))
|
2017-04-20 07:11:51 -04:00
|
|
|
.then(fadeOutLoader)
|
|
|
|
.catch(fadeOutLoader);
|
2016-10-05 07:20:59 -04:00
|
|
|
}
|
2016-10-04 10:52:35 -04:00
|
|
|
else {
|
2016-07-24 16:45:11 -04:00
|
|
|
if ($dropdown.hasClass('js-multiselect')) {
|
|
|
|
|
2016-10-04 10:52:35 -04:00
|
|
|
}
|
|
|
|
else {
|
2016-07-24 16:45:11 -04:00
|
|
|
return saveLabelData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
2016-11-29 02:47:02 -05:00
|
|
|
|
|
|
|
// Set dropdown data
|
|
|
|
_this.setOriginalDropdownData($dropdownContainer, $dropdown);
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
|
|
|
this.bindEvents();
|
|
|
|
}
|
|
|
|
|
|
|
|
LabelsSelect.prototype.bindEvents = function() {
|
|
|
|
return $('body').on('change', '.selected_issue', this.onSelectCheckboxIssue);
|
|
|
|
};
|
|
|
|
|
|
|
|
LabelsSelect.prototype.onSelectCheckboxIssue = function() {
|
|
|
|
if ($('.selected_issue:checked').length) {
|
|
|
|
return;
|
|
|
|
}
|
2017-05-15 18:12:43 -04:00
|
|
|
return $('.issues-bulk-update .labels-filter .dropdown-toggle-text').text('Label');
|
2016-07-24 16:45:11 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
LabelsSelect.prototype.enableBulkLabelDropdown = function() {
|
2017-05-15 18:12:43 -04:00
|
|
|
IssuableBulkUpdateActions.willUpdateLabels = true;
|
2016-07-24 16:45:11 -04:00
|
|
|
};
|
|
|
|
|
2016-11-29 02:47:02 -05:00
|
|
|
LabelsSelect.prototype.setDropdownData = function($dropdown, isMarking, value) {
|
2016-12-13 16:38:21 -05:00
|
|
|
var i, markedIds, unmarkedIds, indeterminateIds;
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2016-11-29 02:47:02 -05:00
|
|
|
markedIds = $dropdown.data('marked') || [];
|
|
|
|
unmarkedIds = $dropdown.data('unmarked') || [];
|
|
|
|
indeterminateIds = $dropdown.data('indeterminate') || [];
|
|
|
|
|
|
|
|
if (isMarking) {
|
|
|
|
markedIds.push(value);
|
|
|
|
|
|
|
|
i = indeterminateIds.indexOf(value);
|
|
|
|
if (i > -1) {
|
|
|
|
indeterminateIds.splice(i, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
i = unmarkedIds.indexOf(value);
|
|
|
|
if (i > -1) {
|
|
|
|
unmarkedIds.splice(i, 1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// If marked item (not common) is unmarked
|
|
|
|
i = markedIds.indexOf(value);
|
|
|
|
if (i > -1) {
|
|
|
|
markedIds.splice(i, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If an indeterminate item is being unmarked
|
2017-05-15 18:12:43 -04:00
|
|
|
if (IssuableBulkUpdateActions.getOriginalIndeterminateIds().indexOf(value) > -1) {
|
2016-11-29 02:47:02 -05:00
|
|
|
unmarkedIds.push(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If a marked item is being unmarked
|
|
|
|
// (a marked item could also be a label that is present in all selection)
|
2017-05-15 18:12:43 -04:00
|
|
|
if (IssuableBulkUpdateActions.getOriginalCommonIds().indexOf(value) > -1) {
|
2016-11-29 02:47:02 -05:00
|
|
|
unmarkedIds.push(value);
|
|
|
|
}
|
|
|
|
}
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2016-11-29 02:47:02 -05:00
|
|
|
$dropdown.data('marked', markedIds);
|
|
|
|
$dropdown.data('unmarked', unmarkedIds);
|
|
|
|
$dropdown.data('indeterminate', indeterminateIds);
|
|
|
|
};
|
|
|
|
|
|
|
|
LabelsSelect.prototype.setOriginalDropdownData = function($container, $dropdown) {
|
|
|
|
var labels = [];
|
2016-12-13 16:38:21 -05:00
|
|
|
$container.find('[name="label_name[]"]').map(function() {
|
|
|
|
return labels.push(this.value);
|
|
|
|
});
|
2016-11-29 02:47:02 -05:00
|
|
|
$dropdown.data('marked', labels);
|
|
|
|
};
|
|
|
|
|
|
|
|
return LabelsSelect;
|
2016-07-24 16:45:11 -04:00
|
|
|
})();
|
2017-02-10 01:50:50 -05:00
|
|
|
}).call(window);
|