On choosing examples, now radio buttons

This commit is contained in:
Ozbolt Menegatti 2020-01-14 21:57:11 +01:00
parent 78f88926ea
commit 0dc849af66
3 changed files with 26 additions and 12 deletions

View File

@ -72,7 +72,17 @@ class EditExample(QuestionMessage):
class DoChosenExamples(Message): class DoChosenExamples(Message):
def update_model(self, model): def update_model(self, model):
chosen_examples = self.get_arg(0, list) chosen_examples = self.get_arg(0, list)
selected = document.getElementById("chosen-examples-select").selectedIndex
inputs = document.getElementsByClassName("checkable-input")
selected = None
for idx, el in enumerate(inputs):
if el.checked:
selected = idx
break
# none was selected
if selected is None:
return
# first, remove the selected examples from wherever they were # first, remove the selected examples from wherever they were
for sense in model.entry.senses: for sense in model.entry.senses:

View File

@ -5,14 +5,18 @@ from browser import document
def modal_template(content, title, msg): def modal_template(content, title, msg):
reset = message.msg(message.ModalNotOkClose()) 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}}, "Cancel"))
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", {}, footer)]
h("a.button", {"on": {"click": message.msg(msg)}}, "OK"),
h("label.button.dangerous", {"on": {"click": reset}}, "Cancel")])]
def question(question, current_value): def question(question, current_value):

View File

@ -59,14 +59,14 @@ def edit_example(example):
def do_chosen_examples(example_list, entry): def do_chosen_examples(example_list, entry):
options = [] options = [h("p", {}, "Choose sense for examples")]
for idx, sense in enumerate(entry.senses): for idx, sense in enumerate(entry.senses):
text = "{}: {}".format(idx, sense.definition["indicator"]) text = "{}: {}".format(idx, sense.definition["indicator"])
options.append(h("option", {}, text)) id_ = "choose-example-{}".format(idx)
content = [ options.append(h("input#{}.checkable-input".format(id_),
h("span", {}, "Choose sense for examples"), {"props": {"type": "radio", "name": "choose-example"}}, []))
h("label", {}, [ options.append(h("label.checkable", {"attrs": {"for": id_}}, text))
h("select#chosen-examples-select", {}, options)])] options.append(h("br", {}, []))
return modal_template(content, "Examples picker", message.DoChosenExamples(example_list)) return modal_template(options, "Examples picker", message.DoChosenExamples(example_list))