/* Espe | Ein schlichtes Werkzeug zur Mitglieder-Verwaltung | Frontend Copyright (C) 2024 Christian Fraß This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ namespace _espe { /** * @todo outsource to plankton */ export class class_input_set implements lib_plankton.zoo_input.interface_input> { /** */ private options : Array; /** */ private show_element : ((element : string) => string); /** */ private read_only : boolean; /** */ private checkboxes : Map; /** */ public constructor( options : Array, show_element : ((element : string) => string), { "read_only": read_only = false, } : { read_only ?: boolean; } = { } ) { this.show_element = show_element; this.options = options; this.read_only = read_only; this.checkboxes = new Map(); } /** * [implementation] */ public setup( parent : HTMLElement ) : Promise { for (const option of this.options) { // label const element_container : HTMLElement = document.createElement("label"); element_container.classList.add("plankton_input_set_option"); element_container.setAttribute("rel", option); // checkbox { const element_checkbox : HTMLInputElement = document.createElement("input"); element_checkbox.setAttribute("type", "checkbox"); element_container.appendChild(element_checkbox); this.checkboxes.set(option, element_checkbox); } // text { const element_text : HTMLElement = document.createElement("span"); element_text.textContent = this.show_element(option); element_container.appendChild(element_text); } parent.appendChild(element_container); } return Promise.resolve(undefined); } /** * [implementation] */ public read( ) : Promise> { const result : Set = new Set(); for (const option of this.options) { const element_checkbox : HTMLInputElement = this.checkboxes.get(option); if (element_checkbox.checked) { result.add(option); } } return Promise.resolve>(result); } /** * [implementation] */ public write( value : Set ) : Promise { for (const option of this.options) { const element_checkbox : HTMLInputElement = this.checkboxes.get(option); element_checkbox.checked = value.has(option); } return Promise.resolve(undefined); } } }