Skip to content

Commit

Permalink
Allow to hide or show customized config elements
Browse files Browse the repository at this point in the history
  • Loading branch information
luigifab committed Jun 15, 2023
1 parent 3b14b96 commit eef0c0e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
3 changes: 1 addition & 2 deletions app/code/core/Mage/Sales/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
20 changes: 11 additions & 9 deletions js/mage/adminhtml/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
});
Expand Down

0 comments on commit eef0c0e

Please sign in to comment.