summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/ide/components/new_dropdown/modal.vue
blob: 1e9668d51544fa97acda29d355ac33711d512954 (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
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
83
84
85
86
87
88
89
90
<script>
import { __ } from '~/locale';
import DeprecatedModal from '~/vue_shared/components/deprecated_modal.vue';

export default {
  components: {
    DeprecatedModal,
  },
  props: {
    branchId: {
      type: String,
      required: true,
    },
    type: {
      type: String,
      required: true,
    },
    path: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      entryName: this.path !== '' ? `${this.path}/` : '',
    };
  },
  computed: {
    modalTitle() {
      if (this.type === 'tree') {
        return __('Create new directory');
      }

      return __('Create new file');
    },
    buttonLabel() {
      if (this.type === 'tree') {
        return __('Create directory');
      }

      return __('Create file');
    },
  },
  mounted() {
    this.$refs.fieldName.focus();
  },
  methods: {
    createEntryInStore() {
      this.$emit('create', {
        branchId: this.branchId,
        name: this.entryName,
        type: this.type,
      });

      this.hideModal();
    },
    hideModal() {
      this.$emit('hide');
    },
  },
};
</script>

<template>
  <deprecated-modal
    :title="modalTitle"
    :primary-button-label="buttonLabel"
    kind="success"
    @cancel="hideModal"
    @submit="createEntryInStore"
  >
    <form
      slot="body"
      class="form-group row"
      @submit.prevent="createEntryInStore"
    >
      <label class="label-light col-form-label col-sm-3">
        {{ __('Name') }}
      </label>
      <div class="col-sm-9">
        <input
          ref="fieldName"
          v-model="entryName"
          type="text"
          class="form-control"
        />
      </div>
    </form>
  </deprecated-modal>
</template>