definitionList UI support
This commit is contained in:
@@ -11,7 +11,7 @@ def modal_template(content, title, msg, delete_msg=None):
|
||||
if msg is not None:
|
||||
footer.append(h("a#modal-ok.button", {"on": {"click": message.msg(*msg)}}, "OK"))
|
||||
|
||||
footer.append(h("label.button.dangerous", {"on": {"click": reset}}, "Cancel"))
|
||||
footer.append(h("label.button.dangerous", {"on": {"click": reset}}, "Prekliči"))
|
||||
if delete_msg is not None:
|
||||
footer.append(h("label.button.warning.modal-delete", {"on": {"click": message.msg(*delete_msg)}}, "🗑"))
|
||||
|
||||
@@ -47,6 +47,34 @@ def generic_list_editor(title, element_list_getter):
|
||||
content.append(h("button", {"on": {"click": message.msg(message.AddToGenericList, element_list_getter)}}, "+"))
|
||||
return content
|
||||
|
||||
def generic_key_value_editor(title, element_list_getter, key, value = "value"):
|
||||
def split_line2(left, right):
|
||||
cls = "flex.two{}".format(".double-list-row")
|
||||
return h("div.{}".format(cls), {}, [
|
||||
h("div.half", {}, left), h("div.half", {}, right)])
|
||||
content = [h("p", {}, title)]
|
||||
for i, element in enumerate(element_list_getter()):
|
||||
keys = []
|
||||
values = []
|
||||
keys.append(h("label", {"attrs": {"for": i}}, key.capitalize() + ":"))
|
||||
keys.append(h("input." + key + "-input", {"props": {"type": "text", "value": element[key], "id": i}}, ""))
|
||||
values.append(h("label", {"attrs": {"for": i + "-value"}}, "Value:"))
|
||||
values.append(
|
||||
h("input.value-input", {"props": {"type": "text", "value": element[value], "id": i + "-value"}}, ""))
|
||||
content.append(split_line2(keys, values))
|
||||
content.append(h("button", {"on": {"click": message.msg(message.AddToGenericList, element_list_getter)}}, "+"))
|
||||
return content
|
||||
|
||||
def sense_definitions_editor(title, type_value, explanation_value):
|
||||
type_props = {"value": type_value, "type": "text"}
|
||||
explanation_props = {"value": explanation_value, "type": "text"}
|
||||
return [
|
||||
h("span", {}, "Indikator:"),
|
||||
h("label", {}, [h("input#indicator-input", {"props": type_props}, "")]),
|
||||
h("span", {}, "Razlaga:"),
|
||||
h("label", {}, [h("input#explanation-input", {"props": explanation_props}, "")])
|
||||
]
|
||||
|
||||
def homonymy_editor(title, current_labels):
|
||||
def split_line2(left, right):
|
||||
cls = "flex.two{}".format(".double-list-row")
|
||||
|
||||
@@ -109,10 +109,9 @@ def edit_variants(entry):
|
||||
|
||||
def edit_homonymy(entry):
|
||||
hget = lambda: entry.copy().homonymy
|
||||
content = homonymy_editor("Homonymy", hget)
|
||||
content = generic_key_value_editor("Homonymy", hget, "name")
|
||||
return modal_template(content, "Add or remove homonymy features", (message.EditHomonymy,), (message.DeleteHomonymy,))
|
||||
|
||||
|
||||
def edit_related_entries(entry):
|
||||
reget = lambda: entry.copy().related_entries
|
||||
content = generic_list_editor("Related entries", reget)
|
||||
@@ -125,7 +124,19 @@ def edit_entry_labels(entry):
|
||||
|
||||
|
||||
def edit_sense_definition(sense):
|
||||
return modal_template(question("Edit sense definition", sense.definition["indicator"]), "Sense definition", (message.EditSenseDefinition, sense))
|
||||
indicator = ""
|
||||
explanation = ""
|
||||
for x in sense.copy().definitions:
|
||||
if indicator == "" and x["type"] == "indicator":
|
||||
indicator = x.value
|
||||
if explanation is not "":
|
||||
break
|
||||
if explanation == "" and x["type"] == "explanation":
|
||||
explanation = x.value
|
||||
if indicator is not "":
|
||||
break
|
||||
content = sense_definitions_editor(indicator, explanation)
|
||||
return modal_template(content, "Definicije pomena", (message.EditSenseDefinition, sense))
|
||||
|
||||
|
||||
def edit_comment(comment):
|
||||
|
||||
Reference in New Issue
Block a user