summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/repo/components/repo_edit_button.vue
blob: 353142edeb70260691467dcb41fcc0e131891407 (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
<script>
import Store from '../stores/repo_store';
import RepoMixin from '../mixins/repo_mixin';

export default {
  data: () => Store,
  mixins: [RepoMixin],
  computed: {
    buttonLabel() {
      return this.editMode ? this.__('Cancel edit') : this.__('Edit');
    },

    showButton() {
      return this.isCommitable &&
        !this.activeFile.render_error &&
        !this.binary &&
        this.openedFiles.length;
    },
  },
  methods: {
    editCancelClicked() {
      if (this.changedFiles.length) {
        this.dialog.open = true;
        return;
      }
      this.editMode = !this.editMode;
      Store.toggleBlobView();
    },
  },
};
</script>

<template>
<button
  v-if="showButton"
  class="btn btn-default"
  type="button"
  @click.prevent="editCancelClicked">
  <i
    v-if="!editMode"
    class="fa fa-pencil"
    aria-hidden="true">
  </i>
  <span>
    {{buttonLabel}}
  </span>
</button>
</template>