debian-mirror-gitlab/app/assets/javascripts/boards/components/board_new_issue.vue

150 lines
3.5 KiB
Vue
Raw Normal View History

2018-03-27 19:54:05 +05:30
<script>
2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2018-12-13 13:39:08 +05:30
import { GlButton } from '@gitlab-org/gitlab-ui';
2017-08-17 22:00:37 +05:30
import eventHub from '../eventhub';
2018-03-27 19:54:05 +05:30
import ProjectSelect from './project_select.vue';
import ListIssue from '../models/issue';
2018-12-13 13:39:08 +05:30
import boardsStore from '../stores/boards_store';
2017-08-17 22:00:37 +05:30
export default {
name: 'BoardNewIssue',
2018-03-27 19:54:05 +05:30
components: {
ProjectSelect,
2018-12-13 13:39:08 +05:30
GlButton,
2018-03-27 19:54:05 +05:30
},
2017-08-17 22:00:37 +05:30
props: {
2018-03-27 19:54:05 +05:30
groupId: {
type: Number,
required: false,
default: 0,
},
2018-03-17 18:26:18 +05:30
list: {
type: Object,
required: true,
},
2017-08-17 22:00:37 +05:30
},
data() {
return {
title: '',
error: false,
2018-03-27 19:54:05 +05:30
selectedProject: {},
2017-08-17 22:00:37 +05:30
};
},
2018-03-27 19:54:05 +05:30
computed: {
disabled() {
if (this.groupId) {
return this.title === '' || !this.selectedProject.name;
}
return this.title === '';
},
},
mounted() {
this.$refs.input.focus();
eventHub.$on('setSelectedProject', this.setSelectedProject);
},
2017-08-17 22:00:37 +05:30
methods: {
submit(e) {
e.preventDefault();
2017-09-10 17:25:29 +05:30
if (this.title.trim() === '') return Promise.resolve();
2017-08-17 22:00:37 +05:30
this.error = false;
const labels = this.list.label ? [this.list.label] : [];
2018-11-08 19:23:39 +05:30
const assignees = this.list.assignee ? [this.list.assignee] : [];
2017-08-17 22:00:37 +05:30
const issue = new ListIssue({
title: this.title,
labels,
subscribed: true,
2018-11-08 19:23:39 +05:30
assignees,
2018-03-27 19:54:05 +05:30
project_id: this.selectedProject.id,
2017-08-17 22:00:37 +05:30
});
2017-09-10 17:25:29 +05:30
eventHub.$emit(`scroll-board-list-${this.list.id}`);
this.cancel();
2018-12-13 13:39:08 +05:30
return this.list
.newIssue(issue)
2017-08-17 22:00:37 +05:30
.then(() => {
// Need this because our jQuery very kindly disables buttons on ALL form submissions
$(this.$refs.submitButton).enable();
2018-12-13 13:39:08 +05:30
boardsStore.detail.issue = issue;
boardsStore.detail.list = this.list;
2017-08-17 22:00:37 +05:30
})
.catch(() => {
// Need this because our jQuery very kindly disables buttons on ALL form submissions
$(this.$refs.submitButton).enable();
// Remove the issue
this.list.removeIssue(issue);
// Show error message
this.error = true;
});
},
cancel() {
this.title = '';
eventHub.$emit(`hide-issue-form-${this.list.id}`);
},
2018-03-27 19:54:05 +05:30
setSelectedProject(selectedProject) {
this.selectedProject = selectedProject;
},
2017-08-17 22:00:37 +05:30
},
2018-03-27 19:54:05 +05:30
};
</script>
<template>
<div class="board-new-issue-form">
2018-11-08 19:23:39 +05:30
<div class="board-card">
2017-08-17 22:00:37 +05:30
<form @submit="submit($event)">
2018-03-27 19:54:05 +05:30
<div
v-if="error"
2018-11-08 19:23:39 +05:30
class="flash-container"
2018-03-27 19:54:05 +05:30
>
2017-08-17 22:00:37 +05:30
<div class="flash-alert">
2018-03-17 18:26:18 +05:30
An error occurred. Please try again.
2017-08-17 22:00:37 +05:30
</div>
</div>
2018-03-27 19:54:05 +05:30
<label
:for="list.id + '-title'"
2018-11-18 11:00:15 +05:30
class="label-bold"
2018-03-27 19:54:05 +05:30
>
2017-08-17 22:00:37 +05:30
Title
</label>
2018-03-27 19:54:05 +05:30
<input
2018-12-05 23:21:45 +05:30
:id="list.id + '-title'"
2018-11-08 19:23:39 +05:30
ref="input"
v-model="title"
2018-03-27 19:54:05 +05:30
class="form-control"
2017-08-17 22:00:37 +05:30
type="text"
2018-11-18 11:00:15 +05:30
name="issue_title"
2017-09-10 17:25:29 +05:30
autocomplete="off"
2018-03-27 19:54:05 +05:30
/>
<project-select
v-if="groupId"
:group-id="groupId"
/>
2017-08-17 22:00:37 +05:30
<div class="clearfix prepend-top-10">
2018-12-05 23:21:45 +05:30
<gl-button
2018-03-27 19:54:05 +05:30
ref="submit-button"
2018-11-08 19:23:39 +05:30
:disabled="disabled"
2018-12-05 23:21:45 +05:30
class="float-left"
variant="success"
2018-11-08 19:23:39 +05:30
type="submit"
2018-03-27 19:54:05 +05:30
>
2017-08-17 22:00:37 +05:30
Submit issue
2018-12-05 23:21:45 +05:30
</gl-button>
<gl-button
class="float-right"
2017-08-17 22:00:37 +05:30
type="button"
2018-12-05 23:21:45 +05:30
variant="default"
2018-03-27 19:54:05 +05:30
@click="cancel"
>
2017-08-17 22:00:37 +05:30
Cancel
2018-12-05 23:21:45 +05:30
</gl-button>
2017-08-17 22:00:37 +05:30
</div>
</form>
</div>
2018-03-27 19:54:05 +05:30
</div>
</template>