| 460 | 461 | URL.revokeObjectURL(url); |
| 461 | 462 | } |
| 462 | 463 | |
| 464 | + async duplicateQrSet() { |
| 465 | + const newName = await Popup.show.input('Duplicate Quick Reply Set', 'Enter a name for the new Quick Reply Set:', `${this.currentQrSet.name} (Copy)`); |
| 466 | + if (newName && newName.length > 0) { |
| 467 | + const existingSet = QuickReplySet.get(newName); |
| 468 | + if (existingSet) { |
| 469 | + toastr.error(`A Quick Reply Set named "${newName}" already exists.`); |
| 470 | + return; |
| 471 | + } |
| 472 | + const newQrSet = QuickReplySet.from(JSON.parse(JSON.stringify(this.currentQrSet))); |
| 473 | + newQrSet.name = newName; |
| 474 | + newQrSet.qrList = this.currentQrSet.qrList.map(qr => QuickReply.from(JSON.parse(JSON.stringify(qr)))); |
| 475 | + newQrSet.addQuickReply(); |
| 476 | + const idx = QuickReplySet.list.findIndex(it => it.name.toLowerCase().localeCompare(newName.toLowerCase()) == 1); |
| 477 | + if (idx > -1) { |
| 478 | + QuickReplySet.list.splice(idx, 0, newQrSet); |
| 479 | + } else { |
| 480 | + QuickReplySet.list.push(newQrSet); |
| 481 | + } |
| 482 | + const opt = document.createElement('option'); { |
| 483 | + opt.value = newQrSet.name; |
| 484 | + opt.textContent = newQrSet.name; |
| 485 | + if (idx > -1) { |
| 486 | + this.currentSet.children[idx].insertAdjacentElement('beforebegin', opt); |
| 487 | + } else { |
| 488 | + this.currentSet.append(opt); |
| 489 | + } |
| 490 | + } |
| 491 | + this.currentSet.value = newName; |
| 492 | + this.onQrSetChange(); |
| 493 | + this.prepareGlobalSetList(); |
| 494 | + this.prepareChatSetList(); |
| 495 | + } |
| 496 | + } |
| 497 | + |
| 463 | 498 | selectQrSet(qrs) { |
| 464 | 499 | this.currentSet.value = qrs.name; |
| 465 | 500 | this.onQrSetChange(); |