New editor written in Python dialect
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.
 
 
 
 
 
 

172 lines
7.1 KiB

import message
from lib.snabbdom import h
from model.tags import TAGS
from browser import document
def modal_template(content, title, msg, delete_msg=None):
reset = message.msg(message.ModalNotOkClose)
footer = []
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}}, "Prekliči"))
if delete_msg is not None:
footer.append(h("label.button.warning.modal-delete", {"on": {"click": message.msg(*delete_msg)}}, "🗑"))
return [
h("header", {}, [
h("h3", {}, title),
h("label.close", {"on": {"click": reset}}, "×")]),
h("section.content", {}, content ),
h("footer", {}, footer)]
def _question(question, current_value, input_element):
props = {"value": current_value}
if input_element == "input":
props["type"] = "text"
return [
h("span", {}, question),
h("label", {}, [
h("{}#modal-question".format(input_element), {"props": props}, "")])]
def big_question(question, current_value):
return _question(question, current_value, "textarea")
def question(question, current_value):
return _question(question, current_value, "input")
def generic_list_editor(title, element_list_getter):
content = [h("p", {}, 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": 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")
return h("div.{}".format(cls), {}, [
h("div.half", {}, left), h("div.half", {}, right)])
content = [h("p", {}, title)]
for i, feature in enumerate(current_labels()):
name = []
value = []
name.append(h("label", {"attrs": {"for": i}}, "Name:"))
name.append(h("input.name-input", {"props": {"type": "text", "value": feature["name"], "id": i}}, ""))
value.append(h("label", {"attrs": {"for": i + "-value"}}, "Value:"))
value.append(h("input.value-input", {"props": {"type": "text", "value": feature["value"], "id": i + "-value"}}, ""))
content.append(split_line2(name, value))
content.append(h("button", {"on": {"click": message.msg(message.AddToGenericList, current_labels)}}, "+"))
return content
def explanation_editor(title, current_labels):
def split_line2(left, right):
cls = "flex.two{}".format(".double-list-row")
return h("div.{}".format(cls), {}, [
h("div.four-fifth", {}, left), h("div.fifth", {}, right)])
content = [h("p", {}, title)]
for i, explanation in enumerate(current_labels()):
language = []
value = []
language.append(h("label", {"attrs": {"for": i}}, "Language:"))
language.append(h("input.language-input", {"props": {"type": "text", "value": explanation["language"], "id": i}}, ""))
value.append(h("label", {"attrs": {"for": i + "-value"}}, "Value:"))
value.append(h("input.value-input", {"props": {"type": "text", "value": explanation["value"], "id": i + "-value"}}, ""))
content.append(split_line2(value, language))
content.append(h("button", {"on": {"click": message.msg(message.AddToGenericList, current_labels)}}, "+"))
return content
def label_list_editor(current_labels, add_label_message_class):
def split_line3(left, center, right, is_llr=True):
cls = "flex.three{}".format(".label-list-row" if is_llr else "")
return h("div.{}".format(cls), {}, [
h("span.third", {}, left), h("span.third", {}, center), h("span.third", {}, right)])
def dropdown_right(label_type, label):
left = h("span.label-type", {}, label_type)
options = [h("option", {}, [])]
for value in TAGS[label_type]:
options.append(h("option", {"props": {"selected": label == value}}, value))
center = h("select.label-value", {}, options)
right_value = label if label not in TAGS[label_type] else ""
right_value = "blagovna znamka" if label_type == 'Blagovna znamka' else right_value
right = h("input.label-value-other",
{"props": {"type": "text", "value": right_value, "placeholder": "drugo"}},
[])
return split_line3(left, center, right)
content = []
kontrastivno = False
for key, value in current_labels:
# we will show kontrastivno a bit differently
if value == "kontrastivno":
kontrastivno = True
continue
content.append(dropdown_right(key, value))
# add a way to get new element to add to tag list
def get_new_label_type():
select = document.getElementById("new-tag-select")
return (select.options[select.selectedIndex].text, "")
add_label_message_class.append(get_new_label_type)
content.append(split_line3(
h("", {}, []),
h("label", {}, [
h("input#kontrastivno-input", {"props": {"type": "checkbox", "checked": kontrastivno}}, []),
h("span.checkable", {}, "kontrastivno")]),
h("", {}, [])))
left = h("span", {}, "Add more!")
center = h("select#new-tag-select", {}, [h("option", {}, ltype) for ltype in TAGS.keys()])
right = h("button", {"style": {"float": "right"}, "on": {"click": message.msg(*add_label_message_class)}}, "+")
content.append(split_line3(left, center, right, False))
content.append(h("hr", {}, []))
return content