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

145 lines
3.3 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';
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';
2017-08-17 22:00:37 +05:30
const Store = gl.issueBoards.BoardsStore;
export default {
name: 'BoardNewIssue',
2018-03-27 19:54:05 +05:30
components: {
ProjectSelect,
},
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();
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();
Store.detail.issue = issue;
Store.detail.list = this.list;
})
.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-08 19:23:39 +05:30
class="label-light"
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-11-08 19:23:39 +05:30
ref="input"
v-model="title"
:id="list.id + '-title'"
2018-03-27 19:54:05 +05:30
class="form-control"
2017-08-17 22:00:37 +05:30
type="text"
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-03-27 19:54:05 +05:30
<button
ref="submit-button"
2018-11-08 19:23:39 +05:30
:disabled="disabled"
class="btn btn-success float-left"
type="submit"
2018-03-27 19:54:05 +05:30
>
2017-08-17 22:00:37 +05:30
Submit issue
</button>
2018-03-27 19:54:05 +05:30
<button
2018-11-08 19:23:39 +05:30
class="btn btn-default float-right"
2017-08-17 22:00:37 +05:30
type="button"
2018-03-27 19:54:05 +05:30
@click="cancel"
>
2017-08-17 22:00:37 +05:30
Cancel
</button>
</div>
</form>
</div>
2018-03-27 19:54:05 +05:30
</div>
</template>