1import { Controller } from '@hotwired/stimulus'; 2import { railsT } from 'utils/rails_i18n'; 3 4export default class extends Controller { 5 static targets = ['template', 'templateInput', 'modal', 'iframe']; 6 7 connect() { 8 if (this.hasTemplateTarget) { 9 this.updateTemplateInput(); 10 this.templateTarget.addEventListener('change', () => this.updateTemplateInput()); 11 } 12 } 13 14 updateTemplateInput() { 15 if (this.hasTemplateInputTarget && this.hasTemplateTarget) { 16 this.templateInputTarget.value = this.templateTarget.value; 17 } 18 } 19 20 preview(event) { 21 if (!this.hasTemplateTarget || !this.hasIframeTarget || !this.hasModalTarget) return; 22 23 const template = this.templateTarget.value; 24 25 let userId = window.location.pathname 26 .split('/') 27 .filter((p) => p !== '') 28 .pop(); 29 30 if (userId === 'users') { 31 const firstRow = document.querySelector('tbody tr'); 32 if (firstRow) { 33 const manageLink = firstRow.querySelector('a[href*="/admin/users/"]'); 34 if (manageLink) { 35 userId = manageLink.getAttribute('href').split('/').pop(); 36 } 37 } 38 } 39 40 const url = 41 userId && userId !== 'users' 42 ? `/admin/users/${userId}/preview_email?template=${template}` 43 : `/admin/users/preview_email?template=${template}`; 44 45 if (userId && userId !== 'users') { 46 this.iframeTarget.src = url; 47 this.modalTarget.classList.remove('hidden'); 48 } else { 49 console.error('Could not determine User ID for preview'); 50 const msg = railsT('noUsersForPreview', 'No hay usuarios en la lista para la vista previa.'); 51 52 if (window.MiQR && typeof window.MiQR.showError === 'function') { 53 window.MiQR.showError(msg); 54 } else { 55 alert(msg); 56 } 57 } 58 } 59 60 close() { 61 if (this.hasModalTarget) this.modalTarget.classList.add('hidden'); 62 if (this.hasIframeTarget) this.iframeTarget.src = ''; 63 } 64}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.