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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
<!--
- @copyright Copyright (c) 2018 René Gieling <github@dartcafe.de>
-
- @author René Gieling <github@dartcafe.de>
-
- @license GNU AGPL version 3 or any later version
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-->
<template lang="html">
<div class="create-dialog">
<ConfigBox :title="t('polls', 'Title')" icon-class="icon-sound">
<input id="pollTitle"
ref="pollTitle"
v-model="title"
type="text"
:placeholder="t('polls', 'Enter Title')"
@keyup.enter="confirm">
</ConfigBox>
<ConfigBox :title="t('polls', 'Poll type')" icon-class="icon-checkmark">
<RadioGroupDiv v-model="pollType" :options="pollTypeOptions" />
</ConfigBox>
<div class="create-buttons">
<button class="button" @click="cancel">
{{ t('polls', 'Cancel') }}
</button>
<button :disabled="titleEmpty" class="button primary" @click="confirm">
{{ t('polls', 'Apply') }}
</button>
</div>
</div>
</template>
<script>
import { mapState } from 'vuex'
import { showSuccess, showError } from '@nextcloud/dialogs'
import { emit } from '@nextcloud/event-bus'
import ConfigBox from '../Base/ConfigBox'
import RadioGroupDiv from '../Base/RadioGroupDiv'
export default {
name: 'CreateDlg',
components: {
ConfigBox,
RadioGroupDiv,
},
data() {
return {
id: 0,
pollType: 'datePoll',
title: '',
pollTypeOptions: [
{ value: 'datePoll', label: t('polls', 'Date poll') },
{ value: 'textPoll', label: t('polls', 'Text poll') },
],
}
},
computed: {
...mapState({
poll: (state) => state.poll,
}),
titleEmpty() {
return this.title === ''
},
},
methods: {
cancel() {
this.title = ''
this.pollType = 'datePoll'
this.$emit('close-create')
},
async confirm() {
try {
const response = await this.$store.dispatch('poll/add', { title: this.title, type: this.pollType })
emit('update-polls')
this.cancel()
showSuccess(t('polls', 'Poll "{pollTitle}" added', { pollTitle: response.data.title }))
this.$router.push({ name: 'vote', params: { id: response.data.id } })
} catch {
showError(t('polls', 'Error while creating Poll "{pollTitle}"', { pollTitle: this.title }))
}
},
setFocus() {
this.$nextTick(() => {
this.$refs.pollTitle.focus()
})
},
},
}
</script>
<style lang="css" scoped>
.create-dialog {
background-color: var(--color-main-background);
padding: 8px 20px;
}
.create-buttons {
display: flex;
justify-content: space-between;
}
</style>
|