support homonymy inside modal

This commit is contained in:
matic_t 2020-07-16 03:22:54 -07:00
parent fb9a809c02
commit b010414bfe
7 changed files with 36 additions and 31 deletions

View File

@ -33,13 +33,11 @@ def export_entry(entry):
headword.appendChild(homonymy)
for h in entry.homonymy:
console.log(h)
feature = doc.createElement("homonymyFeature")
feature.textContent = h.value
feature.setAttribute("name", h["name"])
homonymy.appendChild(feature)
console.log(homonymy)
# if({}) works uncorrectly in transcrypt
if len(entry.lexical_unit) > 0:

View File

@ -8,28 +8,42 @@ def generic_list_getter():
if result_candidate != "":
result.append(result_candidate)
return result
def homonymy_list_getter():
result = []
for row in document.getElementsByClassName("label-list-row"):
value = row.querySelector(".value-input").value
name = row.querySelector(".name-input").value
if ("" in [name, value]):
continue
result.append({"name": name, "value": value})
return result
def label_list_getter():
result = []
for row in document.getElementsByClassName("label-list-row"):
ltype = row.querySelector(".label-type")
lvalue = row.querySelector(".label-value")
lother = row.querySelector(".label-value-other")
if lother is None:
continue
value = lother.value
if not value:
value = lvalue.options[lvalue.selectedIndex].text
value = lvalue.options[lvalue.selectedIndex].text
if not value:
continue
result.append((ltype.textContent, value))
kontrastivno = document.getElementById("kontrastivno-input").checked;
if kontrastivno:
result.append(("razmerje", "kontrastivno"))
return result

View File

@ -90,7 +90,7 @@ class EditVariants(Message):
class EditHomonymy(Message):
def update_model(self, model):
homonymy = common_accessors.generic_list_getter()
homonymy = common_accessors.homonymy_list_getter()
model.entry.homonymy = homonymy

View File

@ -29,7 +29,6 @@ class Entry(Data):
grammar = entry_xml.querySelector("head grammar category")
comment = entry_xml.querySelector("head comment")
self.status = status.textContent if status else ""
self.headword = headword.textContent if headword else ""
self.headword_type = headword.getAttribute("type") if headword else None
@ -97,7 +96,6 @@ class Entry(Data):
if len(self.homonymy) == 0:
view_buttons.append(buttons[4])
else:
console.log(self.homonymy)
view_table.append((buttons[4], ", ".join(h.value for h in self.homonymy)))
if len(self.related_entries) == 0:

View File

@ -9,34 +9,34 @@ class Update:
# check if completely no action needed
if msg.no_action():
return
# by default, no need to redraw entry
entry_redraw = False
# check if we need to signal the data change
if msg.data_change():
screenful.changed()
entry_redraw = True
# redraw of view can happen even if no data changed
entry_redraw |= msg.entry_redraw()
# check if we need to reset the model
reset = msg.reset()
if reset:
self.model.pre_reset()
# actually run the update_model
msg.update_model(self.model)
msg.clear_args()
# post reset comes now
if reset:
self.model.post_reset()
self.view.view(self.model, entry_redraw)
def set_model(self, model):
self.model = model

View File

@ -51,26 +51,22 @@ def homonymy_editor(title, current_labels):
def split_line2(left, right):
cls = "flex.two{}".format(".label-list-row")
return h("div.{}".format(cls), {}, [
h("span.half", {}, left), h("span.half", {}, right)])
h("div.half", {}, left), h("div.half", {}, right)])
content = [h("p", {}, title)]
for i, feature in enumerate(current_labels()):
console.log(feature)
console.log(feature["name"])
name = [h("div", {})]
value = [h("div", {})]
name = [h("div")]
value = [h("div")]
name.append(h("label", {"attrs": {"for": i}}, "Name:"))
name.append(h("input.list-adder-input", {"props": {"type": "text", "value": feature["name"], "id": i}}, ""))
name.append(h("input.name-input", {"props": {"type": "text", "value": feature["name"], "id": i}}, ""))
value.append(h("label", {"attrs": {"for": i + "-value"}}, "Value:"))
value.append(h("input.list-adder-input", {"props": {"type": "text", "value": feature["value"], "id": i + "-value"}}, ""))
value.append(h("input.value-input", {"props": {"type": "text", "value": feature["value"], "id": i + "-value"}}, ""))
content.append(split_line2(name, value))
content.append(h("button", {"on": {"click": message.msg(message.AddToGenericList, current_labels)}}, "+"))
return content
def label_list_editor(current_labels, add_label_message_class):
console.log(current_labels)
console.log(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), {}, [

View File

@ -100,7 +100,6 @@ def edit_variants(entry):
def edit_homonymy(entry):
console.log(entry)
hget = lambda: entry.copy().homonymy
content = homonymy_editor("Homonymy", hget)
return modal_template(content, "Add or remove homonymy features", (message.EditHomonymy,), (message.DeleteHomonymy,))