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):
def update_model(self, model):
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
for sense in model.entry.senses:

View File

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

View File

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