working on custom prompts #12

This commit is contained in:
mic 2024-05-10 23:57:32 +02:00
parent f459cf72e8
commit e35e954961
3 changed files with 117 additions and 24 deletions

View file

@ -54,6 +54,41 @@
"description": "" "description": ""
}, },
"customPrompts_btnSave": {
"message": "Save All",
"description": ""
},
"customPrompts_btnNew": {
"message": "Add New",
"description": ""
},
"customPrompts_btnAddNewCommit": {
"message": "Add the Prompt",
"description": ""
},
"customPrompts_add_to_menu": {
"message": "Add to menu",
"description": ""
},
"customPrompts_add_to_menu_always": {
"message": "Always",
"description": ""
},
"customPrompts_add_to_menu_reading": {
"message": "Reading an email",
"description": ""
},
"customPrompts_add_to_menu_composing": {
"message": "Composing an email",
"description": ""
},
"chatgpt_win_working": { "chatgpt_win_working": {
"message": "Work in progress...", "message": "Work in progress...",
"description": "" "description": ""

View file

@ -15,17 +15,20 @@
<button id="btnNew">__MSG_customPrompts_btnNew__</button> <button id="btnNew">__MSG_customPrompts_btnNew__</button>
</div> </div>
<div id="formNew"> <div id="formNew">
<label for="txtIdNew">ID:</label>
<input type="text" id="txtIdNew" name="id"> [Must be unique and without spaces]
<br>
<label for="txtNameNew">Name:</label> <label for="txtNameNew">Name:</label>
<input type="text" id="txtNameNew" name="name"> <input type="text" id="txtNameNew" name="name">
<br> <br>
<label for="txtTextNew">Text:</label> <label for="txtTextNew">Text:</label>
<textarea id="txtTextNew" name="text"></textarea> <textarea id="txtTextNew" name="text"></textarea>
<br> <br>
<label for="selectTypeNew">Type:</label> <label for="selectTypeNew">__MSG_customPrompts_add_to_menu__:</label>
<select id="selectTypeNew" name="type"> <select id="selectTypeNew" name="type">
<option value="0">Always show</option> <option value="0">__MSG_customPrompts_add_to_menu_always__</option>
<option value="1">When reading an email</option> <option value="1">__MSG_customPrompts_add_to_menu_reading__</option>
<option value="2">When composing a mail</option> <option value="2">__MSG_customPrompts_add_to_menu_composing__</option>
</select> </select>
<br> <br>
<label for="selectActionNew">Action:</label> <label for="selectActionNew">Action:</label>

View file

@ -19,10 +19,11 @@
import { getPrompts } from "../js/mzta-prompts.js"; import { getPrompts } from "../js/mzta-prompts.js";
var somethingChanged = false; var somethingChanged = false;
var positionMax = 0;
document.addEventListener('DOMContentLoaded', async () => { document.addEventListener('DOMContentLoaded', async () => {
let options = { 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'} ], valueNames: [ { data: ['idnum'] }, 'id', 'name', 'text', 'type', 'action', 'position', { 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: `<tr> // item: `<tr>
// <td class="id"></td> // <td class="id"></td>
// <td class="name"></td> // <td class="name"></td>
@ -45,6 +46,10 @@ document.addEventListener('DOMContentLoaded', async () => {
<td class="name"></td> <td class="name"></td>
<td class="text"></td> <td class="text"></td>
<td class="properties"> <td class="properties">
Type: ` + values.type + `
<br>
Action: ` + values.action + `
<br>
<input type="checkbox" class="need_selected"` + ((values.is_default == 1) ? 'disabled':'') + `> Need Select <input type="checkbox" class="need_selected"` + ((values.is_default == 1) ? 'disabled':'') + `> Need Select
<br> <br>
<input type="checkbox" class="need_signature" ` + ((values.is_default == 1) ? 'disabled':'') + `> Need Signature <input type="checkbox" class="need_signature" ` + ((values.is_default == 1) ? 'disabled':'') + `> Need Signature
@ -59,6 +64,7 @@ document.addEventListener('DOMContentLoaded', async () => {
</td> </td>
</tr>`; </tr>`;
//console.log('>>>>>>>> values.name: ' + JSON.stringify(values.name)); //console.log('>>>>>>>> values.name: ' + JSON.stringify(values.name));
positionMax = Math.max(positionMax, values.position);
return output; return output;
} }
}; };
@ -74,8 +80,9 @@ document.addEventListener('DOMContentLoaded', async () => {
const btnSave = document.getElementById('btnSave'); const btnSave = document.getElementById('btnSave');
btnSave.disabled = true; btnSave.disabled = true;
btnSave.addEventListener('click', (e) => { //TODO btnSave.addEventListener('click', (e) => {
e.preventDefault(); e.preventDefault();
saveAll();
}); });
const btnNew = document.getElementById('btnNew'); const btnNew = document.getElementById('btnNew');
@ -84,11 +91,6 @@ document.addEventListener('DOMContentLoaded', async () => {
document.getElementById('formNew').style.display = 'block'; document.getElementById('formNew').style.display = 'block';
}); });
const btnAddNew = document.getElementById('btnNew');
btnAddNew.addEventListener('click', (e) => { //TODO
e.preventDefault();
});
document.querySelectorAll('input').forEach(element => { document.querySelectorAll('input').forEach(element => {
element.addEventListener('change', (e) => { element.addEventListener('change', (e) => {
e.preventDefault(); e.preventDefault();
@ -109,16 +111,64 @@ document.addEventListener('DOMContentLoaded', async () => {
} }
i18n.updateDocument(); i18n.updateDocument();
//To add a new item
var txtIdNew = document.getElementById('txtIdNew');
var txtNameNew = document.getElementById('txtNameNew');
var txtTextNew = document.getElementById('txtTextNew');
var selectTypeNew = document.getElementById('selectTypeNew');
var selectActionNew = document.getElementById('selectActionNew');
var selectNeedSelectedNew = document.getElementById('selectNeedSelectedNew');
var selectNeedSignatureNew = document.getElementById('selectNeedSignatureNew');
var selectNeedCustomTextNew = document.getElementById('selectNeedCustomTextNew');
const btnAddNew = document.getElementById('btnAddNew');
btnAddNew.addEventListener('click', (e) => { //TODO
e.preventDefault();
//TODO check the id must be unique and without spaces
promptsList.add({
id: txtIdNew.value,
name: txtNameNew.value,
text: txtTextNew.value,
type: selectTypeNew.value,
action: selectActionNew.value,
need_selected: selectNeedSelectedNew.value,
need_signature: selectNeedSignatureNew.value,
need_custom_text: selectNeedCustomTextNew.value,
enabled: 1,
position: positionMax + 1,
is_default: 0,
});
//checkSelectedBoxes([selectTypeNew, selectActionNew, selectNeedSelectedNew, selectNeedSignatureNew, selectNeedCustomTextNew]);
checkSelectedBoxes();
clearFields();
});
}, { once: true }); }, { once: true });
function checkSelectedBoxes() { function clearFields() {
const checkboxes = [ document.getElementById('txtIdNew').value = '';
...document.querySelectorAll('.need_selected[type="checkbox"]'), document.getElementById('txtNameNew').value = '';
...document.querySelectorAll('.need_signature[type="checkbox"]'), document.getElementById('txtTextNew').value = '';
...document.querySelectorAll('.need_custom_text[type="checkbox"]'), document.getElementById('selectTypeNew').value = '0';
...document.querySelectorAll('.enabled[type="checkbox"]'), document.getElementById('selectActionNew').value = '0';
]; document.getElementById('selectNeedSelectedNew').value = '0';
document.getElementById('selectNeedSignatureNew').value = '0';
document.getElementById('selectNeedCustomTextNew').value = '0';
document.getElementById('formNew').style.display = 'none';
}
function checkSelectedBoxes(checkboxes = null) {
if(checkboxes == null){
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 // Iterate through the checkboxes
checkboxes.forEach(checkbox => { checkboxes.forEach(checkbox => {
@ -132,9 +182,14 @@ function checkSelectedBoxes() {
}); });
} }
window.addEventListener('beforeunload', function (event) { //Save all prompts
// Check if any changes have been made function saveAll() {
if (somethingChanged) { //TODO
event.preventDefault(); }
}
}); // window.addEventListener('beforeunload', function (event) {
// // Check if any changes have been made
// if (somethingChanged) {
// event.preventDefault();
// }
// });