now a generic list implemented generically :)

This commit is contained in:
Ozbolt Menegatti 2019-11-16 14:59:23 +01:00
parent d8291a15cf
commit 14eb9d1df7
4 changed files with 15 additions and 8 deletions

View 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

View File

@ -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):

View File

@ -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", {}, [

View File

@ -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)