board_new_issue.vue 2.5 KB
Newer Older
1
<script>
2
import eventHub from '../eventhub';
3
import ListIssue from '../models/issue';
4

5 6 7 8 9
const Store = gl.issueBoards.BoardsStore;

export default {
  name: 'BoardNewIssue',
  props: {
10 11 12 13
    list: {
      type: Object,
      required: true,
    },
14 15 16 17 18 19 20
  },
  data() {
    return {
      title: '',
      error: false,
    };
  },
21 22 23
  mounted() {
    this.$refs.input.focus();
  },
24 25 26
  methods: {
    submit(e) {
      e.preventDefault();
27
      if (this.title.trim() === '') return Promise.resolve();
28 29 30 31 32 33 34 35

      this.error = false;

      const labels = this.list.label ? [this.list.label] : [];
      const issue = new ListIssue({
        title: this.title,
        labels,
        subscribed: true,
36
        assignees: [],
37 38
      });

39 40 41 42
      eventHub.$emit(`scroll-board-list-${this.list.id}`);
      this.cancel();

      return this.list.newIssue(issue)
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
        .then(() => {
          // Need this because our jQuery very kindly disables buttons on ALL form submissions
          $(this.$refs.submitButton).enable();

          Store.detail.issue = issue;
          Store.detail.list = this.list;
        })
        .catch(() => {
          // Need this because our jQuery very kindly disables buttons on ALL form submissions
          $(this.$refs.submitButton).enable();

          // Remove the issue
          this.list.removeIssue(issue);

          // Show error message
          this.error = true;
        });
    },
    cancel() {
      this.title = '';
63
      eventHub.$emit(`hide-issue-form-${this.list.id}`);
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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
</script>

<template>
  <div class="card board-new-issue-form">
    <form @submit="submit($event)">
      <div
        class="flash-container"
        v-if="error"
      >
        <div class="flash-alert">
          An error occurred. Please try again.
        </div>
      </div>
      <label
        class="label-light"
        :for="list.id + '-title'"
      >
        Title
      </label>
      <input
        class="form-control"
        type="text"
        v-model="title"
        ref="input"
        autocomplete="off"
        :id="list.id + '-title'"
      />
      <div class="clearfix prepend-top-10">
        <button
          class="btn btn-success pull-left"
          type="submit"
          :disabled="title === ''"
          ref="submit-button"
        >
          Submit issue
        </button>
        <button
          class="btn btn-default pull-right"
          type="button"
          @click="cancel"
        >
          Cancel
        </button>
      </div>
    </form>
  </div>
</template>