model.modal now a function and multiple sense labels
This commit is contained in:
parent
75755ef3c5
commit
58adffb104
|
@ -79,10 +79,14 @@
|
|||
}
|
||||
}
|
||||
|
||||
.sense-label {
|
||||
.sense-label-list {
|
||||
// done!
|
||||
color: @blue;
|
||||
._hoverable();
|
||||
|
||||
.sense-label + .sense-label:before {
|
||||
content: ", ";
|
||||
}
|
||||
}
|
||||
|
||||
.translation-div {
|
||||
|
|
|
@ -56,9 +56,10 @@ def export_sense(doc, sense):
|
|||
label_list = doc.createElement("labelList")
|
||||
sense_xml.appendChild(label_list)
|
||||
|
||||
label = doc.createElement("label")
|
||||
label.textContent = sense.label
|
||||
label_list.appendChild(label)
|
||||
for label in sense.labels:
|
||||
label_xml = doc.createElement("label")
|
||||
label_xml.textContent = label
|
||||
label_list.appendChild(label_xml)
|
||||
|
||||
definition_list = doc.createElement("definitionList")
|
||||
sense_xml.appendChild(definition_list)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from message.simple_messages import NoReset, Reset, ModalNotOkClose
|
||||
from message.translation_edit import EditTranslation, MoveRight, MoveLeft, BinTranslation
|
||||
from message.show_messages import ShowMenu, ShowEditTranslation, ShowSenseLabelEdit, ShowSenseDefinitionEdit, ShowCommentEdit, ShowAddTranslation
|
||||
from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment
|
||||
from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel
|
||||
from message.message import msg
|
||||
|
||||
|
||||
|
|
|
@ -29,20 +29,22 @@ class ShowSenseLabelEdit(GenericShowModal):
|
|||
def update_model(self, model):
|
||||
super().update_model(model)
|
||||
model.sense = self.arg
|
||||
model.modal = modals.edit_sense_label(self.arg)
|
||||
|
||||
model.sense.temporary_labels = model.sense.labels[:]
|
||||
model.modal = lambda: modals.edit_sense_label(model.sense)
|
||||
|
||||
|
||||
class ShowSenseDefinitionEdit(GenericShowModal):
|
||||
def update_model(self, model):
|
||||
super().update_model(model)
|
||||
model.sense = self.arg
|
||||
model.modal = modals.edit_sense_definition(self.arg)
|
||||
model.modal = lambda: modals.edit_sense_definition(self.arg)
|
||||
|
||||
|
||||
class ShowCommentEdit(ClickMessage):
|
||||
def update_model(self, model):
|
||||
model.modal_shown = True
|
||||
model.modal = modals.edit_comment(model.entry.comment)
|
||||
model.modal = lambda: modals.edit_comment(model.entry.comment)
|
||||
|
||||
|
||||
class ShowEditTranslation(GenericShowModal):
|
||||
|
@ -57,7 +59,8 @@ class ShowEditTranslation(GenericShowModal):
|
|||
for t in cluster:
|
||||
if t == translation:
|
||||
# fount the one!
|
||||
model.modal = modals.edit_translation(translation, cidx, num_clusters, EditTranslation, (translation, cidx))
|
||||
model.modal = lambda: modals.edit_translation(
|
||||
translation, cidx, num_clusters, EditTranslation, (translation, cidx))
|
||||
return
|
||||
|
||||
console.log("Should not be here!")
|
||||
|
@ -70,7 +73,8 @@ class ShowAddTranslation(GenericShowModal):
|
|||
|
||||
for sense in model.entry.senses:
|
||||
if sense == chosen_sense:
|
||||
model.modal = modals.edit_translation(sense, -1, len(sense.translations), AddTranslation, sense)
|
||||
model.modal = lambda: modals.edit_translation(
|
||||
sense, -1, len(sense.translations), AddTranslation, sense)
|
||||
return
|
||||
|
||||
console.log("Should not be here!")
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from message.message import Message
|
||||
from message.simple_messages import NoReset
|
||||
from browser import document
|
||||
from model import Sense
|
||||
|
||||
|
@ -10,11 +11,26 @@ class SimpleEditMessage(Message):
|
|||
self.prop = prop
|
||||
|
||||
|
||||
class EditSenseLabel(SimpleEditMessage):
|
||||
class EditSenseLabel(Message):
|
||||
def __init__(self, _, prop):
|
||||
assert(type(prop) is Sense)
|
||||
self.sense = prop
|
||||
|
||||
def update_model(self, model):
|
||||
sense = self.prop
|
||||
assert(type(sense) is Sense)
|
||||
sense.label = self.new_text
|
||||
self.sense.labels = []
|
||||
for input_el in document.getElementsByClassName("sense-edit-input"):
|
||||
new_sense_label = input_el.value
|
||||
if new_sense_label != "":
|
||||
self.sense.labels.append(new_sense_label)
|
||||
|
||||
|
||||
class AddSenseLabel(NoReset):
|
||||
def __init__(self, _, prop):
|
||||
assert(type(prop) is Sense)
|
||||
self.sense = prop
|
||||
|
||||
def update_model(self, model):
|
||||
self.sense.temporary_labels.append("")
|
||||
|
||||
|
||||
class EditSenseDefinition(SimpleEditMessage):
|
||||
|
|
|
@ -19,7 +19,7 @@ class NoReset(Reset):
|
|||
# after setting model.modal, do view update to actually update the DOM
|
||||
class _ModalResetDelayed(Message):
|
||||
def update_model(self, model):
|
||||
model.modal = []
|
||||
model.modal_reset()
|
||||
|
||||
class ModalNotOkClose(Reset):
|
||||
def update_model(self, model):
|
||||
|
|
|
@ -66,8 +66,17 @@ def edit_translation(translation, cluster_idx, num_clusters, cls, prop):
|
|||
|
||||
return modal_template(content, "Translation", cls, prop)
|
||||
|
||||
|
||||
def edit_sense_label(sense):
|
||||
return one_question_modal("Sense", message.EditSenseLabel, "Edit sense label", sense.label, sense)
|
||||
content = [h("span", {}, "Edit sense labels")]
|
||||
|
||||
for slabel in sense.temporary_labels:
|
||||
content.append(h("label", {}, [
|
||||
h("input.sense-edit-input", {"props": {"type": "text", "value": slabel}}, "")]))
|
||||
|
||||
content.append(h("button", {"on": {"click": message.msg(message.AddSenseLabel, sense)}}, "+"))
|
||||
|
||||
return modal_template(content, "Sense", message.EditSenseLabel, sense)
|
||||
|
||||
|
||||
def edit_sense_definition(sense):
|
||||
|
|
|
@ -12,16 +12,25 @@ class Model:
|
|||
#runtime info
|
||||
self.menu_location = (0, 0)
|
||||
self.menu_shown = False
|
||||
self.modal = []
|
||||
|
||||
# modal handling
|
||||
self.modal = lambda: []
|
||||
self.modal_shown = False
|
||||
|
||||
# currently edited stuff
|
||||
self.translation = None
|
||||
self.sense = None
|
||||
|
||||
self.reset()
|
||||
self.modal_reset()
|
||||
|
||||
def reset(self):
|
||||
self.menu_shown = False
|
||||
self.modal_shown = False
|
||||
|
||||
def modal_reset(self):
|
||||
self.modal = lambda: []
|
||||
|
||||
|
||||
def import_xml(self, xml_text):
|
||||
parser = __new__(DOMParser())
|
||||
|
|
|
@ -4,10 +4,9 @@ from model.translation import Translation
|
|||
|
||||
class Sense:
|
||||
def __init__(self, sense_xml):
|
||||
label = sense_xml.querySelector("labelList label")
|
||||
definition = sense_xml.querySelector("definitionList definition")
|
||||
|
||||
self.label = label.textContent if label else ""
|
||||
self.labels = [label.textContent for label in sense_xml.querySelectorAll("labelList label")]
|
||||
self.definition = definition.textContent if definition else ""
|
||||
|
||||
self.examples = [Example(example_xml) for example_xml in
|
||||
|
@ -25,4 +24,6 @@ class Sense:
|
|||
for clusterNum, translation in translations:
|
||||
self.translations[clusterNum - 1].append(translation)
|
||||
|
||||
# useful for editing
|
||||
self.temporary_labels = None
|
||||
|
||||
|
|
|
@ -43,7 +43,8 @@ class View:
|
|||
return h("div.elm-div", {}, [
|
||||
h("div.sense-num", {}, str(senseNum + 1)),
|
||||
h("div.sense", {}, [
|
||||
h("span.sense-label", { "on": { "click": msg(ShowSenseLabelEdit, sense) }}, sense.label),
|
||||
h("span.sense-label-list", { "on": { "click": msg(ShowSenseLabelEdit, sense) }}, [
|
||||
h("span.sense-label", {}, slabel) for slabel in sense.labels ]),
|
||||
h("span.sense-definition", { "on": { "click": msg(ShowSenseDefinitionEdit, sense) }}, sense.definition),
|
||||
h("div", {}, View.view_translations(sense.translations, sense)),
|
||||
h("div", {}, examples)])])
|
||||
|
@ -107,5 +108,5 @@ class View:
|
|||
return h("div.modal", {}, [
|
||||
h("input", { "props": {"type": "checkbox", "checked": modal_shown} }, ""),
|
||||
h("label.overlay", {}, ""),
|
||||
h("article", {"on": { "click": NoReset }}, modal)])
|
||||
h("article", {"on": { "click": NoReset }}, modal())])
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user