From eef0c0edc5a6fa6889af58eceb791cc58c08e9dc Mon Sep 17 00:00:00 2001 From: Fabrice Creuzot Date: Thu, 15 Jun 2023 14:05:09 +0200 Subject: [PATCH 1/4] Allow to hide or show customized config elements --- app/code/core/Mage/Sales/Model/Observer.php | 3 +-- js/mage/adminhtml/form.js | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/app/code/core/Mage/Sales/Model/Observer.php b/app/code/core/Mage/Sales/Model/Observer.php index 53398f05dd2..4b3685f9c6a 100644 --- a/app/code/core/Mage/Sales/Model/Observer.php +++ b/app/code/core/Mage/Sales/Model/Observer.php @@ -272,8 +272,7 @@ public function prepareProductEditFormRecurringProfile($observer) $dependencies = $block ->addFieldMap('is_recurring', 'product[is_recurring]') ->addFieldMap($profileElement->getHtmlId(), $profileElement->getName()) - ->addFieldDependence($profileElement->getName(), 'product[is_recurring]', '1') - ->addConfigOptions(['levels_up' => 2]); + ->addFieldDependence($profileElement->getName(), 'product[is_recurring]', '1'); $observer->getEvent()->getResult()->output .= $dependencies->toHtml(); } diff --git a/js/mage/adminhtml/form.js b/js/mage/adminhtml/form.js index 9453a8695ff..d82cde5869b 100644 --- a/js/mage/adminhtml/form.js +++ b/js/mage/adminhtml/form.js @@ -480,9 +480,7 @@ FormElementDependenceController.prototype = { * Misc. config options * Keys are underscored intentionally */ - _config : { - levels_up : 1 // how many levels up to travel when toggling element - }, + _config : {}, getSelectValues : function(select) { var result = []; @@ -512,16 +510,21 @@ FormElementDependenceController.prototype = { */ trackChange : function(e, idTo, valuesFrom) { - let upLevels = this._config.levels_up; - let ele; - if (!$(idTo)) { + var ele = $(idTo), cnf = this._config;; + if (!ele) { idTo = 'row_' + idTo; ele = $(idTo); if (!ele) { return; } } else { - ele = $(idTo).up(upLevels); + var closest = cnf.levels_up; // @deprecated + if ((typeof closest == 'number') && (closest > 1)) { + ele = ele.up(closest); + } + else { + ele = ele.closest('tr'); + } } // define whether the target should show up @@ -548,11 +551,10 @@ FormElementDependenceController.prototype = { // toggle target row if (shouldShowUp) { - var currentConfig = this._config; ele.select('input', 'select', 'td').each(function (item) { // don't touch hidden inputs (and Use Default inputs too), bc they may have custom logic if ((!item.type || item.type != 'hidden') && !($(item.id+'_inherit') && $(item.id+'_inherit').checked) - && !(currentConfig.can_edit_price != undefined && !currentConfig.can_edit_price)) { + && !(cnf.can_edit_price != undefined && !cnf.can_edit_price)) { item.disabled = false; } }); From 640df1f616bbf8f15bafb1a0bcc709b84be54513 Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Wed, 21 Feb 2024 22:44:08 +0000 Subject: [PATCH 2/4] removed prototypejs call to $ funcion --- js/mage/adminhtml/form.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/mage/adminhtml/form.js b/js/mage/adminhtml/form.js index a749d705281..84a6eaad78e 100644 --- a/js/mage/adminhtml/form.js +++ b/js/mage/adminhtml/form.js @@ -510,7 +510,7 @@ FormElementDependenceController.prototype = { */ trackChange : function(e, idTo, valuesFrom) { - var ele = $(idTo), cnf = this._config;; + var ele = document.getElementById(idTo), cnf = this._config;; if (!ele) { idTo = 'row_' + idTo; ele = $(idTo); From 8a1e08b2f0d458be57d194182679ec15b3c0d38d Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Wed, 21 Feb 2024 22:45:01 +0000 Subject: [PATCH 3/4] whitespace formatting --- js/mage/adminhtml/form.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/js/mage/adminhtml/form.js b/js/mage/adminhtml/form.js index 84a6eaad78e..eb8882ff606 100644 --- a/js/mage/adminhtml/form.js +++ b/js/mage/adminhtml/form.js @@ -521,8 +521,7 @@ FormElementDependenceController.prototype = { var closest = cnf.levels_up; // @deprecated if ((typeof closest == 'number') && (closest > 1)) { ele = ele.up(closest); - } - else { + } else { ele = ele.closest('tr'); } } From 1dbd44c0f949492515769a3a0e5db72c65a73feb Mon Sep 17 00:00:00 2001 From: Ng Kiat Siong Date: Sat, 2 Mar 2024 12:26:55 +0800 Subject: [PATCH 4/4] Update js/mage/adminhtml/form.js Removed extra semicolon --- js/mage/adminhtml/form.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/mage/adminhtml/form.js b/js/mage/adminhtml/form.js index eb8882ff606..73e98499af0 100644 --- a/js/mage/adminhtml/form.js +++ b/js/mage/adminhtml/form.js @@ -510,7 +510,7 @@ FormElementDependenceController.prototype = { */ trackChange : function(e, idTo, valuesFrom) { - var ele = document.getElementById(idTo), cnf = this._config;; + var ele = document.getElementById(idTo), cnf = this._config; if (!ele) { idTo = 'row_' + idTo; ele = $(idTo);