summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/diffs/components/edit_button.vue
blob: 2fb85ca2f0714aa525f9a05b9a4c5956bf9a17db (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
<script>
export default {
  props: {
    editPath: {
      type: String,
      required: true,
    },
    canCurrentUserFork: {
      type: Boolean,
      required: true,
    },
    canModifyBlob: {
      type: Boolean,
      required: false,
      default: false,
    },
  },
  methods: {
    handleEditClick(evt) {
      if (!this.canCurrentUserFork || this.canModifyBlob) {
        // if we can Edit, do default Edit button behavior
        return;
      }

      if (this.canCurrentUserFork) {
        evt.preventDefault();
        this.$emit('showForkMessage');
      }
    },
  },
};
</script>

<template>
  <a
    :href="editPath"
    class="btn btn-default js-edit-blob"
    @click="handleEditClick"
  >
    Edit
  </a>
</template>