summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/boards/components/new_list_dropdown.js.es6
blob: 64e081a462fe97cdd72d23ddb253d67a970c1de0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
$(() => {
  $('.js-new-board-list').each(function () {
    const $this = $(this);

    $this.glDropdown({
      data: function(term, callback) {
        $.ajax({
          url: $this.attr('data-labels')
        }).then((resp) => {
          callback(resp);
        });
      },
      renderRow: (label) => {
        const $li = $('<li />'),
              $a = $('<a />', {
                text: label.title,
                href: '#'
              }),
              $labelColor = $('<span />', {
                class: 'dropdown-label-box',
                style: `background-color: ${label.color}`
              });

        return $li.append($a.prepend($labelColor));
      },
      selectable: true,
      clicked: (label, $el, e) => {
        e.preventDefault();
        BoardsStore.new({
          id: BoardsStore.state.lists.length - 1,
          title: label.title,
          index: BoardsStore.state.lists.length - 1,
          label: {
            title: label.title,
            backgroundColor: label.color,
            color: '#fff'
          },
          issues: []
        });
      }
    });
  });
});