lexonomy_custom_editor/src/message/common_accessors.py

54 lines
1.6 KiB
Python
Raw Normal View History

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
2020-07-16 10:22:54 +00:00
2020-07-16 10:46:48 +00:00
# Formats data from inputs to name-value objects
2020-08-07 08:34:47 +00:00
def double_list_getter(firstParameter, secondParameter, allowEmptyField = False):
2020-07-16 10:22:54 +00:00
result = []
for row in document.getElementsByClassName("double-list-row"):
firstValue = row.querySelector("." + firstParameter + "-input").value
secondValue = row.querySelector("." + secondParameter + "-input").value
2020-07-16 10:22:54 +00:00
2020-08-07 08:34:47 +00:00
if (allowEmptyField is False and '' in [firstValue, secondValue]):
continue
if (allowEmptyField is True and all('' == value or value.isspace() for value in [firstValue, secondValue])):
2020-07-16 10:22:54 +00:00
continue
result.append({firstParameter: firstValue, secondParameter: secondValue})
2020-07-16 10:22:54 +00:00
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")
2020-07-16 10:22:54 +00:00
2020-03-19 20:02:53 +00:00
if lother is None:
continue
2020-07-16 10:22:54 +00:00
value = lother.value
if not value:
2020-07-16 10:22:54 +00:00
value = lvalue.options[lvalue.selectedIndex].text
if not value:
continue
2020-07-16 10:22:54 +00:00
result.append((ltype.textContent, value))
2020-07-16 10:22:54 +00:00
2020-03-19 20:02:53 +00:00
kontrastivno = document.getElementById("kontrastivno-input").checked;
if kontrastivno:
result.append(("razmerje", "kontrastivno"))
2020-07-16 10:22:54 +00:00
return result