gancio-upstream/components/Confirm.vue

85 lines
1.7 KiB
Vue
Raw Normal View History

2020-07-28 12:24:39 +02:00
<template lang="pug">
v-dialog(v-model='show'
:color='options.color'
:title='title'
:max-width='options.width'
:style="{ zIndex: options.zIndex, position: 'absolute' }"
@keydown.esc='cancel')
v-card
v-card-title {{ title }}
2020-08-05 17:05:10 +02:00
v-card-text(v-show='!!message') {{ message }}
v-card-actions
2020-07-28 12:24:39 +02:00
v-spacer
2020-08-05 17:05:10 +02:00
v-btn(color='error' @click='cancel') {{$t('common.cancel')}}
v-btn(color='primary' @click='agree') {{$t('common.ok')}}
2020-07-28 12:24:39 +02:00
</template>
<script>
/**
* Vuetify Confirm Dialog component
*
* Call it:
* this.$refs.confirm.open('Delete', 'Are you sure?', { color: 'red' }).then((confirm) => {})
*
* Or use await:
* if (await this.$refs.confirm.open('Delete', 'Are you sure?', { color: 'red' })) {
* // yes
* }
* else {
* // cancel
* }
*
*/
export default {
data: () => ({
dialog: false,
resolve: null,
reject: null,
message: null,
title: null,
options: {
color: 'danger',
2020-08-05 17:05:10 +02:00
width: 450,
2020-07-28 12:24:39 +02:00
zIndex: 500
}
}),
computed: {
show: {
get () {
return this.dialog
},
set (value) {
this.dialog = value
if (value === false) {
this.cancel()
}
}
}
},
created () {
this.$root.$confirm = this.open
},
methods: {
open (title, message, options) {
this.dialog = true
this.title = title
this.message = message
this.options = Object.assign(this.options, options)
return new Promise((resolve, reject) => {
this.resolve = resolve
this.reject = reject
})
},
agree () {
this.resolve(true)
this.dialog = false
},
cancel () {
this.resolve(false)
this.dialog = false
}
}
}
</script>