Changing how senses are added and how buttons are shown.

This commit is contained in:
2019-11-20 18:58:48 +01:00
parent 06ab8f2230
commit 1039a686cc
7 changed files with 62 additions and 63 deletions

View File

@@ -47,10 +47,6 @@ def edit_entry_labels(entry):
return modal_template(content, "Translation", message.EditEntryLabels())
def add_sense():
return modal_template(question("Add sense with a label", ""), "Add sense", message.AddSense())
def edit_sense_definition(sense):
return modal_template(question("Edit sense definition", sense.definition), "Sense definition", message.EditSenseDefinition(sense))

View File

@@ -20,7 +20,7 @@ class View:
def _view(self):
return h("div", {"on": { "click": msg(Reset()) }}, [
View.view_entry(self.model.entry),
# h("button.blk", {"on": { "click": lambda _: console.log(export_to_xml(self.model)) } }, "XML2Console"),
h("button.blk", {"on": { "click": lambda _: console.log(export_to_xml(self.model)) } }, "XML2Console"),
View.view_menu(self.model.menu_location, self.model.menu_shown, self.model.translation),
View.view_modal(self.model.modal_shown, self.model.modal)])
@@ -35,26 +35,42 @@ class View:
h("span#grammar", {}, entry.grammar)]),
View.view_entry_button_section(entry),
h("div#sense-container", {}, view_sense_list),
h("button.add-button", {"on": {"click": msg(ShowSenseAdd())}}, "+")])
h("button.add-button", {"on": {"click": msg(AddSense())}}, "+")])
@staticmethod
def view_entry_button_section(entry):
clk = lambda cls: {"on": {"click": msg(cls)}}
buttons = [
h("button.warning", clk(ShowCommentEdit()), "Comment"),
h("button.normal", clk(ShowVariantsEdit()), "Variants"),
h("button.success", clk(ShowEntryLabelsEdit()), "Labels")]
h("button.success", clk(ShowEntryLabelsEdit()), "Labels"),
h("button.warning", clk(ShowCommentEdit()), "Comment")]
if entry.comment == "" and len(entry.labels) == 0 and len(entry.variants) == 0:
return h("div", {}, buttons)
view_buttons = []
view_table = []
labels = ", ".join([val for _, val in entry.labels])
return h("table", {}, [
h("tr", {}, [ h("td", {}, buttons[0]), h("td", {}, entry.comment)]),
h("tr", {}, [ h("td", {}, buttons[1]), h("td", {}, ", ".join(entry.variants))]),
h("tr", {}, [ h("td", {}, buttons[2]), h("td", {}, labels)])])
if len(entry.variants) == 0:
view_buttons.append(buttons[0])
else:
view_table.append((buttons[0], ", ".join(entry.variants)))
if len(entry.labels) == 0:
view_buttons.append(buttons[1])
else:
labels = ", ".join([val for _, val in entry.labels])
view_table.append((buttons[1], labels))
if entry.comment == "":
view_buttons.append(buttons[2])
else:
view_table.append((buttons[2], entry.comment))
table_rows = [
h("tr", {}, [ h("td", {}, btn), h("td", {}, content)])
for btn, content in view_table]
view_buttons.append(h("table", {}, table_rows))
return h("div", {}, view_buttons)
@staticmethod
def view_sense(sense, senseNum):