From 5f7320776e15e7a9209b85f642fdcba0e482f217 Mon Sep 17 00:00:00 2001 From: ezsh <ezsh.junk@gmail.com> Date: Thu, 6 Jun 2019 15:04:19 +0200 Subject: [PATCH] Add StringEditor to RA options Closes #811. --- src/js/DefaultRules.js | 8 ++++---- src/js/rulesAssistantOptions.js | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/js/DefaultRules.js b/src/js/DefaultRules.js index 6be91a86737..4bfa944f578 100644 --- a/src/js/DefaultRules.js +++ b/src/js/DefaultRules.js @@ -2905,15 +2905,15 @@ window.DefaultRules = (function() { /** * @param {App.Entity.SlaveState} slave - * @param {object} rule + * @param {App.RA.RuleSetters} rule */ function ProcessLabel(slave, rule) { - if (rule.label !== null && !slave.custom.label.includes(`[${rule.label}]`)) { - slave.custom.label = `${slave.custom.label }[${ rule.label }]`; + if (rule.label !== null && rule.label !== '' && !slave.custom.label.includes(`[${rule.label}]`)) { + slave.custom.label = `${slave.custom.label}[${rule.label}]`; r += `<br>${slave.slaveName} has been tagged as ${rule.label}`; } - if (rule.removeLabel !== null && slave.custom.label.includes(`[${rule.removeLabel}]`)) { + if (rule.removeLabel !== null && rule.removeLabel !== '' && slave.custom.label.includes(`[${rule.removeLabel}]`)) { slave.custom.label = slave.custom.label.replace(`[${rule.removeLabel}]`, ""); r += `<br>${slave.slaveName}'s tag [${rule.removeLabel}] is removed.`; } diff --git a/src/js/rulesAssistantOptions.js b/src/js/rulesAssistantOptions.js index 050e909e70c..16871bd1809 100644 --- a/src/js/rulesAssistantOptions.js +++ b/src/js/rulesAssistantOptions.js @@ -386,6 +386,34 @@ window.rulesAssistantOptions = (function() { } } + class StringEditor extends EditorWithShortcuts { + constructor(prefix, data = [], allowNullValue = true, capitalizeShortcuts = true) { + super(prefix, data, allowNullValue, true, capitalizeShortcuts); + } + + createEditor() { + let res = document.createElement("input"); + res.setAttribute("type", "text"); + res.classList.add("rajs-value"); // + // call the variable binding when the input field is no longer being edited, and when the enter key is pressed + res.onblur = () => { + this.inputEdited(); + }; + res.onkeypress = (e) => { + if (returnP(e)) { this.inputEdited(); } + }; + return res; + } + + getData() { + return this.value.value; + } + + setValue(what) { + this.value.value = what; + } + } + class NumberRange extends EditorWithShortcuts { /** * @param {string} prefix @@ -3631,7 +3659,7 @@ window.rulesAssistantOptions = (function() { } } - class LabelList extends List { + class LabelList extends StringEditor { constructor() { super("Custom label", [], true, true); this.setValue(current_rule.set.label); @@ -3639,7 +3667,7 @@ window.rulesAssistantOptions = (function() { } } - class LabelRemoveList extends List { + class LabelRemoveList extends StringEditor { constructor() { super("Remove custom label", [], true, true); this.setValue(current_rule.set.removeLabel); -- GitLab