-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreatePoll.vue
195 lines (192 loc) · 5.7 KB
/
CreatePoll.vue
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<template>
<v-expansion-panels popout>
<v-expansion-panel>
<v-expansion-panel-header
:expand-icon="expanded ? 'mdi-close' : 'mdi-arrow-expand-down'"
@click="toggleExpand"
>
<h1>{{ title }}</h1>
</v-expansion-panel-header>
<v-expansion-panel-content>
<v-form>
<v-container>
<!-- Title/Question -->
<v-row>
<v-text-field
@keydown.enter="focusAddOptions"
v-model="question"
label="Title/Question"
outlined
></v-text-field>
</v-row>
<!-- Created options -->
<v-row v-for="(opt, i) in options" :key="i">
<v-text-field
v-model="options[i]"
:label="'Option ' + (i + 1)"
append-outer-icon="mdi-close"
@click:append-outer="removeOption(i)"
outlined
></v-text-field>
</v-row>
<v-row>
<!-- Create new option -->
<v-text-field
ref="addOptionTextField"
v-model="tempOpt"
outlined
clearable
label="Add option"
:append-outer-icon="'mdi-plus-thick'"
:clear-icon="'mdi-close-circle'"
@click:append-outer="addOption"
@keydown.enter="addOption"
@click:clear="clearTemp"
></v-text-field>
</v-row>
<v-row>
<!-- Time picker -->
<v-col cols="11" sm="5">
<v-dialog
ref="timeDialog"
v-model="timePicker"
:return-value.sync="time"
persistent
width="290px"
>
<template v-slot:activator="{ on, attrs }">
<v-text-field
v-model="time"
label="Select time"
prepend-icon="mdi-clock-time-four-outline"
readonly
v-bind="attrs"
v-on="on"
></v-text-field>
</template>
<v-time-picker
ampm-in-title
v-if="timePicker"
v-model="time"
full-width
>
<v-spacer></v-spacer>
<v-btn text color="primary" @click="timePicker = false">
Cancel
</v-btn>
<v-btn
text
color="primary"
@click="$refs.timeDialog.save(time)"
>
OK
</v-btn>
</v-time-picker>
</v-dialog>
</v-col>
<v-spacer />
<!-- Date picker -->
<v-col cols="11" sm="5">
<v-dialog
ref="dateDialog"
v-model="datePicker"
:return-value.sync="date"
persistent
width="290px"
>
<template v-slot:activator="{ on, attrs }">
<v-text-field
v-model="date"
label="Select Date"
prepend-icon="mdi-calendar"
readonly
v-bind="attrs"
v-on="on"
></v-text-field>
</template>
<v-date-picker
:min="new Date().toISOString().substr(0, 10)"
v-model="date"
scrollable
>
<v-spacer></v-spacer>
<v-btn text color="primary" @click="datePicker = false">
Cancel
</v-btn>
<v-btn
text
color="primary"
@click="$refs.dateDialog.save(date)"
>
OK
</v-btn>
</v-date-picker>
</v-dialog>
</v-col>
</v-row>
</v-container>
</v-form>
</v-expansion-panel-content>
</v-expansion-panel>
<v-snackbar timeout="3000" v-model="snackbar">
Please type in something.
<template v-slot:action="{ attrs }">
<v-btn color="warning" text v-bind="attrs" @click="snackbar = false">
Got it
</v-btn>
</template>
</v-snackbar>
</v-expansion-panels>
</template>
<script>
export default {
props: {
pollDetails: Object,
title: String,
},
data() {
return {
question: "",
options: [],
tempOpt: "",
snackbar: false,
time: null,
timePicker: false,
date: new Date().toISOString().substr(0, 10),
datePicker: false,
expanded: false,
};
},
methods: {
toggleExpand() {
this.expanded = !this.expanded;
},
clearTemp() {
this.tempOpt = "";
},
addOption(e) {
if (this.tempOpt) {
this.options.push(this.tempOpt);
this.clearTemp();
} else {
this.snackbar = true;
}
},
removeOption(idx) {
this.options.splice(idx, 1);
},
focusAddOptions() {
this.$refs.addOptionTextField.focus();
},
},
beforeMount() {
if (this.pollDetails) {
this.question = this.pollDetails.question;
this.options = this.pollDetails.options;
this.time = this.pollDetails.time;
this.date = this.pollDetails.date;
}
},
};
</script>
<style></style>