summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/boards/components/modal/footer.vue
blob: 268ca6bca131052210a51443475aa4c771dcc51d (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<script>
import Flash from '../../../flash';
import { __ } from '../../../locale';
import ListsDropdown from './lists_dropdown.vue';
import { pluralize } from '../../../lib/utils/text_utility';
import ModalStore from '../../stores/modal_store';
import modalMixin from '../../mixins/modal_mixins';
import boardsStore from '../../stores/boards_store';

export default {
  components: {
    ListsDropdown,
  },
  mixins: [modalMixin],
  data() {
    return {
      modal: ModalStore.store,
      state: boardsStore.state,
    };
  },
  computed: {
    submitDisabled() {
      return !ModalStore.selectedCount();
    },
    submitText() {
      const count = ModalStore.selectedCount();

      return `Add ${count > 0 ? count : ''} ${pluralize('issue', count)}`;
    },
  },
  methods: {
    buildUpdateRequest(list) {
      return {
        add_label_ids: [list.label.id],
      };
    },
    addIssues() {
      const firstListIndex = 1;
      const list = this.modal.selectedList || this.state.lists[firstListIndex];
      const selectedIssues = ModalStore.getSelectedIssues();
      const issueIds = selectedIssues.map(issue => issue.id);
      const req = this.buildUpdateRequest(list);

      // Post the data to the backend
      gl.boardService
        .bulkUpdate(issueIds, req)
        .catch(() => {
          Flash(__('Failed to update issues, please try again.'));

          selectedIssues.forEach((issue) => {
            list.removeIssue(issue);
            list.issuesSize -= 1;
          });
        });

      // Add the issues on the frontend
      selectedIssues.forEach((issue) => {
        list.addIssue(issue);
        list.issuesSize += 1;
      });

      this.toggleModal(false);
    },
  },
};
</script>
<template>
  <footer
    class="form-actions add-issues-footer"
  >
    <div class="float-left">
      <button
        :disabled="submitDisabled"
        class="btn btn-success"
        type="button"
        @click="addIssues"
      >
        {{ submitText }}
      </button>
      <span class="inline add-issues-footer-to-list">
        to list
      </span>
      <lists-dropdown/>
    </div>
    <button
      class="btn btn-default float-right"
      type="button"
      @click="toggleModal(false)"
    >
      Cancel
    </button>
  </footer>
</template>