aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/panel
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2019-10-13 17:04:42 +0200
committerRobert Jaros <rjaros@finn.pl>2019-10-13 17:04:42 +0200
commit780c340a481676e27398dccf4503e8f0b9c63060 (patch)
tree65efeec54d3b4d4e420c5882db38814e40eb3940 /src/main/kotlin/pl/treksoft/kvision/panel
parente84227897eac9d90e79c5ba5ae775eac1085ea64 (diff)
downloadkvision-780c340a481676e27398dccf4503e8f0b9c63060.tar.gz
kvision-780c340a481676e27398dccf4503e8f0b9c63060.tar.bz2
kvision-780c340a481676e27398dccf4503e8f0b9c63060.zip
New Application class to reduce applications boilerplate (#92).
New testutils module.
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/panel')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/Root.kt39
1 files changed, 38 insertions, 1 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt b/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt
index e0c70ac4..ce86c678 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt
@@ -24,6 +24,7 @@ package pl.treksoft.kvision.panel
import com.github.snabbdom.VNode
import com.github.snabbdom.h
import org.w3c.dom.HTMLElement
+import pl.treksoft.kvision.Application
import pl.treksoft.kvision.KVManager
import pl.treksoft.kvision.core.StringBoolPair
import pl.treksoft.kvision.core.Style
@@ -40,6 +41,7 @@ import pl.treksoft.kvision.utils.snOpt
*
* @constructor
* @param id ID attribute of element in the main HTML file
+ * @param element HTML element in the DOM tree
* @param fixed if false, the container is rendered with Bootstrap "container-fluid" class,
* otherwise it's rendered with "container" class (default is false)
* @param init an initializer extension function
@@ -160,13 +162,16 @@ class Root(
/**
* @suppress internal function
*/
- fun shutdown() {
+ fun disposeAllRoots() {
roots.forEach { it.dispose() }
roots.clear()
}
internal val roots: MutableList<Root> = mutableListOf()
+ /**
+ * @suppress internal function
+ */
fun getFirstRoot(): Root? {
return if (roots.isNotEmpty())
roots[0]
@@ -174,6 +179,9 @@ class Root(
null
}
+ /**
+ * @suppress internal function
+ */
fun getLastRoot(): Root? {
return if (roots.isNotEmpty())
roots[roots.size - 1]
@@ -181,12 +189,41 @@ class Root(
null
}
+ /**
+ * @suppress internal function
+ */
fun addModal(modal: Widget) {
modals.add(modal)
}
+ /**
+ * @suppress internal function
+ */
fun removeModal(modal: Widget) {
modals.remove(modal)
}
+
+ /**
+ * Create new Root container based on ID
+ * @param id ID attribute of element in the main HTML file
+ * @param fixed if false, the container is rendered with Bootstrap "container-fluid" class,
+ * otherwise it's rendered with "container" class (default is false)
+ * @param init an initializer extension function
+ */
+ fun Application.root(id: String, fixed: Boolean = false, init: Root.() -> Unit) {
+ Root(id, fixed = fixed, init = init)
+ }
+
+ /**
+ * Create new Root container based on HTML element
+ * @param element HTML element in the DOM tree
+ * @param fixed if false, the container is rendered with Bootstrap "container-fluid" class,
+ * otherwise it's rendered with "container" class (default is false)
+ * @param init an initializer extension function
+ */
+ fun Application.root(element: HTMLElement, fixed: Boolean = false, init: Root.() -> Unit) {
+ Root(element = element, fixed = fixed, init = init)
+ }
+
}
}