debian-mirror-gitlab/app/assets/javascripts/ide/components/new_dropdown/modal.vue

101 lines
2.4 KiB
Vue
Raw Normal View History

2018-05-09 12:01:36 +05:30
<script>
import { __ } from '~/locale';
2018-11-18 11:00:15 +05:30
import { mapActions, mapState } from 'vuex';
import GlModal from '~/vue_shared/components/gl_modal.vue';
import { modalTypes } from '../../constants';
2018-05-09 12:01:36 +05:30
export default {
components: {
2018-11-18 11:00:15 +05:30
GlModal,
2018-05-09 12:01:36 +05:30
},
data() {
return {
2018-11-18 11:00:15 +05:30
name: '',
2018-05-09 12:01:36 +05:30
};
},
computed: {
2018-11-18 11:00:15 +05:30
...mapState(['entryModal']),
entryName: {
get() {
if (this.entryModal.type === modalTypes.rename) {
return this.name || this.entryModal.entry.name;
}
return this.name || (this.entryModal.path !== '' ? `${this.entryModal.path}/` : '');
},
set(val) {
this.name = val;
},
},
2018-05-09 12:01:36 +05:30
modalTitle() {
2018-11-18 11:00:15 +05:30
if (this.entryModal.type === modalTypes.tree) {
2018-05-09 12:01:36 +05:30
return __('Create new directory');
2018-11-18 11:00:15 +05:30
} else if (this.entryModal.type === modalTypes.rename) {
return this.entryModal.entry.type === modalTypes.tree ? __('Rename folder') : __('Rename file');
2018-05-09 12:01:36 +05:30
}
return __('Create new file');
},
buttonLabel() {
2018-11-18 11:00:15 +05:30
if (this.entryModal.type === modalTypes.tree) {
2018-05-09 12:01:36 +05:30
return __('Create directory');
2018-11-18 11:00:15 +05:30
} else if (this.entryModal.type === modalTypes.rename) {
return this.entryModal.entry.type === modalTypes.tree ? __('Rename folder') : __('Rename file');
2018-05-09 12:01:36 +05:30
}
return __('Create file');
},
},
methods: {
2018-11-18 11:00:15 +05:30
...mapActions(['createTempEntry', 'renameEntry']),
submitForm() {
if (this.entryModal.type === modalTypes.rename) {
this.renameEntry({
path: this.entryModal.entry.path,
name: this.entryName,
});
} else {
this.createTempEntry({
name: this.name,
type: this.entryModal.type,
});
}
},
focusInput() {
this.$refs.fieldName.focus();
2018-05-09 12:01:36 +05:30
},
2018-11-18 11:00:15 +05:30
closedModal() {
this.name = '';
2018-05-09 12:01:36 +05:30
},
},
};
</script>
<template>
2018-11-18 11:00:15 +05:30
<gl-modal
id="ide-new-entry"
:header-title-text="modalTitle"
:footer-primary-button-text="buttonLabel"
footer-primary-button-variant="success"
@submit="submitForm"
@open="focusInput"
@closed="closedModal"
2018-05-09 12:01:36 +05:30
>
2018-11-18 11:00:15 +05:30
<div
2018-11-08 19:23:39 +05:30
class="form-group row"
2018-05-09 12:01:36 +05:30
>
2018-11-18 11:00:15 +05:30
<label class="label-bold col-form-label col-sm-3">
2018-11-08 19:23:39 +05:30
{{ __('Name') }}
</label>
<div class="col-sm-9">
<input
ref="fieldName"
v-model="entryName"
type="text"
class="form-control"
/>
</div>
2018-11-18 11:00:15 +05:30
</div>
</gl-modal>
2018-05-09 12:01:36 +05:30
</template>