diff --git a/src/js/rulesAssistantOptions.js b/src/js/rulesAssistantOptions.js index c029e0a34fac2ca11febceacb2fe04063eb3465e..261fe8c59d0676310191a168179182bc4cecb745 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())));