Skip to content

Commit

Permalink
Hotfix - Vistas Personalizadas - Evaluación incorrecta de Condiciones…
Browse files Browse the repository at this point in the history
… en Vista Detalle (#274)
  • Loading branch information
jordiSTIC committed Jun 19, 2024
1 parent e8ca801 commit 9181761
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public function save_lines($post_data, $view_module, $parent, $key = '')
$condition->condition_order = ++$j;
$condition->name = $parent->name . '-' . $condition->condition_order;
$condition->stic_custo233dzations_ida = $parent->id;
if ($condition->value===true) {
$condition->value = 1;
} else if ($condition->value===false) {
$condition->value = 0;
}
$condition->save();
}
}
Expand Down
9 changes: 6 additions & 3 deletions modules/stic_Custom_Views/processor/js/sticCVUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ var sticCVUtils = class sticCVUtils {

static getValue(fieldContent, value_list) {
var $elem = fieldContent.$editor;
if (fieldContent.customView.view == "detailview") {
if (fieldContent.customView.view == "detailview" && fieldContent.type != "bool") {
$elem = fieldContent.$fieldText;
}
if ($elem.length == 0 || $elem.get(0).parentNode === null) {
Expand All @@ -279,6 +279,9 @@ var sticCVUtils = class sticCVUtils {
if (fieldContent.type == "relate") {
return $elem.attr("data-id-value") + "|" + $elem.text().trim();
}
if (fieldContent.type == "bool") {
return $elem.prop("checked");
}
var text = fieldContent.text();
if (
value_list != undefined &&
Expand Down Expand Up @@ -499,11 +502,11 @@ var sticCVUtils = class sticCVUtils {
return false;
}

static onChange($elem, callback, alsoInline = false) {
static onChange($elem, callback) {
$elem.each(function() {
$(this).on("change paste keyup", callback);
YAHOO.util.Event.on($(this)[0], "change", callback);
if (!$(this).is(":input") || alsoInline) {
if (!$(this).is(":input")) {
var observer = new MutationObserver(callback);
observer.observe($(this)[0], { attributes: true, childList: true, subtree: true, characterData: true });
}
Expand Down
7 changes: 7 additions & 0 deletions modules/stic_Custom_Views/processor/js/sticCV_Element_Div.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,11 @@ var sticCV_Element_Div = class sticCV_Element_Div {
}
return false;
}

onChange(callback) {
return sticCVUtils.onChange(this.$element, callback);
}
change() {
return sticCVUtils.change(this.$element, callback);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,4 @@ var sticCV_Element_Label = class sticCV_Element_Label extends sticCV_Element_Div
}
return super.applyAction(action);
}

onChange(callback, alsoInline = false) {
return sticCVUtils.onChange(this.$element, callback, alsoInline);
}
change() {
return sticCVUtils.change(this.$element, callback);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,11 @@ var sticCV_Record_Field_Content = class sticCV_Record_Field_Content extends stic
}

onChange(callback) {
var alsoInline = this.customView.view == "detailview";
return sticCVUtils.onChange(this.$editor, callback, alsoInline) || super.onChange(callback, alsoInline);
if (this.customView.view == "detailview") {
return this.field.container.onChange(callback);
} else {
return sticCVUtils.onChange(this.$editor, callback) || super.onChange(callback);
}
}
change() {
return sticCVUtils.change(this.$editor) || super.change();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ var sticCV_View_Record_Base = class sticCV_View_Record_Base {
this._tabs = [];
}

field(fieldName) {
if (fieldName in this._fields === false) {
field(fieldName, forceReloadField = false) {
if (forceReloadField || fieldName in this._fields === false) {
this._fields[fieldName] = new sticCV_Record_Field(this, fieldName);
}
return this._fields[fieldName];
Expand Down Expand Up @@ -100,7 +100,7 @@ var sticCV_View_Record_Base = class sticCV_View_Record_Base {
var self = this;
conditions.forEach(condition => {
self.field(condition.field).onChange(function() {
self.processCustomization(index);
self.processCustomization(index, false, true);
});
});
}
Expand Down Expand Up @@ -170,8 +170,8 @@ var sticCV_View_Record_Base = class sticCV_View_Record_Base {
* value: social_services
* }
*/
checkCondition(condition) {
return this.field(condition.field).checkCondition(condition);
checkCondition(condition, forceReloadField = false) {
return this.field(condition.field, forceReloadField).checkCondition(condition);
}

/**
Expand All @@ -187,12 +187,14 @@ var sticCV_View_Record_Base = class sticCV_View_Record_Base {
/**
* Process a Customization: Checks all conditions in order to apply all actions
*/
processCustomization(index, resetLastResult = false) {
processCustomization(index, resetLastResult = false, forceReloadField = false) {
var customization = this.customizations[index];
var value = true;
if (Array.isArray(customization.conditions) && customization.conditions.length) {
var self = this;
customization.conditions.forEach(condition => (value = value ? self.checkCondition(condition) : value));
customization.conditions.forEach(
condition => (value = value ? self.checkCondition(condition, forceReloadField) : value)
);
}
if (resetLastResult) {
customization.lastResult = false;
Expand Down

0 comments on commit 9181761

Please sign in to comment.