Pinafore-Web-Client-Frontend/src/routes/_components/dialog/components/ConfirmationDialog.html

97 lines
2.1 KiB
HTML
Raw Normal View History

2018-04-05 05:33:17 +02:00
<ModalDialog
{id}
{label}
{title}
background="var(--main-bg)"
2018-04-05 05:33:17 +02:00
>
2018-02-05 18:43:45 +01:00
<form class="confirmation-dialog-form">
{#if component}
<svelte:component this={component} {...componentOpts} />
{:else}
<p>{text}</p>
{/if}
2018-02-05 18:43:45 +01:00
<div class="confirmation-dialog-form-flex">
<button type="button" on:click="onPositive()">
{positiveText}
2018-02-05 18:43:45 +01:00
</button>
<button type="button" on:click="onNegative()">
{negativeText}
2018-02-05 18:43:45 +01:00
</button>
</div>
</form>
</ModalDialog>
<style>
.confirmation-dialog-form-flex {
2018-02-06 18:09:47 +01:00
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 10px;
padding: 10px 20px;
2018-02-05 18:43:45 +01:00
}
.confirmation-dialog-form-flex button {
2018-02-06 18:09:47 +01:00
min-width: 125px;
2018-02-05 18:43:45 +01:00
}
.confirmation-dialog-form p {
font-size: 1.3em;
padding: 40px 20px;
}
</style>
<script>
import ModalDialog from './ModalDialog.html'
import { show } from '../helpers/showDialog'
import { close } from '../helpers/closeDialog'
import { on } from '../../../_utils/eventBus'
import { oncreate as onCreateDialog } from '../helpers/onCreateDialog'
2018-02-05 18:43:45 +01:00
export default {
2018-04-20 06:38:01 +02:00
oncreate () {
on('destroyDialog', this, this.onDestroyDialog)
onCreateDialog.call(this)
2018-02-05 18:43:45 +01:00
},
data: () => ({
2019-08-20 04:08:59 +02:00
component: undefined,
text: undefined,
onPositive: undefined,
onNegative: undefined,
title: '',
positiveText: 'intl.okay',
negativeText: 'intl.cancel'
}),
2018-02-05 18:43:45 +01:00
methods: {
show,
close,
2018-04-20 06:38:01 +02:00
onDestroyDialog (thisId) {
2019-08-03 22:49:37 +02:00
const {
id,
positiveResult,
onPositive,
onNegative
} = this.get()
if (thisId !== id) {
return
}
if (positiveResult) {
this.fire('positive')
if (onPositive) {
onPositive()
2018-02-05 18:43:45 +01:00
}
} else {
this.fire('negative')
if (onNegative) {
onNegative()
2018-02-05 18:43:45 +01:00
}
}
},
2018-04-20 06:38:01 +02:00
onPositive () {
this.set({ positiveResult: true })
this.close()
2018-02-05 18:43:45 +01:00
},
2018-04-20 06:38:01 +02:00
onNegative () {
this.close()
2018-02-05 18:43:45 +01:00
}
},
components: {
ModalDialog
2018-02-05 18:43:45 +01:00
}
}
</script>