refactoring view, now combining modals and view into one module.
Also common modal components can now be nicely separated and reused
This commit is contained in:
parent
5301b2a5fa
commit
d8291a15cf
|
@ -2,7 +2,7 @@ from message.message import Message, ClickMessage
|
||||||
from message.translation_edit import AddTranslation ,EditTranslation
|
from message.translation_edit import AddTranslation ,EditTranslation
|
||||||
|
|
||||||
from model.sense import NewSense
|
from model.sense import NewSense
|
||||||
import modals
|
from view import modals
|
||||||
|
|
||||||
|
|
||||||
class GenericShowModal(ClickMessage):
|
class GenericShowModal(ClickMessage):
|
||||||
|
|
|
@ -51,7 +51,7 @@ class EditExampleTranslation(Message):
|
||||||
|
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
self.example.translations = []
|
self.example.translations = []
|
||||||
for input_el in document.getElementsByClassName("example-translation-edit-input"):
|
for input_el in document.getElementsByClassName("list-adder-input"):
|
||||||
new_example_translation = input_el.value
|
new_example_translation = input_el.value
|
||||||
if new_example_translation != "":
|
if new_example_translation != "":
|
||||||
self.example.translations.append(new_example_translation)
|
self.example.translations.append(new_example_translation)
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
from message.message import Message, ClickMessage, msg
|
from message.message import Message, ClickMessage, msg
|
||||||
from browser import window
|
from browser import window
|
||||||
import modals
|
|
||||||
|
|
||||||
|
|
||||||
class Reset(ClickMessage):
|
class Reset(ClickMessage):
|
||||||
|
|
2
src/view/__init__.py
Normal file
2
src/view/__init__.py
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
import view.modals
|
||||||
|
from view.view import View
|
30
src/view/modal_templates.py
Normal file
30
src/view/modal_templates.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
import message
|
||||||
|
from lib.snabbdom import h
|
||||||
|
|
||||||
|
def modal_template(content, title, msg, prop):
|
||||||
|
reset = message.msg(message.ModalNotOkClose)
|
||||||
|
return [
|
||||||
|
h("header", {}, [
|
||||||
|
h("h3", {}, title),
|
||||||
|
h("label.close", {"on": {"click": reset}}, "×")]),
|
||||||
|
h("section.content", {}, content ),
|
||||||
|
h("footer", {}, [
|
||||||
|
h("a.button", {"on": {"click": message.msg(msg, prop)}}, "OK"),
|
||||||
|
h("label.button.dangerous", {"on": {"click": reset}}, "Cancel")])]
|
||||||
|
|
||||||
|
|
||||||
|
def one_question_modal(title, msg, question, current_value, prop):
|
||||||
|
content = [
|
||||||
|
h("span", {}, question),
|
||||||
|
h("label", {}, [
|
||||||
|
h("input#modal-input", {"props": {"type": "text", "value": current_value}}, "")])]
|
||||||
|
return modal_template(content, title, msg, prop)
|
||||||
|
|
||||||
|
|
||||||
|
def list_adder(title, element_list_getter, add_click_message):
|
||||||
|
content = [h("span", {}, title)]
|
||||||
|
for slabel in element_list_getter():
|
||||||
|
content.append(h("label", {}, [
|
||||||
|
h("input.list-adder-input", {"props": {"type": "text", "value": slabel}}, "")]))
|
||||||
|
content.append(h("button", {"on": {"click": add_click_message}}, "+"))
|
||||||
|
return content
|
|
@ -1,27 +1,7 @@
|
||||||
from lib.snabbdom import h
|
from lib.snabbdom import h
|
||||||
import message
|
import message
|
||||||
from browser import document
|
|
||||||
from model.translation import TAGS
|
from model.translation import TAGS
|
||||||
|
from view.modal_templates import *
|
||||||
|
|
||||||
def modal_template(content, title, msg, prop):
|
|
||||||
reset = message.msg(message.ModalNotOkClose)
|
|
||||||
return [
|
|
||||||
h("header", {}, [
|
|
||||||
h("h3", {}, title),
|
|
||||||
h("label.close", {"on": {"click": reset}}, "×")]),
|
|
||||||
h("section.content", {}, content ),
|
|
||||||
h("footer", {}, [
|
|
||||||
h("a.button", {"on": {"click": message.msg(msg, prop)}}, "OK"),
|
|
||||||
h("label.button.dangerous", {"on": {"click": reset}}, "Cancel")])]
|
|
||||||
|
|
||||||
|
|
||||||
def one_question_modal(title, msg, question, current_value, prop):
|
|
||||||
content = [
|
|
||||||
h("span", {}, question),
|
|
||||||
h("label", {}, [
|
|
||||||
h("input#modal-input", {"props": {"type": "text", "value": current_value}}, "")])]
|
|
||||||
return modal_template(content, title, msg, prop)
|
|
||||||
|
|
||||||
|
|
||||||
def edit_translation(translation, cluster_idx, num_clusters, cls, prop):
|
def edit_translation(translation, cluster_idx, num_clusters, cls, prop):
|
||||||
|
@ -82,12 +62,8 @@ def edit_sense_label(sense):
|
||||||
|
|
||||||
|
|
||||||
def edit_example_translation(example):
|
def edit_example_translation(example):
|
||||||
content = [h("span", {}, "Edit example translations")]
|
etl_getter = lambda: example.copy().translations
|
||||||
for slabel in example.copy().translations:
|
content = list_adder("Edit example translations", etl_getter, message.msg(message.AddExampleTranslation, example))
|
||||||
content.append(h("label", {}, [
|
|
||||||
h("input.example-translation-edit-input", {"props": {"type": "text", "value": slabel}}, "")]))
|
|
||||||
|
|
||||||
content.append(h("button", {"on": {"click": message.msg(message.AddExampleTranslation, example)}}, "+"))
|
|
||||||
return modal_template(content, "Example Translations", message.EditExampleTranslation, example)
|
return modal_template(content, "Example Translations", message.EditExampleTranslation, example)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user