BigW Consortium Gitlab

footer.js 2.05 KB
Newer Older
1 2
/* eslint-disable no-new */
/* global Flash */
3

4
import Vue from 'vue';
5
import './lists_dropdown';
6

7
const ModalStore = gl.issueBoards.ModalStore;
8

9 10 11 12 13 14 15 16 17 18 19
gl.issueBoards.ModalFooter = Vue.extend({
  mixins: [gl.issueBoards.ModalMixins],
  data() {
    return {
      modal: ModalStore.store,
      state: gl.issueBoards.BoardsStore.state,
    };
  },
  computed: {
    submitDisabled() {
      return !ModalStore.selectedCount();
20
    },
21 22
    submitText() {
      const count = ModalStore.selectedCount();
23

24
      return `Add ${count > 0 ? count : ''} ${gl.text.pluralize('issue', count)}`;
25
    },
26 27 28
  },
  methods: {
    addIssues() {
Phil Hughes committed
29 30
      const firstListIndex = 1;
      const list = this.modal.selectedList || this.state.lists[firstListIndex];
31 32
      const selectedIssues = ModalStore.getSelectedIssues();
      const issueIds = selectedIssues.map(issue => issue.globalId);
33

34 35 36 37 38
      // Post the data to the backend
      gl.boardService.bulkUpdate(issueIds, {
        add_label_ids: [list.label.id],
      }).catch(() => {
        new Flash('Failed to update issues, please try again.', 'alert');
39

Phil Hughes committed
40
        selectedIssues.forEach((issue) => {
41 42
          list.removeIssue(issue);
          list.issuesSize -= 1;
43
        });
44
      });
45

46 47 48 49 50 51 52
      // Add the issues on the frontend
      selectedIssues.forEach((issue) => {
        list.addIssue(issue);
        list.issuesSize += 1;
      });

      this.toggleModal(false);
53
    },
54 55 56 57 58 59 60 61
  },
  components: {
    'lists-dropdown': gl.issueBoards.ModalFooterListsDropdown,
  },
  template: `
    <footer
      class="form-actions add-issues-footer">
      <div class="pull-left">
62
        <button
63
          class="btn btn-success"
64
          type="button"
65 66 67
          :disabled="submitDisabled"
          @click="addIssues">
          {{ submitText }}
68
        </button>
69 70 71 72 73 74 75 76 77 78 79 80 81 82
        <span class="inline add-issues-footer-to-list">
          to list
        </span>
        <lists-dropdown></lists-dropdown>
      </div>
      <button
        class="btn btn-default pull-right"
        type="button"
        @click="toggleModal(false)">
        Cancel
      </button>
    </footer>
  `,
});