aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/pl')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/core/Style.kt9
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt28
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/Root.kt25
3 files changed, 40 insertions, 22 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/core/Style.kt b/src/main/kotlin/pl/treksoft/kvision/core/Style.kt
index 62154f77..549aa44c 100644
--- a/src/main/kotlin/pl/treksoft/kvision/core/Style.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/core/Style.kt
@@ -25,7 +25,6 @@ import com.github.snabbdom.VNode
import com.github.snabbdom.h
import org.w3c.dom.Node
import pl.treksoft.jquery.JQuery
-import pl.treksoft.jquery.jQuery
import pl.treksoft.kvision.panel.Root
/**
@@ -66,8 +65,6 @@ open class Style(className: String? = null, parentStyle: Style? = null, init: (S
if (oldField != field) refresh()
}
- private var vnode: VNode? = null
-
override fun addCssClass(css: String): Component {
return this
}
@@ -112,15 +109,15 @@ open class Style(className: String? = null, parentStyle: Style? = null, init: (S
}
override fun getElement(): Node? {
- return this.vnode?.elm
+ return null
}
override fun getElementJQuery(): JQuery? {
- return getElement()?.let { jQuery(it) }
+ return null
}
override fun getElementJQueryD(): dynamic {
- return getElement()?.let { jQuery(it).asDynamic() }
+ return null
}
override fun clearParent(): Component {
diff --git a/src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt b/src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt
index a0456e7e..5f911539 100644
--- a/src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt
@@ -23,6 +23,7 @@ package pl.treksoft.kvision.modal
import com.github.snabbdom.VNode
import pl.treksoft.kvision.core.Component
+import pl.treksoft.kvision.core.Container
import pl.treksoft.kvision.core.StringBoolPair
import pl.treksoft.kvision.core.StringPair
import pl.treksoft.kvision.core.Widget
@@ -60,6 +61,8 @@ open class Modal(
classes: Set<String> = setOf(), init: (Modal.() -> Unit)? = null
) : SimplePanel(classes) {
+ override var parent: Container? = Root.getFirstRoot()
+
/**
* Window caption text.
*/
@@ -125,13 +128,7 @@ open class Modal(
content.add(header)
content.add(body)
content.add(footer)
- val root = Root.getLastRoot()
- if (root != null) {
- @Suppress("LeakingThis")
- root.addModal(this)
- } else {
- println("At least one Root object is required to create a modal!")
- }
+ modals.add(this)
@Suppress("LeakingThis")
init?.invoke(this)
}
@@ -258,6 +255,23 @@ open class Modal(
private fun hideInternal() {
getElementJQueryD()?.modal("hide")
}
+
+ override fun clearParent(): Widget {
+ this.parent = null
+ return this
+ }
+
+ override fun getRoot(): Root? {
+ return this.parent?.getRoot()
+ }
+
+ override fun dispose() {
+ modals.remove(this)
+ }
+
+ companion object {
+ internal var modals = mutableListOf<Modal>()
+ }
}
/**
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt b/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt
index 16d3a0f8..c17ea1a4 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt
@@ -46,13 +46,12 @@ import pl.treksoft.kvision.utils.snOpt
*/
@Suppress("TooManyFunctions")
class Root(id: String, private val fixed: Boolean = false, init: (Root.() -> Unit)? = null) : SimplePanel() {
- private val modals: MutableList<Modal> = mutableListOf()
private val contextMenus: MutableList<ContextMenu> = mutableListOf()
private var rootVnode: VNode = renderVNode()
internal var renderDisabled = false
- private val isFirstRoot = roots.isEmpty()
+ val isFirstRoot = roots.isEmpty()
init {
rootVnode = KVManager.patch(id, this.renderVNode())
@@ -60,6 +59,7 @@ class Root(id: String, private val fixed: Boolean = false, init: (Root.() -> Uni
roots.add(this)
if (isFirstRoot) {
Style.styles.forEach { it.parent = this }
+ Modal.modals.forEach { it.parent = this }
}
@Suppress("LeakingThis")
init?.invoke(this)
@@ -75,12 +75,6 @@ class Root(id: String, private val fixed: Boolean = false, init: (Root.() -> Uni
}
}
- internal fun addModal(modal: Modal) {
- modals.add(modal)
- modal.parent = this
- refresh()
- }
-
internal fun addContextMenu(contextMenu: ContextMenu) {
contextMenus.add(contextMenu)
contextMenu.parent = this
@@ -108,7 +102,11 @@ class Root(id: String, private val fixed: Boolean = false, init: (Root.() -> Uni
}
private fun modalsVNodes(): Array<VNode> {
- return modals.filter { it.visible }.map { it.renderVNode() }.toTypedArray()
+ return if (isFirstRoot) {
+ Modal.modals.filter { it.visible }.map { it.renderVNode() }.toTypedArray()
+ } else {
+ arrayOf()
+ }
}
private fun contextMenusVNodes(): Array<VNode> {
@@ -141,10 +139,19 @@ class Root(id: String, private val fixed: Boolean = false, init: (Root.() -> Uni
roots.remove(this)
if (isFirstRoot) {
Style.styles.clear()
+ Modal.modals.clear()
}
}
companion object {
+ /**
+ * @suppress internal function
+ */
+ fun shutdown() {
+ roots.forEach { it.dispose() }
+ roots.clear()
+ }
+
internal val roots: MutableList<Root> = mutableListOf()
internal fun getFirstRoot(): Root? {