2019-11-16 13:41:29 +00:00
|
|
|
|
import message
|
|
|
|
|
from lib.snabbdom import h
|
2019-11-17 21:08:53 +00:00
|
|
|
|
from model.tags import TAGS
|
2019-11-17 20:33:58 +00:00
|
|
|
|
from browser import document
|
2019-11-16 13:41:29 +00:00
|
|
|
|
|
2020-01-23 19:01:33 +00:00
|
|
|
|
def modal_template(content, title, msg, delete_msg=None):
|
2020-02-16 22:17:46 +00:00
|
|
|
|
reset = message.msg(message.ModalNotOkClose)
|
2020-01-14 20:57:11 +00:00
|
|
|
|
|
|
|
|
|
footer = []
|
2020-01-23 19:01:33 +00:00
|
|
|
|
|
2020-01-14 20:57:11 +00:00
|
|
|
|
if msg is not None:
|
2020-02-16 22:17:46 +00:00
|
|
|
|
footer.append(h("a#modal-ok.button", {"on": {"click": message.msg(*msg)}}, "OK"))
|
2020-01-23 19:01:33 +00:00
|
|
|
|
|
2020-01-14 20:57:11 +00:00
|
|
|
|
footer.append(h("label.button.dangerous", {"on": {"click": reset}}, "Cancel"))
|
2020-01-23 19:01:33 +00:00
|
|
|
|
if delete_msg is not None:
|
2020-02-16 22:17:46 +00:00
|
|
|
|
footer.append(h("label.button.warning.modal-delete", {"on": {"click": message.msg(*delete_msg)}}, "🗑"))
|
2020-01-14 20:57:11 +00:00
|
|
|
|
|
2019-11-16 13:41:29 +00:00
|
|
|
|
return [
|
|
|
|
|
h("header", {}, [
|
|
|
|
|
h("h3", {}, title),
|
|
|
|
|
h("label.close", {"on": {"click": reset}}, "×")]),
|
|
|
|
|
h("section.content", {}, content ),
|
2020-01-14 20:57:11 +00:00
|
|
|
|
h("footer", {}, footer)]
|
2019-11-16 13:41:29 +00:00
|
|
|
|
|
|
|
|
|
|
2020-03-19 20:29:19 +00:00
|
|
|
|
def _question(question, current_value, input_element):
|
|
|
|
|
props = {"value": current_value}
|
|
|
|
|
if input_element == "input":
|
|
|
|
|
props["type"] = "text"
|
|
|
|
|
|
2019-11-17 20:19:01 +00:00
|
|
|
|
return [
|
2019-11-16 13:41:29 +00:00
|
|
|
|
h("span", {}, question),
|
|
|
|
|
h("label", {}, [
|
2020-03-19 20:29:19 +00:00
|
|
|
|
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")
|
2019-11-16 13:41:29 +00:00
|
|
|
|
|
2019-11-18 19:27:11 +00:00
|
|
|
|
def generic_list_editor(title, element_list_getter):
|
|
|
|
|
content = [h("p", {}, title)]
|
2019-11-16 13:41:29 +00:00
|
|
|
|
for slabel in element_list_getter():
|
|
|
|
|
content.append(h("label", {}, [
|
|
|
|
|
h("input.list-adder-input", {"props": {"type": "text", "value": slabel}}, "")]))
|
2020-02-16 22:17:46 +00:00
|
|
|
|
content.append(h("button", {"on": {"click": message.msg(message.AddToGenericList, element_list_getter)}}, "+"))
|
2019-11-16 13:41:29 +00:00
|
|
|
|
return content
|
2019-11-17 20:33:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 = h("input.label-value-other",
|
|
|
|
|
{"props": {"type": "text", "value": right_value, "placeholder": "drugo"}},
|
|
|
|
|
[])
|
|
|
|
|
|
|
|
|
|
return split_line3(left, center, right)
|
2020-03-19 20:02:53 +00:00
|
|
|
|
|
|
|
|
|
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))
|
2019-11-17 20:33:58 +00:00
|
|
|
|
|
|
|
|
|
# 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, "")
|
2020-02-16 22:17:46 +00:00
|
|
|
|
add_label_message_class.append(get_new_label_type)
|
2019-11-17 20:33:58 +00:00
|
|
|
|
|
2020-03-19 20:02:53 +00:00
|
|
|
|
content.append(split_line3(
|
|
|
|
|
h("", {}, []),
|
|
|
|
|
h("label", {}, [
|
|
|
|
|
h("input#kontrastivno-input", {"props": {"type": "checkbox", "checked": kontrastivno}}, []),
|
|
|
|
|
h("span.checkable", {}, "kontrastivno")]),
|
|
|
|
|
h("", {}, [])))
|
|
|
|
|
|
2019-11-17 20:33:58 +00:00
|
|
|
|
left = h("span", {}, "Add more!")
|
|
|
|
|
center = h("select#new-tag-select", {}, [h("option", {}, ltype) for ltype in TAGS.keys()])
|
2020-02-16 22:17:46 +00:00
|
|
|
|
right = h("button", {"style": {"float": "right"}, "on": {"click": message.msg(*add_label_message_class)}}, "+")
|
2019-11-17 20:33:58 +00:00
|
|
|
|
content.append(split_line3(left, center, right, False))
|
2020-03-19 20:02:53 +00:00
|
|
|
|
|
2019-11-17 20:33:58 +00:00
|
|
|
|
content.append(h("hr", {}, []))
|
|
|
|
|
|
|
|
|
|
return content
|