From a8ecb4a07bbbc8de0249acd46085b8e3785939b8 Mon Sep 17 00:00:00 2001 From: Henning <leutz@pcsg.de> Date: Tue, 11 Mar 2025 12:20:01 +0100 Subject: [PATCH] fix: update variable declarations and cache handling This commit involves refactoring code in Products.js by updating 'var' to 'let' or 'const' for proper scoping and better readability. It also introduces a new variable 'inAdministration' to handle specific conditions for QUIQQER's administrative state and modifies the condition for using cached data, considering 'inAdministration'. Expect no changes in functionality or behavior of the software with these changes. --- bin/classes/Products.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/bin/classes/Products.js b/bin/classes/Products.js index 7d3649f7..3f310f7c 100644 --- a/bin/classes/Products.js +++ b/bin/classes/Products.js @@ -84,19 +84,19 @@ define('package/quiqqer/products/bin/classes/Products', [ */ openProduct: function (productId) { return this.getChild(productId).then(function (attributes) { - var panel = attributes.typePanel; + let panel = attributes.typePanel; if (panel === '' || typeof panel === 'undefined') { panel = 'package/quiqqer/products/bin/controls/products/Product'; } return new Promise(function (resolve) { - var needles = []; + let needles = []; needles.push(panel); needles.push('utils/Panels'); require(needles, function (Panel, Utils) { - var Control = new Panel({ + const Control = new Panel({ productId: productId }); @@ -175,7 +175,7 @@ define('package/quiqqer/products/bin/classes/Products', [ } require(['Projects'], function (Projects) { - var Project = Projects.get(result.project), + const Project = Projects.get(result.project), Media = Project.getMedia(); Media.get(result.id).then(resolve).catch(function () { @@ -231,8 +231,13 @@ define('package/quiqqer/products/bin/classes/Products', [ const jsonData = JSON.stringify({productId, fields}); const key = btoa(String.fromCharCode(...new TextEncoder().encode(jsonData))).slice(0, 32); + let inAdministration = false; + if (typeof QUIQQER.inAdministration !== 'undefined' && QUIQQER.inAdministration) { + inAdministration = !!QUIQQER.inAdministration; + } + return new Promise(function (resolve, reject) { - if (!forceCache && typeof requestCache[key] !== 'undefined') { + if (!forceCache && typeof requestCache[key] !== 'undefined' && !inAdministration) { // JSON.parse(JSON.stringify because JS reference usage return resolve(JSON.parse(JSON.stringify(requestCache[key]))); } @@ -489,7 +494,7 @@ define('package/quiqqer/products/bin/classes/Products', [ 'package/quiqqer/products/bin/controls/products/Product', 'utils/Panels' ], function (ProductPanel, Panels) { - var PPanel = new ProductPanel({ + const PPanel = new ProductPanel({ productId: productId, '#id': productId }); @@ -504,7 +509,7 @@ define('package/quiqqer/products/bin/classes/Products', [ * @param {number} pid */ addToVisited: function (pid) { - var visited = this.getVisitedProductIds(); + let visited = this.getVisitedProductIds(); visited.push(pid); visited = visited.unique(); @@ -522,7 +527,7 @@ define('package/quiqqer/products/bin/classes/Products', [ * @returns {Array} */ getVisitedProductIds: function () { - var visited = QUI.Storage.get('quiqqer-products-visited'); + let visited = QUI.Storage.get('quiqqer-products-visited'); if (!visited) { return []; -- GitLab