diff --git a/customprompts/mzta-custom-prompts.css b/customprompts/mzta-custom-prompts.css index ca159d22..ec9f384c 100644 --- a/customprompts/mzta-custom-prompts.css +++ b/customprompts/mzta-custom-prompts.css @@ -45,3 +45,11 @@ table td { table td.properties{ white-space: nowrap; } + +.hiddendata{ + display: none; +} + +#formNew{ + display: none; +} \ No newline at end of file diff --git a/customprompts/mzta-custom-prompts.html b/customprompts/mzta-custom-prompts.html index a7cc8a2d..5ced4648 100644 --- a/customprompts/mzta-custom-prompts.html +++ b/customprompts/mzta-custom-prompts.html @@ -10,14 +10,60 @@

Manage Prompts

Manage your custom prompts.

+
+ + +
+
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ +
- - - + + + + diff --git a/customprompts/mzta-custom-prompts.js b/customprompts/mzta-custom-prompts.js index 378a4400..f509c611 100644 --- a/customprompts/mzta-custom-prompts.js +++ b/customprompts/mzta-custom-prompts.js @@ -16,31 +16,55 @@ * along with this program. If not, see . */ -import { defaultPrompts } from "../js/mzta-prompts.js"; +import { getPrompts } from "../js/mzta-prompts.js"; + +var somethingChanged = false; document.addEventListener('DOMContentLoaded', async () => { let options = { - valueNames: [ '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: 'enabled_val'} ], - item: ` - - - - - ` + 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: ` + // + // + // + // + // ` + item: function(values) { + let output = ` + + + + + + `; + //console.log('>>>>>>>> values.name: ' + JSON.stringify(values.name)); + return output; + } }; - let values = defaultPrompts; // test in browser - //let values = await getPrompts(); // production + //let values = getDefaultPrompts_withProps; // test in browser + let values = await getPrompts(); // production console.log('>>>>>>>>>>>>>>>> values: ' + JSON.stringify(values)); @@ -48,16 +72,52 @@ document.addEventListener('DOMContentLoaded', async () => { checkSelectedBoxes(); - //i18n.updateDocument(); // production + 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() { - // Get all elements with the class 'need_selected' that are checkboxes 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 @@ -70,4 +130,11 @@ function checkSelectedBoxes() { checkbox.checked = true; } }); -} \ No newline at end of file +} + +window.addEventListener('beforeunload', function (event) { + // Check if any changes have been made + if (somethingChanged) { + event.preventDefault(); + } +}); \ No newline at end of file diff --git a/js/mzta-prompts.js b/js/mzta-prompts.js index 8a617f64..8d43b01a 100644 --- a/js/mzta-prompts.js +++ b/js/mzta-prompts.js @@ -54,8 +54,7 @@ */ -export const defaultPrompts = [ // test in browser -//const defaultPrompts = [ // production +const defaultPrompts = [ { id: 'prompt_reply', name: "__MSG_prompt_reply__", @@ -141,13 +140,18 @@ export async function getPrompts(){ const customPrompts = await getCustomPrompts(); let output = defaultPrompts.concat(customPrompts); output.sort((a, b) => a.position - b.position); + for(let i=1; i<=output.length; i++){ + output[i-1].idnum = i; + } return output; } async function getDefaultPrompts_withProps() { - let prefs = await browser.storage.sync.get({_default_prompts_properties: null}); + // let prefs = await browser.storage.sync.get({_default_prompts_properties: null}); //production let defaultPrompts_prop = [...defaultPrompts]; + let prefs = {}; //test + prefs._default_prompts_properties = null; //test if(prefs._default_prompts_properties === null){ // no default prompts properties saved let pos = 1; defaultPrompts_prop.forEach((prompt) => {
IDNameTextIDNameText PropertiesAction
- Need Select -
- Need Signature -
- Need Custom Text -
- Is Default -
- Enabled -
+ // Need Select + //
+ // Need Signature + //
+ // Need Custom Text + //
+ // Is Default + //
+ // Enabled + //
+ Need Select +
+ Need Signature +
+ Need Custom Text +
+ Enabled + is_default +
+ ` + ((values.is_default == 0) ? '':'') + ` +