issue_note_form.vue 2.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
<script>
import MarkdownField from '../../vue_shared/components/markdown/field.vue';

export default {
  props: {
    noteBody: {
      type: String,
      required: true,
    },
    updateHandler: {
      type: Function,
      required: true,
    },
    cancelHandler: {
      type: Function,
      required: true,
    },
  },
  data() {
    return {
      note: this.noteBody,
      markdownPreviewUrl: '',
      markdownDocsUrl: '',
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
  },
  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;
  },
};
</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"
          data-supports-slash-commands="false"
          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">
          Save comment
        </button>
        <button
          @click="cancelHandler"
          class="btn btn-nr btn-cancel"
          type="button">
          Cancel
        </button>
      </div>
    </form>
  </div>
</template>