/* * ThunderAI [https://micz.it/thunderdbird-addon-thunderai/] * Copyright (C) 2024 Mic (m@micz.it) * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ import { getPrompts } from "../js/mzta-prompts.js"; var somethingChanged = false; document.addEventListener('DOMContentLoaded', async () => { let options = { valueNames: [ { data: ['idnum'] }, 'id', 'name', 'text', 'type', 'action', { name: 'need_selected', attr: 'checked_val'}, { name: 'need_signature', attr: 'checked_val'}, { name: 'need_custom_text', attr: 'checked_val'}, { name: 'is_default', attr: 'is_default_val'}, { name: 'enabled', attr: 'checked_val'} ], // item: ` // // // // // Need Select //
// Need Signature //
// Need Custom Text //
// Is Default //
// Enabled // // ` item: function(values) { let output = ` Need Select
Need Signature
Need Custom Text
Enabled is_default ` + ((values.is_default == 0) ? '':'') + ` `; //console.log('>>>>>>>> values.name: ' + JSON.stringify(values.name)); return output; } }; //let values = getDefaultPrompts_withProps; // test in browser let values = await getPrompts(); // production console.log('>>>>>>>>>>>>>>>> values: ' + JSON.stringify(values)); let promptsList = new List('all_prompts', options, values); checkSelectedBoxes(); const btnSave = document.getElementById('btnSave'); btnSave.disabled = true; btnSave.addEventListener('click', (e) => { //TODO e.preventDefault(); }); const btnNew = document.getElementById('btnNew'); btnNew.addEventListener('click', (e) => { e.preventDefault(); document.getElementById('formNew').style.display = 'block'; }); const btnAddNew = document.getElementById('btnNew'); btnAddNew.addEventListener('click', (e) => { //TODO e.preventDefault(); }); document.querySelectorAll('input').forEach(element => { element.addEventListener('change', (e) => { e.preventDefault(); btnSave.disabled = false; somethingChanged = true; }); }) let btnEdit_elements = document.querySelectorAll(".btnEdit") if(btnEdit_elements) { btnEdit_elements.forEach(element => { element.addEventListener('click', (e) => { e.preventDefault(); const tr = e.target.parentNode.parentNode; //TODO console.log('>>>>>>>> tr: ' + tr.getAttribute('data-idnum')); }); }); } i18n.updateDocument(); }, { once: true }); function checkSelectedBoxes() { const checkboxes = [ ...document.querySelectorAll('.need_selected[type="checkbox"]'), ...document.querySelectorAll('.need_signature[type="checkbox"]'), ...document.querySelectorAll('.need_custom_text[type="checkbox"]'), ...document.querySelectorAll('.enabled[type="checkbox"]'), ]; // Iterate through the checkboxes checkboxes.forEach(checkbox => { // Check if the 'checked' attribute is "0" if (checkbox.getAttribute('checked_val') === "0") { // Uncheck the checkbox checkbox.checked = false; } else { checkbox.checked = true; } }); } window.addEventListener('beforeunload', function (event) { // Check if any changes have been made if (somethingChanged) { event.preventDefault(); } });