Fix: Clean up Python comments and deprecated js code.

This commit is contained in:
2025-03-21 14:34:29 +00:00
parent a6cbf9a7b7
commit 85a3ec4c9f
20 changed files with 28 additions and 879 deletions

View File

@@ -1,3 +0,0 @@
// Shared JS file names: routing, main, shared, localStorage, appDialogs

View File

@@ -1,65 +0,0 @@
// main.js
import { initializeAPI } from './shared/api.js';
import { setupEventListeners } from './shared/events.js';
import { initializeComponents } from './components/componentInitializer.js';
import { router } from './shared/router.js';
import { CONFIG } from './config/config.js';
// DOM ready function
function domReady(fn) {
if (document.readyState !== 'loading') {
fn();
} else {
document.addEventListener('DOMContentLoaded', fn);
}
}
// Main initialization function
function initializeApp() {
console.log('Initializing application...');
// Initialize API with base URL
initializeAPI(CONFIG.API_BASE_URL);
// Setup global event listeners
setupEventListeners();
// Initialize reusable components
initializeComponents();
// Initialize router
router.init();
// Page-specific initialization
const currentPage = document.body.dataset.page;
switch (currentPage) {
case 'home':
import('./pages/home.js').then(module => module.initHomePage());
break;
case 'about':
import('./pages/about.js').then(module => module.initAboutPage());
break;
case 'contact':
import('./pages/contact.js').then(module => module.initContactPage());
break;
default:
console.log('No specific initialization for this page');
}
console.log('Application initialized');
}
// Run the initialization when the DOM is ready
domReady(initializeApp);
// Expose a global app object if needed
window.app = {
// Add methods or properties that need to be globally accessible
reloadPage: () => {
window.location.reload();
},
navigateTo: (url) => {
router.navigateTo(url);
}
};

View File

@@ -1,111 +0,0 @@
import Validation from "./lib/validation.js";
function mapHashToController(hash) {
if (hash == null) return mapHashToController(hashPageHome);
url = _pathHost; // + '/';
console.log("url: " + url + "\nhash: " + hash);
return url + hash;
switch (hash) {
case hashPageErrorNoPermission:
url += 'error';
break;
case hashPageStoreHome:
url += 'store/home';
break;
case hashPageStoreProduct:
url += 'store/product';
break;
case hashStoreBasketLoad:
url += 'store/basket_load';
break;
case hashStoreBasketAdd:
url += 'store/product';
break;
default:
url += '';
}
return url;
}
/*
function goToPage(pageHash, parameters) {
window.location.href = "{{ url_for(" + pageHash + (parameters == '' ? '' : ',' + parameters) + ") }}"; // getPageRoute(pageHash, parameters);
}
*/
function goToPage(pageHash, parametersJSON) {
// window.location.href = "{{ url_for(" + pageHash + (parameters == '' ? '' : ',' + parameters) + ") }}"; // getPageRoute(pageHash, parameters);
// ajaxJSONData(pageHash, mapHashToController(pageHash), parameters, null, false);
url = mapHashToController(pageHash);
if (!Validation.isEmpty(parametersJSON)) {
url += '%3F'; // '?';
let firstParameter = true;
for (var p in parametersJSON) {
// url += p + '=' + parametersJSON[p];
if (!firstParameter) {
url += '&';
} else {
firstParameter = false;
}
url += parametersJSON[p];
}
}
leavePage();
window.location.href = url;
// ajaxJSONData(pageHash, url, parametersJSON, loadPageBody, false);
}
function leavePage() {}
function goToUrl(parameterisedUrl) {
leavePage();
window.location.href = parameterisedUrl;
}
function htmlEncode(value) {
return document.createElement('<div/>').text(value).innerHTML;
}
var _domParser = null;
function htmlDecode(value) {
if (_domParser == null) _domParser = DOMParser(); // https://www.w3docs.com/snippets/javascript/how-to-html-encode-a-string.html
return _domParser.parseFromString(value, 'text/html').documentElement.textContent;
}
function convertForm2JSON(elemForm) {
formData = {}
formDataTmp = elemForm.serializeArray();
$.each(formDataTmp, function(index, field) {
formData[field.name] = field.value;
/*
console.log('field name: ' + field.name);
console.log('field value: ' + field.value);
console.log('field currentval: ' + getElementValueCurrent(field));
*/
});
return formData;
}
function loadPageBody(response) {
let pageBody = document.querySelectorAll(idPageBody);
console.log('ajax:');
console.log(response.data);
pageBody.innerHTML = response.data['html_block'];
}