= ArrayList()
+ var selected: Selection = Selection.ALL
+
+ fun addTodo(e: Event) {
+ val target = e.target
+
+ if (target is HTMLInputElement) {
+ todoList.add(Todo("${Date().getTime()}", target.value))
+
+ requestUpdate()
+ }
+ }
+
+ fun editTodo(e: Event, todo: Todo) {
+ val target = e.target
+
+ if (target is HTMLInputElement) {
+ todo.title = target.value
+ todo.editing = false
+
+ requestUpdate()
+ }
+
+ }
+
+ fun destroyTodo(todo: Todo) {
+ todoList.remove(todo)
+
+ requestUpdate()
+ }
+
+ fun selectSelection(selection: Selection) {
+ selected = selection
+
+ requestUpdate()
+ }
+
+ fun clearCompleted() {
+ for (todo in ArrayList(todoList)) {
+ if (todo.completed) {
+ todoList.remove(todo)
+ }
+ }
+
+ requestUpdate()
+ }
+
+ fun todoClicked(todo: Todo) {
+ todo.completed = !todo.completed
+
+ requestUpdate()
+ }
+
+ fun getItemsLeft(): Int {
+ var result = 0
+ for (todo in todoList) {
+ if (!todo.completed) {
+ result++
+ }
+ }
+ return result
+ }
+
+ fun setEditing(editTodo: Todo) {
+ for (todo in todoList) {
+ todo.editing = todo == editTodo
+ }
+
+ requestUpdate()
+ }
+
+ override fun HtmlBuilder.render() {
+ section(classes = "todoapp") {
+ header(classes = "header") {
+ h1 { +"todos" }
+ input(classes = "new-todo") {
+ id = "todo_input"
+ placeholder = "What needs to be done?"
+ autoFocus = true
+ onKeyPressFunction = { e ->
+ val target = e.target
+ if (target is HTMLInputElement && e is KeyboardEvent && e.keyCode == 13 && target.value.isNotBlank()) {
+ addTodo(e)
+
+ target.value = ""
+ target.defaultValue = ""
+ }
+ }
+ }
+ }
+
+ section(classes = "main") {
+ input(classes = "toggle-all") {
+ type = InputType.checkBox
+ }
+ label {
+ htmlFor = "toggle-all"
+ + "Mark all as complete"
+ }
+ ul(classes = "todo-list") {
+ for (todo in todoList) {
+ if (selected == Selection.ALL ||
+ (todo.completed && selected == Selection.COMPLETED) ||
+ (!todo.completed && selected == Selection.ACTIVE)) {
+ include(TodoKomponent(this@TodoApp, todo))
+ }
+ }
+ }
+ }
+
+ footer(classes = "footer") {
+ span(classes = "todo-count") {
+ strong { +"${getItemsLeft()}" }
+ +" item left"
+ }
+ ul(classes = "filters") {
+ for (selection in Selection.values()) {
+ li {
+ a {
+ if (selection == selected) {
+ classes += "selected"
+ }
+ href = "#"
+ +selection.title
+ onClickFunction = {
+ selectSelection(selection)
+ }
+ }
+ }
+ }
+ }
+ button(classes = "clear-completed") {
+ +"Clear completed"
+ onClickFunction = {
+ clearCompleted()
+ }
+ }
+ }
+ }
+ }
+
+}
+
+fun main() {
+ Komponent.create(document.body!!, TodoApp(), true)
+}
diff --git a/web/css/base.css b/src/jsMain/resources/css/base.css
similarity index 100%
rename from web/css/base.css
rename to src/jsMain/resources/css/base.css
diff --git a/web/css/index.css b/src/jsMain/resources/css/index.css
similarity index 100%
rename from web/css/index.css
rename to src/jsMain/resources/css/index.css
diff --git a/web/index.html b/src/jsMain/resources/index.html
similarity index 86%
rename from web/index.html
rename to src/jsMain/resources/index.html
index b096035..364b0b9 100644
--- a/web/index.html
+++ b/src/jsMain/resources/index.html
@@ -12,6 +12,6 @@
Compare other javascript MVC* frameworks with TodoMVC
-
+