debian-mirror-gitlab/app/assets/javascripts/issue_show/components/form.vue

155 lines
3.6 KiB
Vue
Raw Normal View History

2017-09-10 17:25:29 +05:30
<script>
2019-07-31 22:56:46 +05:30
import $ from 'jquery';
2018-12-13 13:39:08 +05:30
import lockedWarning from './locked_warning.vue';
import titleField from './fields/title.vue';
import descriptionField from './fields/description.vue';
import editActions from './edit_actions.vue';
import descriptionTemplate from './fields/description_template.vue';
2019-07-31 22:56:46 +05:30
import Autosave from '~/autosave';
import eventHub from '../event_hub';
2017-09-10 17:25:29 +05:30
2018-12-13 13:39:08 +05:30
export default {
components: {
lockedWarning,
titleField,
descriptionField,
descriptionTemplate,
editActions,
},
props: {
canDestroy: {
type: Boolean,
required: true,
2018-03-17 18:26:18 +05:30
},
2018-12-13 13:39:08 +05:30
formState: {
type: Object,
required: true,
2017-09-10 17:25:29 +05:30
},
2018-12-13 13:39:08 +05:30
issuableTemplates: {
type: Array,
required: false,
default: () => [],
2017-09-10 17:25:29 +05:30
},
2018-12-13 13:39:08 +05:30
issuableType: {
type: String,
required: true,
},
markdownPreviewPath: {
type: String,
required: true,
},
markdownDocsPath: {
type: String,
required: true,
},
projectPath: {
type: String,
required: true,
},
projectNamespace: {
type: String,
required: true,
},
showDeleteButton: {
type: Boolean,
required: false,
default: true,
},
canAttachFile: {
type: Boolean,
required: false,
default: true,
},
enableAutocomplete: {
type: Boolean,
required: false,
default: true,
},
},
computed: {
hasIssuableTemplates() {
return this.issuableTemplates.length;
},
},
2019-07-31 22:56:46 +05:30
created() {
eventHub.$on('delete.issuable', this.resetAutosave);
eventHub.$on('update.issuable', this.resetAutosave);
eventHub.$on('close.form', this.resetAutosave);
},
mounted() {
this.initAutosave();
},
beforeDestroy() {
eventHub.$off('delete.issuable', this.resetAutosave);
eventHub.$off('update.issuable', this.resetAutosave);
eventHub.$off('close.form', this.resetAutosave);
},
methods: {
initAutosave() {
const {
description: {
$refs: { textarea },
},
title: {
$refs: { input },
},
} = this.$refs;
this.autosaveDescription = new Autosave($(textarea), [
document.location.pathname,
document.location.search,
'description',
]);
this.autosaveTitle = new Autosave($(input), [
document.location.pathname,
document.location.search,
'title',
]);
},
resetAutosave() {
this.autosaveDescription.reset();
this.autosaveTitle.reset();
},
},
2018-12-13 13:39:08 +05:30
};
2017-09-10 17:25:29 +05:30
</script>
<template>
<form>
<locked-warning v-if="formState.lockedWarningVisible" />
<div class="row">
2019-02-15 15:39:39 +05:30
<div v-if="hasIssuableTemplates" class="col-sm-4 col-lg-3">
2017-09-10 17:25:29 +05:30
<description-template
:form-state="formState"
:issuable-templates="issuableTemplates"
:project-path="projectPath"
2018-03-17 18:26:18 +05:30
:project-namespace="projectNamespace"
/>
2017-09-10 17:25:29 +05:30
</div>
<div
:class="{
'col-sm-8 col-lg-9': hasIssuableTemplates,
2018-11-08 19:23:39 +05:30
'col-12': !hasIssuableTemplates,
2018-03-17 18:26:18 +05:30
}"
>
2019-07-31 22:56:46 +05:30
<title-field ref="title" :form-state="formState" :issuable-templates="issuableTemplates" />
2017-09-10 17:25:29 +05:30
</div>
</div>
<description-field
2019-07-31 22:56:46 +05:30
ref="description"
2017-09-10 17:25:29 +05:30
:form-state="formState"
2018-03-17 18:26:18 +05:30
:markdown-preview-path="markdownPreviewPath"
:markdown-docs-path="markdownDocsPath"
:can-attach-file="canAttachFile"
:enable-autocomplete="enableAutocomplete"
/>
2017-09-10 17:25:29 +05:30
<edit-actions
:form-state="formState"
2018-03-17 18:26:18 +05:30
:can-destroy="canDestroy"
:show-delete-button="showDeleteButton"
2018-12-05 23:21:45 +05:30
:issuable-type="issuableType"
2018-03-17 18:26:18 +05:30
/>
2017-09-10 17:25:29 +05:30
</form>
</template>