You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
126 lines
5.4 KiB
126 lines
5.4 KiB
from lib.snabbdom import h
|
|
import message
|
|
from view.modal_templates import *
|
|
from view.utils import show_toggle_cluster_buttons
|
|
|
|
|
|
def edit_translation(translation, cluster_idx, num_clusters, cls):
|
|
def split_line2(left, right):
|
|
return h("div.flex.two", {}, [
|
|
h("span.third.span-left-of-input", {}, left), h("span.two-third", {}, 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)))
|
|
|
|
content.append(h("h4", {}, "Tags"))
|
|
content.extend(label_list_editor(translation.copy().tags, message.AddToLabelList(translation.copy().tags)))
|
|
|
|
return modal_template(content, "Translation", cls)
|
|
|
|
|
|
def edit_sense_label(sense):
|
|
content = label_list_editor(sense.copy().labels, message.AddToLabelList(sense.copy().labels))
|
|
return modal_template(content, "Translation", message.EditSenseLabel(sense))
|
|
|
|
|
|
def edit_example(example, sense):
|
|
example_original = example
|
|
example = example_original.copy()
|
|
|
|
def role_msg(idx, role):
|
|
return message.msg(message.ExampleRoleChange(example_original, idx, role))
|
|
|
|
divs = []
|
|
buttons_right = lambda idx: [
|
|
h("span.example-component-button.example-component-headword",
|
|
{"on": {"click": role_msg(idx, "headword")}}, "H"),
|
|
h("span.example-component-button.example-component-collocate",
|
|
{"on": {"click": role_msg(idx, "collocate")}}, "C"),
|
|
h("span.example-component-button.example-component-other",
|
|
{"on": {"click": role_msg(idx, "other")}}, "O"),
|
|
h("span.example-component-button.example-component-none",
|
|
{"on": {"click": role_msg(idx, "none")}}, "N"),
|
|
h("span.example-component-button",
|
|
{"on": {"click": message.msg(message.ExampleComponentAdd(example_original, idx))}}, "+"),
|
|
h("span.example-component-button",
|
|
{"on": {"click": message.msg(message.ExampleComponentRemove(example_original, idx))}}, "-")]
|
|
|
|
for idx, component in enumerate(example.components):
|
|
role_txt = component.role if component.role is not None else "none"
|
|
color_class = ".example-component-" + role_txt
|
|
|
|
left = [h("span" + color_class, {}, role_txt)]
|
|
middle = [h("input.example-component-text", {"props": {"type": "text", "value": component.text}}, "")]
|
|
|
|
divs.append(h("div.flex.five.example-component", {}, [
|
|
h("div.one-fifth", {}, left),
|
|
h("div.three-fifth", {}, middle),
|
|
h("div.one-fifth", {}, buttons_right(idx))]))
|
|
|
|
cluster = example.get_cluster()
|
|
if cluster is not None:
|
|
divs.append(h("hr", {}, []))
|
|
divs.append(h("div.flex.five.example-component", {}, [
|
|
h("div.one-fifth", {}, "Cluster"),
|
|
h("div.four-fifth", {}, show_toggle_cluster_buttons(sense, example))]))
|
|
|
|
return modal_template(divs, "Edit Example", message.EditExampleText(example_original))
|
|
|
|
|
|
def edit_variants(entry):
|
|
vget = lambda: entry.copy().variants
|
|
content = generic_list_editor("Variants", vget)
|
|
return modal_template(content, "Add or remove variants", message.EditVariants(), message.DeleteVariants())
|
|
|
|
|
|
def edit_related_entries(entry):
|
|
reget = lambda: entry.copy().related_entries
|
|
content = generic_list_editor("Related entries", reget)
|
|
return modal_template(content, "Add or remove related entries", message.EditRelatedEntries(), message.DeleteRelatedEntries())
|
|
|
|
|
|
def edit_entry_labels(entry):
|
|
content = label_list_editor(entry.copy().labels, message.AddToLabelList(entry.copy().labels))
|
|
return modal_template(content, "Translation", message.EditEntryLabels(), message.DeleteEntryLabels())
|
|
|
|
|
|
def edit_sense_definition(sense):
|
|
return modal_template(question("Edit sense definition", sense.definition["indicator"]), "Sense definition", message.EditSenseDefinition(sense))
|
|
|
|
|
|
def edit_comment(comment):
|
|
return modal_template(question("Edit comment", comment), "Comment", message.EditComment(), message.DeleteComment())
|
|
|
|
|
|
def do_chosen_examples(example_list, entry):
|
|
example_senses = []
|
|
for idx, sense in enumerate(entry.senses):
|
|
for ex in sense.examples:
|
|
if ex in example_list:
|
|
example_senses.append(idx)
|
|
break
|
|
|
|
sense_of_first_example = example_senses[0]
|
|
|
|
options = [h("p", {}, "Choose sense for examples")]
|
|
for idx, sense in enumerate(entry.senses):
|
|
text = "{}: {}".format(idx + 1, sense.definition["indicator"])
|
|
id_ = "choose-example-{}".format(idx)
|
|
|
|
props = {"type": "radio", "name": "choose-example"}
|
|
if idx == sense_of_first_example:
|
|
props["checked"] = True
|
|
|
|
options.append(h("input#{}.checkable-input".format(id_), {"props": props}, []))
|
|
options.append(h("label.checkable", {"attrs": {"for": id_}}, text))
|
|
options.append(h("br", {}, []))
|
|
|
|
return modal_template(options, "Examples picker", message.DoChosenExamples(example_list))
|