2018-02-14 21:36:30 +09:00
|
|
|
<template>
|
2019-05-21 03:45:07 +09:00
|
|
|
<div class="zmdxowus">
|
2018-02-14 21:36:30 +09:00
|
|
|
<p class="caution" v-if="choices.length < 2">
|
2018-11-09 03:44:35 +09:00
|
|
|
<fa icon="exclamation-triangle"/>{{ $t('no-only-one-choice') }}
|
2018-02-14 21:36:30 +09:00
|
|
|
</p>
|
|
|
|
<ul ref="choices">
|
2018-02-22 05:57:24 +09:00
|
|
|
<li v-for="(choice, i) in choices">
|
2018-11-09 22:11:11 +09:00
|
|
|
<input :value="choice" @input="onInput(i, $event)" :placeholder="$t('choice-n').replace('{}', i + 1)">
|
2018-11-09 03:44:35 +09:00
|
|
|
<button @click="remove(i)" :title="$t('remove')">
|
2018-11-06 01:40:11 +09:00
|
|
|
<fa icon="times"/>
|
2018-02-14 21:36:30 +09:00
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
</ul>
|
2018-11-09 03:44:35 +09:00
|
|
|
<button class="add" v-if="choices.length < 10" @click="add">{{ $t('add') }}</button>
|
2019-03-06 22:55:47 +09:00
|
|
|
<button class="add" v-else disabled>{{ $t('no-more') }}</button>
|
2018-11-09 03:44:35 +09:00
|
|
|
<button class="destroy" @click="destroy" :title="$t('destroy')">
|
2018-11-06 01:40:11 +09:00
|
|
|
<fa icon="times"/>
|
2018-02-14 21:36:30 +09:00
|
|
|
</button>
|
2019-03-06 22:55:47 +09:00
|
|
|
<section>
|
|
|
|
<ui-switch v-model="multiple">{{ $t('multiple') }}</ui-switch>
|
|
|
|
<div>
|
|
|
|
<ui-select v-model="expiration">
|
|
|
|
<template #label>{{ $t('expiration') }}</template>
|
|
|
|
<option value="infinite">{{ $t('infinite') }}</option>
|
|
|
|
<option value="at">{{ $t('at') }}</option>
|
|
|
|
<option value="after">{{ $t('after') }}</option>
|
|
|
|
</ui-select>
|
|
|
|
<section v-if="expiration === 'at'">
|
2019-07-18 20:56:48 +09:00
|
|
|
<ui-input v-model="atDate" type="date">
|
|
|
|
<template #title>{{ $t('deadline-date') }}</template>
|
|
|
|
</ui-input>
|
|
|
|
<ui-input v-model="atTime" type="time">
|
|
|
|
<template #title>{{ $t('deadline-time') }}</template>
|
|
|
|
</ui-input>
|
2019-03-06 22:55:47 +09:00
|
|
|
</section>
|
|
|
|
<section v-if="expiration === 'after'">
|
2019-07-18 20:56:48 +09:00
|
|
|
<ui-input v-model="after" type="number">
|
|
|
|
<template #title>{{ $t('interval') }}</template>
|
|
|
|
</ui-input>
|
2019-03-06 22:55:47 +09:00
|
|
|
<ui-select v-model="unit">
|
2019-07-18 20:56:48 +09:00
|
|
|
<template #title>{{ $t('unit') }}</template>
|
2019-03-06 22:55:47 +09:00
|
|
|
<option value="second">{{ $t('second') }}</option>
|
|
|
|
<option value="minute">{{ $t('minute') }}</option>
|
|
|
|
<option value="hour">{{ $t('hour') }}</option>
|
|
|
|
<option value="day">{{ $t('day') }}</option>
|
|
|
|
</ui-select>
|
|
|
|
</section>
|
|
|
|
</div>
|
|
|
|
</section>
|
2018-02-14 21:36:30 +09:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
2019-03-06 22:55:47 +09:00
|
|
|
import * as moment from 'moment';
|
2018-11-09 03:44:35 +09:00
|
|
|
import i18n from '../../../i18n';
|
2018-09-07 00:02:55 +09:00
|
|
|
import { erase } from '../../../../../prelude/array';
|
2018-02-14 21:36:30 +09:00
|
|
|
export default Vue.extend({
|
2018-11-09 03:44:35 +09:00
|
|
|
i18n: i18n('common/views/components/poll-editor.vue'),
|
2018-02-14 21:36:30 +09:00
|
|
|
data() {
|
|
|
|
return {
|
2019-03-06 22:55:47 +09:00
|
|
|
choices: ['', ''],
|
|
|
|
multiple: false,
|
|
|
|
expiration: 'infinite',
|
|
|
|
atDate: moment().add(1, 'day').toISOString().split('T')[0],
|
|
|
|
atTime: '00:00',
|
|
|
|
after: 0,
|
|
|
|
unit: 'second'
|
2018-02-14 21:36:30 +09:00
|
|
|
};
|
|
|
|
},
|
2018-02-22 05:57:24 +09:00
|
|
|
watch: {
|
|
|
|
choices() {
|
|
|
|
this.$emit('updated');
|
|
|
|
}
|
|
|
|
},
|
2018-02-14 21:36:30 +09:00
|
|
|
methods: {
|
|
|
|
onInput(i, e) {
|
2018-02-21 01:23:25 +09:00
|
|
|
Vue.set(this.choices, i, e.target.value);
|
2018-02-14 21:36:30 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
add() {
|
|
|
|
this.choices.push('');
|
2018-02-22 05:57:24 +09:00
|
|
|
this.$nextTick(() => {
|
|
|
|
(this.$refs.choices as any).childNodes[this.choices.length - 1].childNodes[0].focus();
|
|
|
|
});
|
2018-02-14 21:36:30 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
remove(i) {
|
|
|
|
this.choices = this.choices.filter((_, _i) => _i != i);
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy() {
|
|
|
|
this.$emit('destroyed');
|
|
|
|
},
|
|
|
|
|
|
|
|
get() {
|
2019-03-06 22:55:47 +09:00
|
|
|
const at = () => {
|
2019-06-18 15:42:08 +09:00
|
|
|
return moment(`${this.atDate} ${this.atTime}`).valueOf();
|
2019-03-06 22:55:47 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
const after = () => {
|
|
|
|
let base = parseInt(this.after);
|
|
|
|
switch (this.unit) {
|
|
|
|
case 'day': base *= 24;
|
|
|
|
case 'hour': base *= 60;
|
|
|
|
case 'minute': base *= 60;
|
|
|
|
case 'second': return base *= 1000;
|
|
|
|
default: return null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-02-14 21:36:30 +09:00
|
|
|
return {
|
2019-03-06 22:55:47 +09:00
|
|
|
choices: erase('', this.choices),
|
|
|
|
multiple: this.multiple,
|
|
|
|
...(
|
|
|
|
this.expiration === 'at' ? { expiresAt: at() } :
|
|
|
|
this.expiration === 'after' ? { expiredAfter: after() } : {})
|
|
|
|
};
|
2018-02-14 21:36:30 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
set(data) {
|
|
|
|
if (data.choices.length == 0) return;
|
|
|
|
this.choices = data.choices;
|
2018-02-22 05:57:24 +09:00
|
|
|
if (data.choices.length == 1) this.choices = this.choices.concat('');
|
2019-03-06 22:55:47 +09:00
|
|
|
this.multiple = data.multiple;
|
|
|
|
if (data.expiresAt) {
|
|
|
|
this.expiration = 'at';
|
|
|
|
this.atDate = this.atTime = data.expiresAt;
|
|
|
|
} else if (typeof data.expiredAfter === 'number') {
|
|
|
|
this.expiration = 'after';
|
|
|
|
this.after = data.expiredAfter;
|
|
|
|
} else {
|
|
|
|
this.expiration = 'infinite';
|
|
|
|
}
|
2018-02-14 21:36:30 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" scoped>
|
2019-05-21 03:45:07 +09:00
|
|
|
.zmdxowus
|
2018-02-14 21:36:30 +09:00
|
|
|
padding 8px
|
|
|
|
|
|
|
|
> .caution
|
|
|
|
margin 0 0 8px 0
|
|
|
|
font-size 0.8em
|
|
|
|
color #f00
|
|
|
|
|
2018-11-06 01:40:11 +09:00
|
|
|
> [data-icon]
|
2018-02-14 21:36:30 +09:00
|
|
|
margin-right 4px
|
|
|
|
|
|
|
|
> ul
|
|
|
|
display block
|
|
|
|
margin 0
|
|
|
|
padding 0
|
|
|
|
list-style none
|
|
|
|
|
|
|
|
> li
|
|
|
|
display block
|
|
|
|
margin 8px 0
|
|
|
|
padding 0
|
|
|
|
width 100%
|
|
|
|
|
|
|
|
&:first-child
|
|
|
|
margin-top 0
|
|
|
|
|
|
|
|
&:last-child
|
|
|
|
margin-bottom 0
|
|
|
|
|
|
|
|
> input
|
2018-02-25 03:05:29 +09:00
|
|
|
padding 6px 8px
|
|
|
|
width 300px
|
|
|
|
font-size 14px
|
2018-09-27 22:50:34 +09:00
|
|
|
color var(--inputText)
|
2018-09-28 12:10:15 +09:00
|
|
|
background var(--pollEditorInputBg)
|
2018-09-26 20:19:35 +09:00
|
|
|
border solid 1px var(--primaryAlpha01)
|
2018-02-14 21:36:30 +09:00
|
|
|
border-radius 4px
|
|
|
|
|
|
|
|
&:hover
|
2018-09-26 20:19:35 +09:00
|
|
|
border-color var(--primaryAlpha02)
|
2018-02-14 21:36:30 +09:00
|
|
|
|
|
|
|
&:focus
|
2018-09-26 20:19:35 +09:00
|
|
|
border-color var(--primaryAlpha05)
|
2018-02-14 21:36:30 +09:00
|
|
|
|
|
|
|
> button
|
|
|
|
padding 4px 8px
|
2018-09-26 20:19:35 +09:00
|
|
|
color var(--primaryAlpha04)
|
2018-02-14 21:36:30 +09:00
|
|
|
|
|
|
|
&:hover
|
2018-09-26 20:19:35 +09:00
|
|
|
color var(--primaryAlpha06)
|
2018-02-14 21:36:30 +09:00
|
|
|
|
|
|
|
&:active
|
2018-09-26 20:19:35 +09:00
|
|
|
color var(--primaryDarken30)
|
2018-02-14 21:36:30 +09:00
|
|
|
|
|
|
|
> .add
|
|
|
|
margin 8px 0 0 0
|
|
|
|
vertical-align top
|
2018-09-26 20:19:35 +09:00
|
|
|
color var(--primary)
|
2019-03-06 22:55:47 +09:00
|
|
|
z-index 1
|
2018-02-14 21:36:30 +09:00
|
|
|
|
|
|
|
> .destroy
|
|
|
|
position absolute
|
|
|
|
top 0
|
|
|
|
right 0
|
|
|
|
padding 4px 8px
|
2018-09-26 20:19:35 +09:00
|
|
|
color var(--primaryAlpha04)
|
2018-02-14 21:36:30 +09:00
|
|
|
|
|
|
|
&:hover
|
2018-09-26 20:19:35 +09:00
|
|
|
color var(--primaryAlpha06)
|
2018-02-14 21:36:30 +09:00
|
|
|
|
|
|
|
&:active
|
2018-09-26 20:19:35 +09:00
|
|
|
color var(--primaryDarken30)
|
2018-02-14 21:36:30 +09:00
|
|
|
|
2019-03-06 22:55:47 +09:00
|
|
|
> section
|
|
|
|
margin 16px 0 -16px 0
|
|
|
|
|
|
|
|
> div
|
|
|
|
margin 0 8px
|
|
|
|
|
|
|
|
&:last-child
|
|
|
|
flex 1 0 auto
|
|
|
|
|
|
|
|
> section
|
|
|
|
align-items center
|
|
|
|
display flex
|
|
|
|
margin -32px 0 0
|
|
|
|
|
|
|
|
> :first-child
|
|
|
|
margin-right 16px
|
|
|
|
|
|
|
|
> .ui-input
|
|
|
|
flex 1 0 auto
|
2018-02-14 21:36:30 +09:00
|
|
|
</style>
|