116 lines
3.4 KiB
Python
116 lines
3.4 KiB
Python
from message.message import Message
|
|
from message.simple_messages import NoReset, DataChgClickMessage
|
|
import message.common_accessors as common_accessors
|
|
from browser import document
|
|
from model import Sense, Example
|
|
from model.example_clusters import ExampleClusters
|
|
|
|
|
|
class QuestionMessage(Message):
|
|
def on_event(self, event):
|
|
input_element = document.getElementById("modal-question")
|
|
self.new_text = input_element.value
|
|
|
|
|
|
class EditSenseLabel(Message):
|
|
def update_model(self, model):
|
|
sense = self.get_arg(0, Sense)
|
|
sense.labels = common_accessors.label_list_getter()
|
|
|
|
|
|
class AddToGenericList(NoReset):
|
|
def update_model(self, model):
|
|
list_getter = self.get_arg(0)
|
|
list_getter().append("")
|
|
|
|
def data_change(self):
|
|
return False
|
|
|
|
|
|
class AddToLabelList(NoReset):
|
|
def update_model(self, model):
|
|
list_to_add_to = self.get_arg(0, list)
|
|
thing_to_add_getter = self.get_arg(1)
|
|
thing_to_add = thing_to_add_getter()
|
|
|
|
# just adding to the copy to show in the modal
|
|
list_to_add_to.append(thing_to_add)
|
|
|
|
def data_change(self):
|
|
return False
|
|
|
|
|
|
class AddSense(Message):
|
|
def update_model(self, model):
|
|
sense = Sense()
|
|
sense.definition = {"indicator": "New Sense"}
|
|
model.entry.senses.append(sense)
|
|
|
|
|
|
class EditSenseDefinition(QuestionMessage):
|
|
def update_model(self, model):
|
|
sense = self.get_arg(0, Sense)
|
|
sense.definition["indicator"] = self.new_text
|
|
|
|
|
|
class EditComment(QuestionMessage):
|
|
def update_model(self, model):
|
|
model.entry.comment = self.new_text
|
|
|
|
|
|
class DoChosenExamples(Message):
|
|
def update_model(self, model):
|
|
chosen_examples = self.get_arg(0, list)
|
|
|
|
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:
|
|
for example in chosen_examples:
|
|
if example in sense.examples:
|
|
sense.examples.remove(example)
|
|
|
|
# now, append selected examples to chosen sense
|
|
model.entry.senses[selected].examples.extend(chosen_examples)
|
|
|
|
|
|
class EditVariants(Message):
|
|
def update_model(self, model):
|
|
variants = common_accessors.generic_list_getter()
|
|
model.entry.variants = variants
|
|
|
|
|
|
class EditRelatedEntries(Message):
|
|
def update_model(self, model):
|
|
related_entries = common_accessors.generic_list_getter()
|
|
model.entry.related_entries = related_entries
|
|
|
|
|
|
class EditEntryLabels(Message):
|
|
def update_model(self, model):
|
|
labels = common_accessors.label_list_getter()
|
|
model.entry.labels = labels
|
|
|
|
|
|
class ExampleClusterEdit(DataChgClickMessage):
|
|
def update_model(self, model):
|
|
example = self.get_arg(0, Example)
|
|
cluster = self.get_arg(1, int)
|
|
example.set_cluster(cluster)
|
|
|
|
|
|
class ExampleClusterAdd(DataChgClickMessage):
|
|
def update_model(self, model):
|
|
example = self.get_arg(0, Example)
|
|
example.set_cluster(ExampleClusters.first_empty_cluster())
|
|
|