diff options
author | Maxim Devaev <[email protected]> | 2023-03-19 01:17:31 +0200 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2023-03-19 02:16:20 +0200 |
commit | 84563553b8a2f00bbb4b1559029f77ad225627f4 (patch) | |
tree | 6795ccb04bff10d2c2bd09c1ce6381f381727007 /web/share/js/tools.js | |
parent | 097dbc517df4fcfb8d37d958744b1eb1f0e8d8b6 (diff) |
fixed msd parts api
Diffstat (limited to 'web/share/js/tools.js')
-rw-r--r-- | web/share/js/tools.js | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/web/share/js/tools.js b/web/share/js/tools.js index 4d082eea..ca31f1f8 100644 --- a/web/share/js/tools.js +++ b/web/share/js/tools.js @@ -253,15 +253,8 @@ export var tools = new function() { self.selector = new function() { return { - "initDefault": function(el, title, value) { - if (el.options.length === 0) { - self.selector.addOption(el, `\u2500 ${title} \u2500`, value); - } else { - el.options.length = 1; - } - }, - "addOption": function(el, title, value) { - el.add(new Option(title, value, false, false)); + "addOption": function(el, title, value, selected=false) { + el.add(new Option(title, value, selected, selected)); }, "addComment": function(el, title) { let option = new Option(title, ".".repeat(30), false, false); // Kinda magic value @@ -274,6 +267,30 @@ export var tools = new function() { self.selector.addComment(el, "\u2500".repeat(30)); } }, + + "setValues": function(el, values, empty_title=null) { + if (values.constructor == Object) { + values = Object.keys(values).sort(); + } + let values_json = JSON.stringify(values); + if (el.__values_json !== values_json) { + el.options.length = 0; + for (let value of values) { + let title = value; + if (title.length === 0 && empty_title !== null) { + title = empty_title; + } + self.selector.addOption(el, title, value); + } + el.__values_json = values_json; + el.__values = values; + } + }, + "setSelectedValue": function(el, value) { + if (el.__values && el.__values.includes(value)) { + el.value = value; + } + }, }; }; |