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:
83
src/view/modals.py
Normal file
83
src/view/modals.py
Normal file
@@ -0,0 +1,83 @@
|
||||
from lib.snabbdom import h
|
||||
import message
|
||||
from model.translation import TAGS
|
||||
from view.modal_templates import *
|
||||
|
||||
|
||||
def edit_translation(translation, cluster_idx, num_clusters, cls, prop):
|
||||
def split_line2(left, right):
|
||||
return h("div.flex.two", {}, [
|
||||
h("span.third.span-left-of-input", {}, left), h("span.two-third", {}, right)])
|
||||
|
||||
def split_line3(left, center, right):
|
||||
return h("div.flex.three", {}, [
|
||||
h("span.third.span-left-of-input", {}, left), h("span.third", {}, center), h("span.third", {}, right)])
|
||||
|
||||
def dropdown_right(tag_name):
|
||||
left = tag_name + ":"
|
||||
|
||||
values = TAGS[tag_name]
|
||||
selected_value = translation.tags[tag_name] if tag_name in translation.tags else None
|
||||
|
||||
options = [h("option", {}, [])]
|
||||
for value in values:
|
||||
options.append(h("option", {"props": {"selected": selected_value == value}}, value))
|
||||
center = h("select#{}-s".format(tag_name), {}, options)
|
||||
|
||||
right_value = selected_value if selected_value not in values and selected_value is not None else ""
|
||||
right = h("input#{}-o".format(tag_name),
|
||||
{"props": {"type": "text", "value": right_value, "placeholder": "drugo"}},
|
||||
[])
|
||||
|
||||
return split_line3(left, center, right)
|
||||
|
||||
# first line: transalation itself
|
||||
content = [split_line2("Prevedek:",
|
||||
h("input#etv", {"props": {"type": "text", "value": translation.translation}}, "")),
|
||||
split_line2("Razlaga:",
|
||||
h("input#ete", {"props": {"type": "text", "value": translation.explanation}}, ""))]
|
||||
|
||||
# cluster number
|
||||
options = [h("option", {"props": {"selected": idx == cluster_idx}}, str(idx + 1)) for idx in range(num_clusters + 1)]
|
||||
content.append(split_line2("Stevilka gruce:", h("select#cluster-num", {}, options)))
|
||||
|
||||
# tags
|
||||
content.append(h("h4", {}, "Tags"))
|
||||
for tag in TAGS.keys():
|
||||
content.append(dropdown_right(tag))
|
||||
|
||||
return modal_template(content, "Translation", cls, prop)
|
||||
|
||||
|
||||
def edit_sense_label(sense):
|
||||
content = [h("span", {}, "Edit sense labels")]
|
||||
|
||||
for slabel in sense.copy().labels:
|
||||
content.append(h("label", {}, [
|
||||
h("input.sense-edit-input", {"props": {"type": "text", "value": slabel}}, "")]))
|
||||
|
||||
content.append(h("button", {"on": {"click": message.msg(message.AddSenseLabel, sense)}}, "+"))
|
||||
|
||||
return modal_template(content, "Sense", message.EditSenseLabel, sense)
|
||||
|
||||
|
||||
def edit_example_translation(example):
|
||||
etl_getter = lambda: example.copy().translations
|
||||
content = list_adder("Edit example translations", etl_getter, message.msg(message.AddExampleTranslation, example))
|
||||
return modal_template(content, "Example Translations", message.EditExampleTranslation, example)
|
||||
|
||||
|
||||
def add_sense(sense):
|
||||
return one_question_modal("Add sense", message.AddSense, "Add sense with a label", "", sense)
|
||||
|
||||
|
||||
def edit_sense_definition(sense):
|
||||
return one_question_modal("Sense definition", message.EditSenseDefinition, "Edit sense definition", sense.definition, sense)
|
||||
|
||||
|
||||
def edit_comment(comment):
|
||||
return one_question_modal("Comment", message.EditComment, "Edit comment", comment, None)
|
||||
|
||||
|
||||
def edit_example(example):
|
||||
return one_question_modal("Example", message.EditExample, "Edit example", example.example, example)
|
||||
Reference in New Issue
Block a user