tried some url control

This commit is contained in:
maru21 2023-11-01 19:39:59 +01:00
parent 89a44377c9
commit 6c362693da
5 changed files with 159 additions and 77 deletions

View File

@ -38,14 +38,14 @@
style="width: 300px; margin-top: 51px; padding-top: 12px" style="width: 300px; margin-top: 51px; padding-top: 12px"
id="sidebar" id="sidebar"
> >
<ul class="w3-ul"> <ul class="w3-ul" style="padding-top: 1px;">
<li <!-- <li
class="w3-bar-item w3-padding-large w3-button" class="w3-bar-item w3-padding-large w3-button"
style="border-bottom: 1px solid rgb(221, 221, 221)" style="border-bottom: 1px solid rgb(221, 221, 221)"
id="loadTemplateBtn" id="loadTemplateBtn"
> >
Load new template Load new template
</li> </li> -->
<li <li
class="w3-bar-item w3-padding-large w3-button" class="w3-bar-item w3-padding-large w3-button"
style="border-bottom: 1px solid rgb(221, 221, 221)" style="border-bottom: 1px solid rgb(221, 221, 221)"
@ -91,7 +91,7 @@
href="javascript:void(0);" href="javascript:void(0);"
title="Toggle Textblocks Menu" title="Toggle Textblocks Menu"
id="toggleTestBlocksMenu" id="toggleTestBlocksMenu"
style="display: none;" style="display: none"
><i class="fa fa-plane"></i ><i class="fa fa-plane"></i
></a> ></a>
<a <a
@ -103,7 +103,7 @@
></a> ></a>
<a <a
id="logo" id="logo"
href="." href="javascript:void(0)"
class="w3-left-align w3-button w3-padding-large w3-flat-wet-asphalt" class="w3-left-align w3-button w3-padding-large w3-flat-wet-asphalt"
><img class="logo" src="logo.png" alt="logo" height="30px" ><img class="logo" src="logo.png" alt="logo" height="30px"
/></a> /></a>
@ -124,7 +124,7 @@
<div <div
id="mainForm" id="mainForm"
class="w3-row-padding w3-padding-top-64 w3-container w3-flat-clouds" class="w3-row-padding w3-padding-top-64 w3-container w3-flat-clouds"
style="min-height: 600px;" style="min-height: 600px"
> >
<div class="w3-content"> <div class="w3-content">
<div class="w3-third w3-center"> <div class="w3-third w3-center">
@ -175,9 +175,9 @@
</li> </li>
<li> <li>
<b>For one word which needs to change:</b><br /> <b>For one word which needs to change:</b><br />
<code class="w3-codespan">%Sample Word%1</code><br> <code class="w3-codespan">%Sample Word%1</code><br />
Use <code class="w3-codespan">%</code> at the start and end Use <code class="w3-codespan">%</code> at the start and end
position of the placeholder<br> position of the placeholder<br />
Set <code class="w3-codespan">1</code> as priority or any other Set <code class="w3-codespan">1</code> as priority or any other
number up until <code class="w3-codespan">99</code> number up until <code class="w3-codespan">99</code>
</li> </li>
@ -191,23 +191,26 @@
<code class="w3-codespan">Sample Expression=</code> placeholder <code class="w3-codespan">Sample Expression=</code> placeholder
name<br /> name<br />
Set <code class="w3-codespan">1</code> as priority or any other Set <code class="w3-codespan">1</code> as priority or any other
number up until <code class="w3-codespan">99</code> <br> number up until <code class="w3-codespan">99</code> <br />
Config <code class="w3-codespan">hiddenField</code> like so: Config <code class="w3-codespan">hiddenField</code> like so:
<br /> <br />
<code class="w3-codespan" <code class="w3-codespan"
>%Sample Expression=hiddenField:id:longText:!l%1</code >%Sample Expression=hiddenField:id:longText:!l%1</code
><br> ><br />
in this example <code class="w3-codespan">longText:!l</code> can in this example <code class="w3-codespan">longText:!l</code> can
also be omitted.<br /> also be omitted.<br />
With <code class="w3-codespan">longText</code> you can add With <code class="w3-codespan">longText</code> you can add
markups like <code class="w3-codespan">!l</code> by adding them markups like <code class="w3-codespan">!l</code> by adding them
like this:<br> like this:<br />
<code class="w3-codespan" <code class="w3-codespan"
>%Sample Expression=longText:!l%1</code >%Sample Expression=longText:!l%1</code
> >
</li> </li>
<li> <li>
<b>Use field types like longText or markup to customize further</b> <b
>Use field types like longText or markup to customize
further</b
>
These are all the different Field types:<br /> These are all the different Field types:<br />
<code class="w3-codespan">simpleInput</code><br /> <code class="w3-codespan">simpleInput</code><br />
<code class="w3-codespan">longText</code><br /> <code class="w3-codespan">longText</code><br />
@ -237,12 +240,17 @@
</li> </li>
<li> <li>
<b>For dropdown lists:</b><br /> <b>For dropdown lists:</b><br />
Use <code class="w3-codespan">%Sample Expression=l:item 1;l:item 2;%1</code> for each item Use
<code class="w3-codespan"
>%Sample Expression=l:item 1;l:item 2;%1</code
>
for each item
</li> </li>
<li> <li>
<b>For hidden fields and its trigger:</b><br /> <b>For hidden fields and its trigger:</b><br />
Use Use
<code class="w3-codespan">%Sample Expression=h:itemid 1:fieldtype:formatting;%1</code <code class="w3-codespan"
>%Sample Expression=h:itemid 1:fieldtype:formatting;%1</code
><br /> ><br />
You can also have multiple hidden fields selectable by a list You can also have multiple hidden fields selectable by a list
</li> </li>
@ -269,9 +277,9 @@
<div class="w3-container w3-flat-clouds w3-padding"> <div class="w3-container w3-flat-clouds w3-padding">
<div <div
id="outputInfo" id="outputInfo"
class="w3-row-padding w3-padding-64 w3-container w3-flat-clouds" class="w3-row-padding w3-padding-64 w3-container w3-flat-clouds"
style="margin-bottom: 0px; display: none" style="margin-bottom: 0px; display: none"
></div> ></div>
<div <div
id="output" id="output"
@ -320,11 +328,7 @@
> >
<p> <p>
wrong password - would you like to wrong password - would you like to
<a <a href="#" style="text-decoration: underline">clear</a>
href="#"
style="text-decoration: underline"
>clear</a
>
all files? all files?
</p> </p>
</div> </div>
@ -355,7 +359,10 @@
<footer <footer
class="w3-container w3-padding w3-flat-clouds w3-center w3-margin-top" class="w3-container w3-padding w3-flat-clouds w3-center w3-margin-top"
> >
<div class="w3-container w3-margin-top w3-right-align w3-small" id="currentVersion"> <div
class="w3-container w3-margin-top w3-right-align w3-small"
id="currentVersion"
>
<span></span> <span></span>
</div> </div>
</footer> </footer>

View File

@ -1,13 +1,10 @@
import { import { passwordHash } from "./scripts.js";
clearData, import { clearData, createBookShelf, importBookShelf } from "./storage.js";
createBookShelf,
importBookShelf,
} from "./storage.js";
import { import {
loadTemplate, loadTemplate,
storeFilesToServer, storeFilesToServer,
checkForStoredDataOnServer, checkForStoredDataOnServer,
delStoredDataOnServer delStoredDataOnServer,
} from "./web.js"; } from "./web.js";
function showMenu() { function showMenu() {
@ -59,13 +56,18 @@ function insertTextBlocks(t) {
if (element === null) { if (element === null) {
return; return;
} }
element.value += " "+insert; element.value += " " + insert;
let tB = document.getElementById("navTb"); let tB = document.getElementById("navTb");
tB.className.replace(" w3-show", ""); tB.className.replace(" w3-show", "");
if (element.parentElement != undefined) { if (element.parentElement != undefined) {
if (element.parentElement.getElementsByClassName("pell-content")[0] != undefined) { if (
element.parentElement.getElementsByClassName("pell-content")[0].innerHTML = element.value; element.parentElement.getElementsByClassName("pell-content")[0] !=
undefined
) {
element.parentElement.getElementsByClassName(
"pell-content"
)[0].innerHTML = element.value;
element = element.parentElement.getElementsByClassName("pell-content")[0]; element = element.parentElement.getElementsByClassName("pell-content")[0];
} }
} }
@ -133,7 +135,7 @@ function printVersion(msg = "") {
let pathVersion = source.split("/"); let pathVersion = source.split("/");
pathVersion = pathVersion[pathVersion.length - 2]; pathVersion = pathVersion[pathVersion.length - 2];
//add it to document footer currentVersion //add it to document footer currentVersion
versionSpan.textContent = msg+" version: " + pathVersion; versionSpan.textContent = msg + " version: " + pathVersion;
} }
} }
} }
@ -158,32 +160,40 @@ function clickImportFiles() {
case "Yes": case "Yes":
importBookShelf(); importBookShelf();
modal.replaceWith(modal.cloneNode(true)); modal.replaceWith(modal.cloneNode(true));
modalNotifier("Imported!", activeState.settings.notifierPause); modalNotifier(
"Imported!",
activeState.settings.notifierPause
);
break; break;
case "Cancel": case "Cancel":
modal.replaceWith(modal.cloneNode(true)); modal.replaceWith(modal.cloneNode(true));
document.getElementById("modalNotifier").style.display = "none"; document.getElementById("modalNotifier").style.display =
"none";
break; break;
default: default:
e.preventDefault; e.preventDefault;
} }
} }
}) });
modalNotifier( modalNotifier(
"<div class='w3-container'> \ "<div class='w3-container'> \
Would you like to import the backup created on: "+activeState.serverFilesTs.replace("_", " - ")+ "<br><br> \ Would you like to import the backup created on: " +
activeState.serverFilesTs.replace("_", " - ") +
"<br><br> \
<button class='w3-button w3-border w3-flat-wet-asphalt' >Yes</button> \ <button class='w3-button w3-border w3-flat-wet-asphalt' >Yes</button> \
<button class='w3-button w3-border w3-flat-wet-asphalt' >Cancel</button></div>", <button class='w3-button w3-border w3-flat-wet-asphalt' >Cancel</button></div>",
0); 0
);
break; break;
case "Save": case "Save":
storeFilesToServer(createBookShelf()); storeFilesToServer(createBookShelf());
modal.replaceWith(modal.cloneNode(true)); modal.replaceWith(modal.cloneNode(true));
modalNotifier( modalNotifier(
"Files saved to server <br><br> would you like to <a href='/storage/" + "Files saved to server <br><br> would you like to <a href='/storage/" +
activeState.userId + activeState.userId +
".txt' style='text-decoration: underline;' download>download</a> them?" ".txt' style='text-decoration: underline;' download>download</a> them?",
,0); 0
);
break; break;
case "Delete": case "Delete":
delStoredDataOnServer(); delStoredDataOnServer();
@ -202,19 +212,23 @@ function clickImportFiles() {
<button style='display: none;' id='importModalBtn' class='w3-button w3-border w3-flat-wet-asphalt' >Import</button> \ <button style='display: none;' id='importModalBtn' class='w3-button w3-border w3-flat-wet-asphalt' >Import</button> \
<button class='w3-button w3-border w3-flat-wet-asphalt' >Save</button> \ <button class='w3-button w3-border w3-flat-wet-asphalt' >Save</button> \
<button class='w3-button w3-border w3-flat-pomegranate' >Delete</button></div>", <button class='w3-button w3-border w3-flat-pomegranate' >Delete</button></div>",
0); 0
);
} }
function createBookShelfDownload() { function createBookShelfDownload() {
let data = createBookShelf(); let data = createBookShelf();
let filename = data[0]['data'] + ".txt"; let filename = data[0]["data"] + ".txt";
document.getElementById("modalMsg").addEventListener("click", (e) => { document.getElementById("modalMsg").addEventListener("click", (e) => {
if (e.target && e.target.tagName === "BUTTON") { if (e.target && e.target.tagName === "BUTTON") {
var element = document.createElement('a'); var element = document.createElement("a");
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(JSON.stringify(data))); element.setAttribute(
element.setAttribute('download', filename); "href",
element.style.display = 'none'; "data:text/plain;charset=utf-8," +
encodeURIComponent(JSON.stringify(data))
);
element.setAttribute("download", filename);
element.style.display = "none";
document.body.appendChild(element); document.body.appendChild(element);
element.click(); element.click();
document.body.removeChild(element); document.body.removeChild(element);
@ -224,23 +238,64 @@ function createBookShelfDownload() {
"Since you are in local only mode you can only export a backup of your files \ "Since you are in local only mode you can only export a backup of your files \
<br><br> \ <br><br> \
<div class='w3-container'> \ <div class='w3-container'> \
<button class='w3-button w3-border w3-flat-wet-asphalt' >Export</button></div>" <button class='w3-button w3-border w3-flat-wet-asphalt' >Export</button></div>",
,0); 0
);
} }
function resetNavBar() { function resetNavBar() {
//enable toggleFiles Button //enable toggleFiles Button
let target = document.getElementById("toggleFilesMenu"); let target = document.getElementById("toggleFilesMenu");
target.innerHTML = ""; target.innerHTML = "";
let i = document.createElement("i"); let i = document.createElement("i");
i.classList.add("fa", "fa-file"); i.classList.add("fa", "fa-file");
//target.classList.add("w3-disabled"); //target.classList.add("w3-disabled");
target.appendChild(i); target.appendChild(i);
target.style.cssText = ''; target.style.cssText = "";
//enable toggleTestBlocksMenu //enable toggleTestBlocksMenu
document.getElementById("toggleTestBlocksMenu").style.display = "block"; document.getElementById("toggleTestBlocksMenu").style.display = "block";
}
function resetPage() {
return;
//set current page value in activeState object
activeState.activePage = "landing";
if (screen.width > 992) {
document.getElementById("siteTitle").innerHTML = "Template Gen";
} else {
document.getElementById("siteTitle").innerHTML = "TG";
}
//sessionVerfication check
if (!passwordHash.verify()) {
modalNotifier("Error: Session is not authenticated...", 0, false);
}
//reset navbar if files was used
resetNavBar();
//disable toggleTestBlocksMenu
document.getElementById("toggleTestBlocksMenu").style.display = "none";
//reset page and event listeners
hideMenus("force");
let mainFormDiv = document.getElementById("mainForm");
let outputDiv = document.getElementById("output");
let submitContainerDiv = document.getElementById("submitContainer");
let sidebarDiv = document.getElementById("sidebar");
mainFormDiv.innerHTML = "";
mainFormDiv.replaceWith(activeState.orgPage.main);
outputDiv.innerHTML = "";
outputDiv.replaceWith(outputDiv.cloneNode(true));
submitContainerDiv.innerHTML = "";
submitContainerDiv.replaceWith(submitContainerDiv.cloneNode(true));
sidebarDiv.innerHTML = "";
sidebarDiv.replaceWith(activeState.orgPage.sidebar);
} }
export { export {
@ -254,5 +309,6 @@ export {
modalNotifier, modalNotifier,
clickImportFiles, clickImportFiles,
resetNavBar, resetNavBar,
printVersion printVersion,
resetPage,
}; };

View File

@ -6,6 +6,7 @@ import {
clickImportFiles, clickImportFiles,
modalNotifier, modalNotifier,
printVersion, printVersion,
resetPage
} from "./evts.js"; } from "./evts.js";
import { buildFile } from "./files.js"; import { buildFile } from "./files.js";
import setPassword, { import setPassword, {
@ -46,7 +47,11 @@ window.activeState = {
"markup", "markup",
], ],
markups: ["title", "link", "italic", "green_highlighted", "highlighted"], markups: ["title", "link", "italic", "green_highlighted", "highlighted"],
storage: [] storage: [],
orgPage: {
main: {},
sidebar: {}
}
}; };
function init() { function init() {
@ -87,6 +92,11 @@ function init() {
if (screen.width < 993) { if (screen.width < 993) {
document.getElementById("siteTitle").innerHTML = "TG"; document.getElementById("siteTitle").innerHTML = "TG";
} }
//backup landing page
activeState.orgPage.sidebar = document.getElementById("sidebar");
activeState.orgPage.main = document.getElementById("mainForm");
} }
function eventListeners() { function eventListeners() {
@ -95,6 +105,11 @@ function eventListeners() {
.body .body
.addEventListener("click", (e) => hideMenus(e)); .addEventListener("click", (e) => hideMenus(e));
//add logo reset event
document
.getElementById("logo")
.addEventListener("click", resetPage);
//add set Password to loginForm //add set Password to loginForm
document document
.getElementById("submitPassword") .getElementById("submitPassword")
@ -104,9 +119,9 @@ function eventListeners() {
.getElementById("toggleNavigationMenu") .getElementById("toggleNavigationMenu")
.addEventListener("click", showMenu); .addEventListener("click", showMenu);
//add loadTemplateBtn event showMenu //add loadTemplateBtn event showMenu
document /* document
.getElementById("loadTemplateBtn") .getElementById("loadTemplateBtn")
.addEventListener("click", showMenu); .addEventListener("click", showMenu); */
//add toggle sideBar Menu //add toggle sideBar Menu
document document
.getElementById("toggleSidebarMenu") .getElementById("toggleSidebarMenu")
@ -155,11 +170,15 @@ function eventListeners() {
template = newURLArr[newURLArr.length -1]; template = newURLArr[newURLArr.length -1];
if (template != undefined) { if (template != undefined) {
template = template.split("=")[1]; template = template.split("=")[1];
if (template != undefined) {
if (activeState.templates.includes("")) {
loadNewTemplate(template);
}
}
} }
} }
console.log(template); console.log(template);
//loadNewTemplate(template);
}); });
} }

View File

@ -1,6 +1,6 @@
import { hideMenus, modalNotifier, printVersion, resetNavBar } from "./evts.js"; import { hideMenus, modalNotifier, printVersion, resetNavBar } from "./evts.js";
import { passwordHash, sanitize } from "./scripts.js"; import { passwordHash, sanitize } from "./scripts.js";
import { clearData, retrieveData, storeData, storeSettings } from "./storage.js"; import { retrieveData, storeData, storeSettings } from "./storage.js";
const buildSettings = () => { const buildSettings = () => {
//set current page value in activeState object //set current page value in activeState object

View File

@ -102,7 +102,7 @@ function loadNavBar() {
for (let x in res) { for (let x in res) {
let aMob = document.createElement("a"); let aMob = document.createElement("a");
aMob.setAttribute("href", "#"); aMob.setAttribute("href", "javascript:void(0)");
aMob.setAttribute("data-template", res[x][1]); aMob.setAttribute("data-template", res[x][1]);
aMob.classList.add("w3-bar-item", "w3-button", "w3-padding-large"); aMob.classList.add("w3-bar-item", "w3-button", "w3-padding-large");
aMob.innerHTML = res[x][0]; aMob.innerHTML = res[x][0];
@ -112,7 +112,7 @@ function loadNavBar() {
activeState.templates.push(res[x][1]); activeState.templates.push(res[x][1]);
} }
let createEntry = document.createElement("a"); let createEntry = document.createElement("a");
createEntry.setAttribute("href", "#"); createEntry.setAttribute("href", "javascript:void(0)");
createEntry.setAttribute("data-template", "!createNew"); createEntry.setAttribute("data-template", "!createNew");
createEntry.classList.add("w3-bar-item", "w3-button", "w3-padding-large"); createEntry.classList.add("w3-bar-item", "w3-button", "w3-padding-large");
createEntry.style.borderTop = "2px solid rgb(221, 221, 221)"; createEntry.style.borderTop = "2px solid rgb(221, 221, 221)";
@ -120,22 +120,22 @@ function loadNavBar() {
divMob.appendChild(createEntry); divMob.appendChild(createEntry);
createEntry = document.createElement("a"); createEntry = document.createElement("a");
createEntry.setAttribute("href", "#"); createEntry.setAttribute("href", "javascript:void(0)");
createEntry.setAttribute("data-template", "!settings"); createEntry.setAttribute("data-template", "!settings");
createEntry.classList.add("w3-bar-item", "w3-button", "w3-padding-large"); createEntry.classList.add("w3-bar-item", "w3-button", "w3-padding-large");
createEntry.innerHTML = "Settings"; createEntry.innerHTML = "Settings";
divMob.appendChild(createEntry); divMob.appendChild(createEntry);
createEntry = document.createElement("a"); createEntry = document.createElement("a");
createEntry.setAttribute("href", "#"); createEntry.setAttribute("href", "javascript:void(0)");
createEntry.setAttribute("data-template", "!logout"); createEntry.setAttribute("data-template", "!logout");
createEntry.classList.add("w3-bar-item", "w3-button", "w3-padding-large", "w3-flat-pomegranate"); createEntry.classList.add("w3-bar-item", "w3-button", "w3-padding-large", "w3-flat-pomegranate");
createEntry.innerHTML = "Logout"; createEntry.innerHTML = "Logout";
divMob.appendChild(createEntry); divMob.appendChild(createEntry);
divMob.addEventListener("click", (e) => { divMob.addEventListener("click", (e) => {
e.preventDefault;
if (e.target && e.target.matches("a.w3-bar-item")) { if (e.target && e.target.matches("a.w3-bar-item")) {
e.preventDefault;
let template = e.target.dataset.template; let template = e.target.dataset.template;
if (template == "!createNew") { if (template == "!createNew") {
createTemplate(); createTemplate();
@ -174,7 +174,7 @@ function initTextBlocks() {
if (res[x][1].length < 1) continue; if (res[x][1].length < 1) continue;
let aReg = document.createElement("a"); let aReg = document.createElement("a");
aReg.setAttribute("href", "#"); aReg.setAttribute("href", "javascript:void(0)");
aReg.classList.add("w3-bar-item", "w3-hide-small", "w3-padding-small"); aReg.classList.add("w3-bar-item", "w3-hide-small", "w3-padding-small");
let textBlockText = res[x][1]; let textBlockText = res[x][1];
if (res[x][1].length > 80) { if (res[x][1].length > 80) {