summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/repo/repo_edit_button.js
blob: 07ae93d7f001d1f47c7b6b741b26215424b2ea02 (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
import Vue from 'vue';
import Store from './repo_store';
import RepoMixin from './repo_mixin'

export default class RepoEditButton {
  constructor(el) {
    this.initVue(el);
  }

  initVue(el) {
    this.vue = new Vue({
      el,
      mixins: [RepoMixin],
      data: () => Store,
      computed: {
        buttonLabel() {
          return this.editMode ? 'Cancel edit' : 'Edit';
        },

        buttonIcon() {
          return this.editMode ? [] : ['fa', 'fa-pencil'];
        },
      },
      methods: {
        editClicked() {
          console.log('thiscf', this.changedFiles)
          if(this.changedFiles.length) {
            this.dialog.open = true;
            return;
          }
          this.editMode = !this.editMode;
        },
      },

      watch: {
        dialog: {
          handler(obj) {
            if(obj.status) {
              obj.status = false;
            }
          },
          deep: true,
        }
      }
    });
  }
}