Add dirty check to all remaining editor modals
Subclass Modal with snapshotValues() for: value source editor, audio source editor, add device, profile editor, capture template, stream editor, and PP template modals. Close/cancel now triggers discard confirmation when form has unsaved changes. Document the convention in CLAUDE.md. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -9,7 +9,21 @@ import { showToast, showConfirm } from '../core/ui.js';
|
||||
import { Modal } from '../core/modal.js';
|
||||
import { CardSection } from '../core/card-sections.js';
|
||||
|
||||
const profileModal = new Modal('profile-editor-modal');
|
||||
class ProfileEditorModal extends Modal {
|
||||
constructor() { super('profile-editor-modal'); }
|
||||
|
||||
snapshotValues() {
|
||||
return {
|
||||
name: document.getElementById('profile-editor-name').value,
|
||||
enabled: document.getElementById('profile-editor-enabled').checked.toString(),
|
||||
logic: document.getElementById('profile-editor-logic').value,
|
||||
conditions: JSON.stringify(getProfileEditorConditions()),
|
||||
targets: JSON.stringify(getProfileEditorTargetIds()),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const profileModal = new ProfileEditorModal();
|
||||
const csProfiles = new CardSection('profiles', { titleKey: 'profiles.title', gridClass: 'devices-grid', addCardOnclick: "openProfileEditor()" });
|
||||
|
||||
// Re-render profiles when language changes (only if tab is active)
|
||||
@@ -176,10 +190,11 @@ export async function openProfileEditor(profileId) {
|
||||
modal.querySelectorAll('[data-i18n]').forEach(el => {
|
||||
el.textContent = t(el.getAttribute('data-i18n'));
|
||||
});
|
||||
profileModal.snapshot();
|
||||
}
|
||||
|
||||
export function closeProfileEditorModal() {
|
||||
profileModal.forceClose();
|
||||
export async function closeProfileEditorModal() {
|
||||
await profileModal.close();
|
||||
}
|
||||
|
||||
async function loadProfileTargetChecklist(selectedIds) {
|
||||
|
||||
Reference in New Issue
Block a user