gitlab-org--gitlab-foss/app/assets/javascripts/boards/components/new_list_dropdown.js

81 lines
2.2 KiB
JavaScript
Raw Normal View History

/* eslint-disable func-names, no-new, space-before-function-paren, one-var,
promise/catch-or-return */
2018-02-08 11:48:02 +00:00
import axios from '~/lib/utils/axios_utils';
import _ from 'underscore';
import CreateLabelDropdown from '../../create_label';
2017-04-10 23:52:46 +00:00
window.gl = window.gl || {};
window.gl.issueBoards = window.gl.issueBoards || {};
2017-04-10 23:52:46 +00:00
const Store = gl.issueBoards.BoardsStore;
2017-04-10 23:52:46 +00:00
$(document).off('created.label').on('created.label', (e, label) => {
Store.new({
title: label.title,
position: Store.state.lists.length - 2,
list_type: 'label',
label: {
id: label.id,
title: label.title,
color: label.color,
},
});
2017-04-10 23:52:46 +00:00
});
2017-04-10 23:52:46 +00:00
gl.issueBoards.newListDropdownInit = () => {
$('.js-new-board-list').each(function () {
const $this = $(this);
new CreateLabelDropdown($this.closest('.dropdown').find('.dropdown-new-label'), $this.data('namespace-path'), $this.data('project-path'));
2017-04-10 23:52:46 +00:00
$this.glDropdown({
data(term, callback) {
2018-02-08 11:48:02 +00:00
axios.get($this.attr('data-list-labels-path'))
.then(({ data }) => {
callback(data);
2017-01-12 03:49:57 +00:00
});
2017-04-10 23:52:46 +00:00
},
renderRow (label) {
const active = Store.findList('title', label.title);
const $li = $('<li />');
const $a = $('<a />', {
class: (active ? `is-active js-board-list-${active.id}` : ''),
text: label.title,
href: '#',
2017-04-10 23:52:46 +00:00
});
const $labelColor = $('<span />', {
class: 'dropdown-label-box',
style: `background-color: ${label.color}`,
2017-04-10 23:52:46 +00:00
});
2016-08-01 13:18:30 +00:00
2017-04-10 23:52:46 +00:00
return $li.append($a.prepend($labelColor));
},
search: {
fields: ['title'],
2017-04-10 23:52:46 +00:00
},
filterable: true,
selectable: true,
multiSelect: true,
clicked (options) {
const { e } = options;
const label = options.selectedObj;
2017-04-10 23:52:46 +00:00
e.preventDefault();
2017-04-10 23:52:46 +00:00
if (!Store.findList('title', label.title)) {
Store.new({
title: label.title,
position: Store.state.lists.length - 2,
list_type: 'label',
label: {
id: label.id,
title: label.title,
color: label.color,
},
2017-04-10 23:52:46 +00:00
});
2016-11-09 09:23:48 +00:00
2017-04-10 23:52:46 +00:00
Store.state.lists = _.sortBy(Store.state.lists, 'position');
}
},
2016-08-01 13:18:30 +00:00
});
2017-04-10 23:52:46 +00:00
});
};