WIP: changed how some modals get created, also adopting for new msg()

This commit is contained in:
Ozbolt Menegatti 2019-11-17 21:19:01 +01:00
parent 5302d49396
commit 14655bd6cf
2 changed files with 14 additions and 15 deletions

View File

@ -1,24 +1,23 @@
import message import message
from lib.snabbdom import h from lib.snabbdom import h
def modal_template(content, title, msg, prop): def modal_template(content, title, msg):
reset = message.msg(message.ModalNotOkClose) reset = message.msg(message.ModalNotOkClose())
return [ return [
h("header", {}, [ h("header", {}, [
h("h3", {}, title), h("h3", {}, title),
h("label.close", {"on": {"click": reset}}, "×")]), h("label.close", {"on": {"click": reset}}, "×")]),
h("section.content", {}, content ), h("section.content", {}, content ),
h("footer", {}, [ h("footer", {}, [
h("a.button", {"on": {"click": message.msg(msg, prop)}}, "OK"), h("a.button", {"on": {"click": message.msg(msg)}}, "OK"),
h("label.button.dangerous", {"on": {"click": reset}}, "Cancel")])] h("label.button.dangerous", {"on": {"click": reset}}, "Cancel")])]
def one_question_modal(title, msg, question, current_value, prop): def question(question, current_value):
content = [ return [
h("span", {}, question), h("span", {}, question),
h("label", {}, [ h("label", {}, [
h("input#modal-input", {"props": {"type": "text", "value": current_value}}, "")])] h("input#modal-question", {"props": {"type": "text", "value": current_value}}, "")])]
return modal_template(content, title, msg, prop)
def generic_list_editor(title, element_list_getter, add_click_message): def generic_list_editor(title, element_list_getter, add_click_message):

View File

@ -4,7 +4,7 @@ from model.translation import TAGS
from view.modal_templates import * from view.modal_templates import *
def edit_translation(translation, cluster_idx, num_clusters, cls, prop): def edit_translation(translation, cluster_idx, num_clusters, cls):
def split_line2(left, right): def split_line2(left, right):
return h("div.flex.two", {}, [ return h("div.flex.two", {}, [
h("span.third.span-left-of-input", {}, left), h("span.two-third", {}, right)]) h("span.third.span-left-of-input", {}, left), h("span.two-third", {}, right)])
@ -46,7 +46,7 @@ def edit_translation(translation, cluster_idx, num_clusters, cls, prop):
for tag in TAGS.keys(): for tag in TAGS.keys():
content.append(dropdown_right(tag)) content.append(dropdown_right(tag))
return modal_template(content, "Translation", cls, prop) return modal_template(content, "Translation", cls)
def edit_sense_label(sense): def edit_sense_label(sense):
@ -58,7 +58,7 @@ def edit_sense_label(sense):
content.append(h("button", {"on": {"click": message.msg(message.AddSenseLabel(sense))}}, "+")) content.append(h("button", {"on": {"click": message.msg(message.AddSenseLabel(sense))}}, "+"))
return modal_template(content, "Sense", message.EditSenseLabel, sense) return modal_template(content, "Sense", message.EditSenseLabel(sense))
def edit_example_translation(example): def edit_example_translation(example):
@ -67,17 +67,17 @@ def edit_example_translation(example):
return modal_template(content, "Example Translations", message.EditExampleTranslation(example)) return modal_template(content, "Example Translations", message.EditExampleTranslation(example))
def add_sense(sense): def add_sense():
return one_question_modal("Add sense", message.AddSense, "Add sense with a label", "", sense) return modal_template(question("Add sense with a label", ""), "Add sense", message.AddSense())
def edit_sense_definition(sense): def edit_sense_definition(sense):
return one_question_modal("Sense definition", message.EditSenseDefinition, "Edit sense definition", sense.definition, sense) return modal_template(question("Edit sense definition", sense.definition), "Sense definition", message.EditSenseDefinition(sense))
def edit_comment(comment): def edit_comment(comment):
return one_question_modal("Comment", message.EditComment, "Edit comment", comment, None) return modal_template(question("Edit comment", comment), "Comment", message.EditComment())
def edit_example(example): def edit_example(example):
return one_question_modal("Example", message.EditExample, "Edit example", example.example, example) return modal_template(question("Edit exmample", example.example), "Example", message.EditExample(example))