issue_note_form.vue 2.2 KB
Newer Older
1 2 3 4 5 6 7
<script>
import MarkdownField from '../../vue_shared/components/markdown/field.vue';

export default {
  props: {
    noteBody: {
      type: String,
8 9
      required: false,
      default: '',
10 11 12 13 14 15 16 17 18
    },
    updateHandler: {
      type: Function,
      required: true,
    },
    cancelHandler: {
      type: Function,
      required: true,
    },
19 20 21 22
    saveButtonTitle: {
      type: String,
      required: false,
      default: 'Save comment',
23
    },
24 25 26 27 28 29
  },
  data() {
    return {
      note: this.noteBody,
      markdownPreviewUrl: '',
      markdownDocsUrl: '',
30
    };
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
  },
  components: {
    MarkdownField,
  },
  methods: {
    handleUpdate() {
      this.updateHandler({
        note: this.note,
      });
    },
  },
  mounted() {
    const issuableDataEl = document.getElementById('js-issuable-app-initial-data');
    const issueData = JSON.parse(issuableDataEl.innerHTML.replace(/&quot;/g, '"'));
    const { markdownDocs, markdownPreviewUrl } = issueData;

    this.markdownDocsUrl = markdownDocs;
    this.markdownPreviewUrl = markdownPreviewUrl;
49
    this.$refs.textarea.focus();
50 51 52 53 54 55 56 57 58 59 60 61 62 63
  },
};
</script>

<template>
  <div class="note-edit-form">
    <form class="edit-note common-note-form">
      <markdown-field
        :markdown-preview-url="markdownPreviewUrl"
        :markdown-docs="markdownDocsUrl"
        :addSpacingClasses="false">
        <textarea
          id="note-body"
          class="note-textarea js-gfm-input js-autosize markdown-area"
64 65
          data-supports-slash-commands="true"
          data-supports-quick-actions="true"
66 67 68 69 70 71 72 73 74 75 76 77 78
          aria-label="Description"
          v-model="note"
          ref="textarea"
          slot="textarea"
          placeholder="Write a comment or drag your files here..."
          @keydown.meta.enter="handleUpdate">
        </textarea>
      </markdown-field>
      <div class="note-form-actions clearfix">
        <button
          @click="handleUpdate"
          type="button"
          class="btn btn-nr btn-save">
79
          {{saveButtonTitle}}
80 81 82 83 84 85 86 87 88 89 90
        </button>
        <button
          @click="cancelHandler"
          class="btn btn-nr btn-cancel"
          type="button">
          Cancel
        </button>
      </div>
    </form>
  </div>
</template>