now a generic list implemented generically :)
This commit is contained in:
parent
d8291a15cf
commit
14eb9d1df7
11
src/message/common_accessors.py
Normal file
11
src/message/common_accessors.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
from browser import document
|
||||
|
||||
|
||||
def generic_list_getter():
|
||||
result = []
|
||||
for input_el in document.getElementsByClassName("list-adder-input"):
|
||||
result_candidate = input_el.value
|
||||
if result_candidate != "":
|
||||
result.append(result_candidate)
|
||||
return result
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
from message.message import Message
|
||||
from message.simple_messages import NoReset
|
||||
import message.common_accessors as common_accessors
|
||||
from browser import document
|
||||
from model import Sense, Example
|
||||
|
||||
|
@ -50,12 +51,7 @@ class EditExampleTranslation(Message):
|
|||
self.example = prop
|
||||
|
||||
def update_model(self, model):
|
||||
self.example.translations = []
|
||||
for input_el in document.getElementsByClassName("list-adder-input"):
|
||||
new_example_translation = input_el.value
|
||||
if new_example_translation != "":
|
||||
self.example.translations.append(new_example_translation)
|
||||
|
||||
self.example.translations = common_accessors.generic_list_getter()
|
||||
|
||||
|
||||
class AddSense(SimpleEditMessage):
|
||||
|
|
|
@ -21,7 +21,7 @@ def one_question_modal(title, msg, question, current_value, prop):
|
|||
return modal_template(content, title, msg, prop)
|
||||
|
||||
|
||||
def list_adder(title, element_list_getter, add_click_message):
|
||||
def generic_list_editor(title, element_list_getter, add_click_message):
|
||||
content = [h("span", {}, title)]
|
||||
for slabel in element_list_getter():
|
||||
content.append(h("label", {}, [
|
||||
|
|
|
@ -63,7 +63,7 @@ def edit_sense_label(sense):
|
|||
|
||||
def edit_example_translation(example):
|
||||
etl_getter = lambda: example.copy().translations
|
||||
content = list_adder("Edit example translations", etl_getter, message.msg(message.AddExampleTranslation, example))
|
||||
content = generic_list_editor("Edit example translations", etl_getter, message.msg(message.AddExampleTranslation, example))
|
||||
return modal_template(content, "Example Translations", message.EditExampleTranslation, example)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user