aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/modal/Confirm.kt
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2017-09-17 04:28:09 +0200
committerRobert Jaros <rjaros@finn.pl>2017-09-17 04:28:09 +0200
commitab12f9a29f7517e6ad5923b687f8ff476fc83a93 (patch)
treee22a30fd6d54f63f538dd81a609f794991d986ea /src/main/kotlin/pl/treksoft/kvision/modal/Confirm.kt
parent5d5db76ff0d9d1505c4a41cd84e871793a7a7b8d (diff)
downloadkvision-ab12f9a29f7517e6ad5923b687f8ff476fc83a93.tar.gz
kvision-ab12f9a29f7517e6ad5923b687f8ff476fc83a93.tar.bz2
kvision-ab12f9a29f7517e6ad5923b687f8ff476fc83a93.zip
Modals
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/modal/Confirm.kt')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/modal/Confirm.kt84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/modal/Confirm.kt b/src/main/kotlin/pl/treksoft/kvision/modal/Confirm.kt
new file mode 100644
index 00000000..366eec52
--- /dev/null
+++ b/src/main/kotlin/pl/treksoft/kvision/modal/Confirm.kt
@@ -0,0 +1,84 @@
+package pl.treksoft.kvision.modal
+
+import pl.treksoft.kvision.html.ALIGN
+import pl.treksoft.kvision.html.BUTTONSTYLE
+import pl.treksoft.kvision.html.Button
+import pl.treksoft.kvision.html.TAG
+import pl.treksoft.kvision.html.Tag
+
+open class Confirm(caption: String? = null, text: String? = null, rich: Boolean = false,
+ align: ALIGN = ALIGN.NONE, size: MODALSIZE? = null, animation: Boolean = true,
+ cancelVisible: Boolean = false,
+ private val noCallback: (() -> Unit)? = null,
+ private val yesCallback: (() -> Unit)? = null) : Modal(caption, false, size, animation, false) {
+ var text
+ get() = content.text
+ set(value) {
+ content.text = value
+ }
+ var rich
+ get() = content.rich
+ set(value) {
+ content.rich = value
+ }
+ var align
+ get() = content.align
+ set(value) {
+ content.align = value
+ }
+ var cancelVisible = cancelVisible
+ set(value) {
+ field = value
+ refreshCancelButton()
+ }
+
+ val content = Tag(TAG.SPAN, text, rich, align)
+ val cancelButton = Button("Cancel", "remove")
+
+ init {
+ body.add(content)
+ cancelButton.setEventListener {
+ click = {
+ hide()
+ }
+ }
+ this.addButton(cancelButton)
+ val noButton = Button("No", "ban-circle")
+ noButton.setEventListener {
+ click = {
+ hide()
+ noCallback?.invoke()
+ }
+ }
+ this.addButton(noButton)
+ val yesButton = Button("Yes", "ok", BUTTONSTYLE.PRIMARY)
+ yesButton.setEventListener {
+ click = {
+ hide()
+ yesCallback?.invoke()
+ }
+ }
+ this.addButton(yesButton)
+ refreshCancelButton()
+ }
+
+ private fun refreshCancelButton() {
+ if (cancelVisible) {
+ cancelButton.show()
+ closeIcon.show()
+ } else {
+ cancelButton.hide()
+ closeIcon.hide()
+ }
+ }
+
+ companion object {
+ @Suppress("LongParameterList")
+ fun show(caption: String? = null, text: String? = null, rich: Boolean = false,
+ align: ALIGN = ALIGN.NONE, size: MODALSIZE? = null, animation: Boolean = true,
+ cancelVisible: Boolean = false,
+ noCallback: (() -> Unit)? = null, yesCallback: (() -> Unit)? = null) {
+ Confirm(caption, text, rich, align, size, animation, cancelVisible, noCallback, yesCallback).show()
+ }
+ }
+}