Sharkey/src/client/app/common/views/components/dialog.vue

270 lines
5.5 KiB
Vue
Raw Normal View History

2018-11-14 09:30:58 +02:00
<template>
2018-11-14 17:01:49 +02:00
<div class="felqjxyj" :class="{ splash }">
2018-11-14 09:30:58 +02:00
<div class="bg" ref="bg" @click="onBgClick"></div>
<div class="main" ref="main">
2019-02-25 13:08:56 +02:00
<template v-if="type == 'signin'">
<mk-signin/>
</template>
<template v-else>
2019-04-18 13:40:23 +03:00
<div class="icon" v-if="icon">
<fa :icon="icon"/>
</div>
<div class="icon" v-else-if="!input && !select && !user" :class="type">
<fa icon="check" v-if="type === 'success'"/>
<fa :icon="faTimesCircle" v-if="type === 'error'"/>
<fa icon="exclamation-triangle" v-if="type === 'warning'"/>
<fa icon="info-circle" v-if="type === 'info'"/>
<fa :icon="faQuestionCircle" v-if="type === 'question'"/>
<fa icon="spinner" pulse v-if="type === 'waiting'"/>
</div>
2019-02-25 13:08:56 +02:00
<header v-if="title" v-html="title"></header>
<div class="body" v-if="text" v-html="text"></div>
<ui-input v-if="input" v-model="inputValue" autofocus :type="input.type || 'text'" :placeholder="input.placeholder" @keydown="onInputKeydown"></ui-input>
<ui-input v-if="user" v-model="userInputValue" autofocus @keydown="onInputKeydown"><template #prefix>@</template></ui-input>
2019-02-25 13:18:15 +02:00
<ui-select v-if="select" v-model="selectedValue" autofocus>
<template v-if="select.items">
<option v-for="item in select.items" :value="item.value">{{ item.text }}</option>
</template>
<template v-else>
<optgroup v-for="groupedItem in select.groupedItems" :label="groupedItem.label">
<option v-for="item in groupedItem.items" :value="item.value">{{ item.text }}</option>
</optgroup>
</template>
2019-02-25 13:08:56 +02:00
</ui-select>
2019-04-18 13:40:23 +03:00
<ui-horizon-group no-grow class="buttons fit-bottom" v-if="!splash && (showOkButton || showCancelButton)">
<ui-button @click="ok" v-if="showOkButton" primary :autofocus="!input && !select && !user">{{ (showCancelButton || input || select || user) ? $t('@.ok') : $t('@.got-it') }}</ui-button>
2019-02-25 13:08:56 +02:00
<ui-button @click="cancel" v-if="showCancelButton || input || select || user">{{ $t('@.cancel') }}</ui-button>
</ui-horizon-group>
</template>
2018-11-14 09:30:58 +02:00
</div>
</div>
</template>
<script lang="ts">
import Vue from 'vue';
2019-01-18 06:06:11 +02:00
import anime from 'animejs';
2018-11-14 09:30:58 +02:00
import { faTimesCircle, faQuestionCircle } from '@fortawesome/free-regular-svg-icons';
2018-12-02 13:10:53 +02:00
import parseAcct from "../../../../../misc/acct/parse";
2019-02-25 13:08:56 +02:00
import i18n from '../../../i18n';
2018-11-14 09:30:58 +02:00
export default Vue.extend({
2019-02-25 13:08:56 +02:00
i18n: i18n(),
2018-11-14 09:30:58 +02:00
props: {
type: {
type: String,
required: false,
default: 'info'
},
title: {
type: String,
required: false
},
text: {
type: String,
2018-11-14 17:01:49 +02:00
required: false
2018-11-14 09:30:58 +02:00
},
2018-12-02 13:10:53 +02:00
input: {
required: false
},
2018-12-02 08:26:56 +02:00
select: {
required: false
},
2018-12-02 13:10:53 +02:00
user: {
required: false
},
2019-04-18 13:40:23 +03:00
icon: {
required: false
},
showOkButton: {
type: Boolean,
default: true
},
2018-11-14 09:30:58 +02:00
showCancelButton: {
type: Boolean,
default: false
},
2019-04-18 13:40:23 +03:00
cancelableByBgClick: {
type: Boolean,
default: true
},
2018-11-14 17:01:49 +02:00
splash: {
2018-11-14 09:30:58 +02:00
type: Boolean,
2018-11-14 17:01:49 +02:00
default: false
2018-11-14 09:30:58 +02:00
}
},
2018-12-02 08:26:56 +02:00
data() {
return {
2018-12-02 13:10:53 +02:00
inputValue: this.input && this.input.default ? this.input.default : null,
userInputValue: null,
2019-04-18 13:40:23 +03:00
selectedValue: null,
faTimesCircle, faQuestionCircle
2018-12-02 08:26:56 +02:00
};
},
2018-11-14 09:30:58 +02:00
mounted() {
this.$nextTick(() => {
(this.$refs.bg as any).style.pointerEvents = 'auto';
anime({
targets: this.$refs.bg,
opacity: 1,
duration: 100,
easing: 'linear'
});
anime({
targets: this.$refs.main,
opacity: 1,
scale: [1.2, 1],
duration: 300,
2019-01-18 06:06:11 +02:00
easing: 'cubicBezier(0, 0.5, 0.5, 1)'
2018-11-14 09:30:58 +02:00
});
2018-11-14 17:01:49 +02:00
if (this.splash) {
setTimeout(() => {
this.close();
}, 1000);
}
2018-11-14 09:30:58 +02:00
});
},
methods: {
2018-12-02 13:10:53 +02:00
async ok() {
2019-04-18 13:40:23 +03:00
if (!this.showOkButton) return;
2018-12-02 13:10:53 +02:00
if (this.user) {
const user = await this.$root.api('users/show', parseAcct(this.userInputValue));
if (user) {
this.$emit('ok', user);
this.close();
}
} else {
const result =
this.input ? this.inputValue :
this.select ? this.selectedValue :
true;
this.$emit('ok', result);
this.close();
}
2018-11-14 09:30:58 +02:00
},
cancel() {
this.$emit('cancel');
this.close();
},
close() {
2019-02-20 22:53:10 +02:00
this.$el.style.pointerEvents = 'none';
2018-11-14 09:30:58 +02:00
(this.$refs.bg as any).style.pointerEvents = 'none';
2019-02-20 22:53:10 +02:00
(this.$refs.main as any).style.pointerEvents = 'none';
2018-11-14 09:30:58 +02:00
anime({
targets: this.$refs.bg,
opacity: 0,
duration: 300,
easing: 'linear'
});
anime({
targets: this.$refs.main,
opacity: 0,
scale: 0.8,
duration: 300,
2019-01-18 06:06:11 +02:00
easing: 'cubicBezier(0, 0.5, 0.5, 1)',
2018-11-14 09:30:58 +02:00
complete: () => this.destroyDom()
});
},
onBgClick() {
2019-04-18 13:40:23 +03:00
if (this.cancelableByBgClick) {
this.cancel();
}
2018-12-02 13:10:53 +02:00
},
onInputKeydown(e) {
if (e.which == 13) { // Enter
e.preventDefault();
e.stopPropagation();
this.ok();
}
2018-11-14 09:30:58 +02:00
}
}
});
</script>
<style lang="stylus" scoped>
.felqjxyj
display flex
align-items center
justify-content center
position fixed
z-index 30000
top 0
left 0
width 100%
height 100%
2018-11-14 17:01:49 +02:00
&.splash
> .main
min-width 0
width initial
2018-11-14 09:30:58 +02:00
> .bg
display block
position fixed
top 0
left 0
width 100%
height 100%
background rgba(#000, 0.7)
opacity 0
pointer-events none
> .main
display block
position fixed
margin auto
2018-11-14 13:23:51 +02:00
padding 32px
2018-11-14 09:30:58 +02:00
min-width 320px
max-width 480px
width calc(100% - 32px)
text-align center
background var(--face)
border-radius 8px
color var(--faceText)
opacity 0
> .icon
font-size 32px
&.success
color #85da5a
2018-11-14 09:30:58 +02:00
&.error
color #ec4137
&.warning
color #ecb637
> *
display block
margin 0 auto
2018-12-02 08:26:56 +02:00
& + header
margin-top 16px
2018-11-14 13:17:12 +02:00
> header
2018-12-02 08:26:56 +02:00
margin 0 0 8px 0
2018-11-14 09:30:58 +02:00
font-weight bold
2018-11-14 13:17:12 +02:00
font-size 20px
2018-11-14 09:30:58 +02:00
2018-11-14 11:00:23 +02:00
& + .body
margin-top 8px
2018-11-14 09:30:58 +02:00
> .body
2019-04-18 13:40:23 +03:00
margin 16px 0 0 0
2018-11-14 09:30:58 +02:00
2018-11-14 13:17:12 +02:00
> .buttons
margin-top 16px
2018-11-14 09:30:58 +02:00
</style>