diff options
author | Phil Hughes <me@iamphill.com> | 2016-10-03 11:10:20 +0300 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2016-10-03 11:10:20 +0300 |
commit | cc88fa4d5be9ec0d5fb42f1bb5efa0b82f30a589 (patch) | |
tree | 1b9facaf15466aa7f5b0393e97cb1eabfdcafa7e /app/assets/javascripts/labels_select.js | |
parent | 69db604e55de2bdf1a28c274be6cc9131534517d (diff) | |
parent | f2c0f8237124d2dc539120bd77f301f216453cb7 (diff) |
Merge branch 'master' into revert-c676283b
Diffstat (limited to 'app/assets/javascripts/labels_select.js')
-rw-r--r-- | app/assets/javascripts/labels_select.js | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/app/assets/javascripts/labels_select.js b/app/assets/javascripts/labels_select.js index 9d40a303a8f..2324c166a79 100644 --- a/app/assets/javascripts/labels_select.js +++ b/app/assets/javascripts/labels_select.js @@ -4,7 +4,7 @@ var _this; _this = this; $('.js-label-select').each(function(i, dropdown) { - var $block, $colorPreview, $dropdown, $form, $loading, $selectbox, $sidebarCollapsedValue, $value, abilityName, defaultLabel, enableLabelCreateButton, issueURLSplit, issueUpdateURL, labelHTMLTemplate, labelNoneHTMLTemplate, labelUrl, projectId, saveLabelData, selectedLabel, showAny, showNo, $sidebarLabelTooltip, $toggleText, fieldName, useId, propertyName; + var $block, $colorPreview, $dropdown, $form, $loading, $selectbox, $sidebarCollapsedValue, $value, abilityName, defaultLabel, enableLabelCreateButton, issueURLSplit, issueUpdateURL, labelHTMLTemplate, labelNoneHTMLTemplate, labelUrl, projectId, saveLabelData, selectedLabel, showAny, showNo, $sidebarLabelTooltip, initialSelected, $toggleText, fieldName, useId, propertyName; $dropdown = $(dropdown); $toggleText = $dropdown.find('.dropdown-toggle-text'); projectId = $dropdown.data('project-id'); @@ -28,7 +28,11 @@ fieldName = $dropdown.data('field-name'); useId = $dropdown.is('.js-issuable-form-dropdown, .js-filter-bulk-update, .js-label-sidebar-dropdown'); propertyName = useId ? 'id' : 'title'; - + initialSelected = $selectbox + .find('input[name="' + $dropdown.data('field-name') + '"]') + .map(function () { + return this.value; + }).get(); if (issueUpdateURL != null) { issueURLSplit = issueUpdateURL.split('/'); } @@ -48,6 +52,10 @@ selected = $dropdown.closest('.selectbox').find("input[name='" + fieldName + "']").map(function() { return this.value; }).get(); + + if (_.isEqual(initialSelected, selected)) return; + initialSelected = selected; + data = {}; data[abilityName] = {}; data[abilityName].label_ids = selected; @@ -163,15 +171,17 @@ selectedClass.push('is-indeterminate'); } if (active.indexOf(label.id) !== -1) { + // Remove is-indeterminate class if the item will be marked as active i = selectedClass.indexOf('is-indeterminate'); if (i !== -1) { selectedClass.splice(i, 1); } selectedClass.push('is-active'); + // Add input manually instance.addInput(this.fieldName, label.id); } } - if ($form.find("input[type='hidden'][name='" + ($dropdown.data('fieldName')) + "'][value='" + escape(this.id(label)) + "']").length) { + if (this.id(label) && $form.find("input[type='hidden'][name='" + ($dropdown.data('fieldName')) + "'][value='" + this.id(label).toString().replace(/'/g, '\\\'') + "']").length) { selectedClass.push('is-active'); } if ($dropdown.hasClass('js-multiselect') && removesAll) { @@ -179,6 +189,7 @@ } if (label.duplicate) { spacing = 100 / label.color.length; + // Reduce the colors to 4 label.color = label.color.filter(function(color, i) { return i < 4; }); @@ -199,11 +210,13 @@ } else { colorEl = ''; } + // We need to identify which items are actually labels if (label.id) { selectedClass.push('label-item'); $a.attr('data-label-id', label.id); } $a.addClass(selectedClass.join(' ')).html(colorEl + " " + label.title); + // Return generated html return $li.html($a).prop('outerHTML'); }, persistWhenHide: $dropdown.data('persistWhenHide'), @@ -254,6 +267,7 @@ isIssueIndex = page === 'projects:issues:index'; isMRIndex = page === 'projects:merge_requests:index'; $selectbox.hide(); + // display:block overrides the hide-collapse rule $value.removeAttr('style'); if ($dropdown.hasClass('js-issuable-form-dropdown')) { @@ -276,6 +290,7 @@ } } if ($dropdown.hasClass('js-filter-bulk-update')) { + // If we are persisting state we need the classes if (!this.options.persistWhenHide) { return $dropdown.parent().find('.is-active, .is-indeterminate').removeClass(); } @@ -302,12 +317,12 @@ if (page === 'projects:boards:show') { if (label.isAny) { gl.issueBoards.BoardsStore.state.filters['label_name'] = []; - } else if (label.title) { + } else if ($el.hasClass('is-active')) { gl.issueBoards.BoardsStore.state.filters['label_name'].push(label.title); } else { var filters = gl.issueBoards.BoardsStore.state.filters['label_name']; - filters = filters.filter(function (label) { - return label !== $el.text().trim(); + filters = filters.filter(function (filteredLabel) { + return filteredLabel !== label.title; }); gl.issueBoards.BoardsStore.state.filters['label_name'] = filters; } @@ -353,7 +368,9 @@ if ($('.selected_issue:checked').length) { return; } + // Remove inputs $('.issues_bulk_update .labels-filter input[type="hidden"]').remove(); + // Also restore button text return $('.issues_bulk_update .labels-filter .dropdown-toggle-text').text('Label'); }; |