Add QR set rename button
| @@ -46,6 +46,7 @@ | |||
| 46 | <div class="qr--title" data-i18n="Edit Quick Replies">Edit Quick Replies</div> | 46 | <div class="qr--title" data-i18n="Edit Quick Replies">Edit Quick Replies</div> |
| 47 | <div class="qr--actions"> | 47 | <div class="qr--actions"> |
| 48 | <select id="qr--set" class="text_pole"></select> | 48 | <select id="qr--set" class="text_pole"></select> |
| 49 | <div class="qr--add menu_button menu_button_icon fa-solid fa-pencil" id="qr--set-rename" title="Rename quick reply set"></div> | ||
| 49 | <div class="qr--add menu_button menu_button_icon fa-solid fa-plus" id="qr--set-new" title="Create new quick reply set"></div> | 50 | <div class="qr--add menu_button menu_button_icon fa-solid fa-plus" id="qr--set-new" title="Create new quick reply set"></div> |
| 50 | <div class="qr--add menu_button menu_button_icon fa-solid fa-file-import" id="qr--set-import" title="Import quick reply set"></div> | 51 | <div class="qr--add menu_button menu_button_icon fa-solid fa-file-import" id="qr--set-import" title="Import quick reply set"></div> |
| 51 | <input type="file" id="qr--set-importFile" accept=".json" hidden> | 52 | <input type="file" id="qr--set-importFile" accept=".json" hidden> |
| @@ -111,6 +111,7 @@ export class SettingsUi { | |||
| 111 | 111 | ||
| 112 | prepareQrEditor() { | 112 | prepareQrEditor() { |
| 113 | // qr editor | 113 | // qr editor |
| 114 | this.dom.querySelector('#qr--set-rename').addEventListener('click', async () => this.renameQrSet()); | ||
| 114 | this.dom.querySelector('#qr--set-new').addEventListener('click', async()=>this.addQrSet()); | 115 | this.dom.querySelector('#qr--set-new').addEventListener('click', async()=>this.addQrSet()); |
| 115 | /**@type {HTMLInputElement}*/ | 116 | /**@type {HTMLInputElement}*/ |
| 116 | const importFile = this.dom.querySelector('#qr--set-importFile'); | 117 | const importFile = this.dom.querySelector('#qr--set-importFile'); |
| @@ -303,6 +304,44 @@ export class SettingsUi { | |||
| 303 | this.settings.save(); | 304 | this.settings.save(); |
| 304 | } | 305 | } |
| 305 | 306 | ||
| 307 | async renameQrSet() { | ||
| 308 | const newName = await callPopup('Enter new name for the Quick Reply Set:', 'input'); | ||
| 309 | if (newName && newName.length > 0) { | ||
| 310 | const existingSet = QuickReplySet.get(newName); | ||
| 311 | if (existingSet) { | ||
| 312 | toastr.error(`A Quick Reply Set named "${newName}" already exists.`); | ||
| 313 | return; | ||
| 314 | } | ||
| 315 | const oldName = this.currentQrSet.name; | ||
| 316 | this.currentQrSet.name = newName; | ||
| 317 | await this.currentQrSet.save(); | ||
| 318 | |||
| 319 | // Update the option in all select dropdowns | ||
| 320 | /** @type {NodeListOf<HTMLOptionElement>} */ | ||
| 321 | const options = this.dom.querySelectorAll(`#qr--set option[value="${oldName}"], select.qr--set option[value="${oldName}"]`); | ||
| 322 | options.forEach(option => { | ||
| 323 | option.value = newName; | ||
| 324 | option.textContent = newName; | ||
| 325 | }); | ||
| 326 | |||
| 327 | // Update in in both set lists | ||
| 328 | this.settings.config.setList.forEach(set => { | ||
| 329 | if (set.set.name === oldName) { | ||
| 330 | set.set.name = newName; | ||
| 331 | } | ||
| 332 | }); | ||
| 333 | this.settings.chatConfig?.setList.forEach(set => { | ||
| 334 | if (set.set.name === oldName) { | ||
| 335 | set.set.name = newName; | ||
| 336 | } | ||
| 337 | }); | ||
| 338 | |||
| 339 | this.settings.save(); | ||
| 340 | this.currentSet.value = newName; | ||
| 341 | console.info(`Quick Reply Set renamed from ""${oldName}" to "${newName}".`); | ||
| 342 | } | ||
| 343 | } | ||
| 344 | |||
| 306 | async addQrSet() { | 345 | async addQrSet() { |
| 307 | const name = await callPopup('Quick Reply Set Name:', 'input'); | 346 | const name = await callPopup('Quick Reply Set Name:', 'input'); |
| 308 | if (name && name.length > 0) { | 347 | if (name && name.length > 0) { |