From ccf03f3486000ea1327657ef5fc9986acfecc765 Mon Sep 17 00:00:00 2001 From: Arkerthan <arkerthan@mailbox.org> Date: Sun, 11 Sep 2022 18:04:23 +0200 Subject: [PATCH] Allow duplicating rules --- src/js/rulesAssistantOptions.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/js/rulesAssistantOptions.js b/src/js/rulesAssistantOptions.js index c029e0a34fa..261fe8c59d0 100644 --- a/src/js/rulesAssistantOptions.js +++ b/src/js/rulesAssistantOptions.js @@ -87,11 +87,22 @@ App.RA.options = (function() { } function changeName(name) { - if (name === current_rule.name) { return; } + if (name === current_rule.name) { + return; + } current_rule.name = name; reload(); } + function duplicate() { + const clonedRule = _.cloneDeep(current_rule); + clonedRule.ID = generateNewID(); + clonedRule.name = `Copy of ${clonedRule.name}`; + V.currentRule = clonedRule.ID; + V.defaultRules.push(clonedRule); + reload(); + } + // reload the passage function reload() { saveSettings(); @@ -105,7 +116,7 @@ App.RA.options = (function() { * Save the settings for this rule. */ function saveSettings() { - if(current_rule){ + if (current_rule) { App.RA.Activation.Editor.save(current_rule.condition); } } @@ -1244,6 +1255,7 @@ App.RA.options = (function() { this.appendChild(new OptionsItem("Lower Priority", lowerPriority)); this.appendChild(new OptionsItem("Higher Priority", higherPriority)); this.appendChild(new OptionsItem("Rename", rename(this))); + this.appendChild(new OptionsItem("Duplicate", duplicate)); this.appendChild(new OptionsItem("Export this rule", () => this.appendChild(new ExportField(current_rule)))); this.appendChild(new OptionsItem("Export all rules", () => this.appendChild(new ExportField(...V.defaultRules)))); this.appendChild(new OptionsItem("Import rule(s)", () => this.appendChild(new NewRuleField()))); -- GitLab