1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- "use strict";
- module.exports = class PortSelect {
- constructor(selectElement) {
- this.selectElement = selectElement;
- this.map = {}; // Cache matching the text value of a port to OPTION element.
- }
- /**
- * Appends a single port to the end of serial port SELECT element.
- * Adds port to map.
- * @param port
- */
- add(port) {
- const option = this.createOption(port);
- this.map[port] = option;
- this.selectElement.appendChild(option);
- }
- /**
- * Removed single port from the serial port SELECT element.
- * Removes port from map.
- * @param port
- */
- remove(port) {
- this.selectElement.removeChild(this.map[port]);
- delete this.map[port];
- }
- /**
- * Removes existing comment, adds ports to the serial port SELECT element.
- * @param ports. An Array of strings.
- */
- addAll(ports) {
- ports.forEach(port => {
- this.add(port);
- });
- }
- /**
- * Creates option with the port text and value.
- * @param port
- * @returns {Element}
- */
- createOption(port) {
- const option = document.createElement("option");
- option.textContent = port;
- option.value = port;
- return option;
- }
- /**
- * Pass through.
- * Updates the disabled attribute on the SELECT element.
- * @param value
- */
- set disabled (value) {
- this.selectElement.disabled = value;
- }
-
- get value() {
- return this.selectElement.value;
- }
- };
|