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

79 lines
2.3 KiB
JavaScript
Raw Normal View History

2018-06-16 13:20:30 +00:00
/* eslint-disable func-names, no-new, promise/catch-or-return */
import $ from 'jquery';
2018-02-08 11:48:02 +00:00
import axios from '~/lib/utils/axios_utils';
import _ from 'underscore';
import CreateLabelDropdown from '../../create_label';
import boardsStore from '../stores/boards_store';
2017-04-10 23:52:46 +00:00
$(document).off('created.label').on('created.label', (e, label) => {
boardsStore.new({
2017-04-10 23:52:46 +00:00
title: label.title,
position: boardsStore.state.lists.length - 2,
2017-04-10 23:52:46 +00:00
list_type: 'label',
label: {
id: label.id,
title: label.title,
color: label.color,
},
});
2017-04-10 23:52:46 +00:00
});
export default function initNewListDropdown() {
2017-04-10 23:52:46 +00:00
$('.js-new-board-list').each(function () {
const $this = $(this);
2018-02-20 22:20:48 +00:00
new CreateLabelDropdown($this.closest('.dropdown').find('.dropdown-new-label'), $this.data('namespacePath'), $this.data('projectPath'));
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 = boardsStore.findList('title', label.title);
2017-04-10 23:52:46 +00:00
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,
containerSelector: '.js-tab-container-labels .dropdown-page-one .dropdown-content',
clicked (options) {
const { e } = options;
const label = options.selectedObj;
2017-04-10 23:52:46 +00:00
e.preventDefault();
if (!boardsStore.findList('title', label.title)) {
boardsStore.new({
2017-04-10 23:52:46 +00:00
title: label.title,
position: boardsStore.state.lists.length - 2,
2017-04-10 23:52:46 +00:00
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
boardsStore.state.lists = _.sortBy(boardsStore.state.lists, 'position');
}
},
2016-08-01 13:18:30 +00:00
});
2017-04-10 23:52:46 +00:00
});
}