Skip to content

Commit

Permalink
fix(twolevels.js): solve trouble if associating Form is defined
Browse files Browse the repository at this point in the history
  • Loading branch information
J9rem committed Sep 28, 2023
1 parent 9c4d537 commit 5a1b144
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
6 changes: 4 additions & 2 deletions fields/EnumLevel2CommonsField.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,11 @@ public function formatValuesBeforeSaveIfEditable($entry, bool $isCreation = fals
if (!empty($parentField)) {
$values = $this->getFieldValues($this, $entry);
$parentValues = $this->getFieldValues($parentField, $entry);
if (!empty($this->getAssociatingFormId())) {
$assocFormId = $this->getAssociatingFormId();
if (!empty($assocFormId)
&& (strval($assocFormId) !== strval(intval($assocFormId)) || $assocFormId !== $parentField->getLinkedObjectName())) {
$formId = $this->formatFormId($this->getLinkedObjectName());
$associatingFormId = $this->formatFormId($this->getAssociatingFormId());
$associatingFormId = $this->formatFormId($assocFormId);
if (!empty($formId) && $formId == $associatingFormId){
$availableValues = $this->getAvailableChildrenValuesReverseFromForm($parentValues, $parentField->getLinkedObjectName());
} else {
Expand Down
18 changes: 12 additions & 6 deletions javascripts/bazar/define-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ if (Vue) {
}
})
}
const canGetSecondValuesByForm = (parentField,formIdData) => {
const res = parentField.isForm && (
!(formIdData?.id?.length > 0) // no associatingForm => form
|| String(formIdData?.id) === String(parentField.linkedObjectId) // same as form for primary level
)
return res
}

const refreshOption = (filterOption,promisesData,root,uuid) => {
const field = getFieldFormRoot(root,filterOption.name)
if (field !== null && Object.keys(field).length > 0
Expand Down Expand Up @@ -205,11 +213,8 @@ if (Vue) {
for (let index = 0; index < optionsAsEntries.length; index++) {
const optionKey = optionsAsEntries[index][0]
const values = [optionKey]
const formIdData = extractFormIdData(filterOption.name,parentField)
if (parentField.isForm && (
!(formIdData?.id?.length > 0)
|| String(formIdData?.id) === String(parentField.linkedObjectId)
) ){
const formIdData = extractFormIdData(filterOption.name,parentField,uuid)
if (canGetSecondValuesByForm(parentField,formIdData)){
twoLevelsHelper.createPromise(promisesData,{
formId: parentField.linkedObjectId,
processFormAsync: async (form)=>{
Expand All @@ -235,7 +240,8 @@ if (Vue) {
parentField,
values,
formIdData,
refreshOptionCache[uuid].options
refreshOptionCache[uuid].options,
formIdData.isForm && formId === childField.linkedObjectId
)
.then(([secondLevelValues,formModified,associations])=>{
updateSecondLevelValues(optionKey,filterOption,childField,parentField,secondLevelValues,formModified,associations)
Expand Down
19 changes: 17 additions & 2 deletions javascripts/enumlevel2Field/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,14 @@ const enumlevel2Helper = {
if (parentField && parentField.linkedObjectId.length > 0){
let values = this.getParentFieldNameValues(parentField)
const formsIds = this.extractListOfAssociatingForms(fieldName,parentField)
if (parentField.isForm && formsIds.length === 0){
const canGetSecondValuesByForm = parentField.isForm && (
formsIds.length === 0 // no associatingForm => form
|| (
formsIds.length === 1
&& String(formsIds[0].id) === String(parentField.linkedObjectId) // same as form for primary level
)
)
if (canGetSecondValuesByForm){
twoLevelsHelper.createPromise(promisesData,{
formId: parentField.linkedObjectId,
processFormAsync: async (form)=>{
Expand All @@ -692,7 +699,15 @@ const enumlevel2Helper = {
twoLevelsHelper.createPromise(promisesData,{
formId,
processFormAsync: async (form)=>{
return twoLevelsHelper.getAvailableSecondLevelsValuesForLists(form,fieldName,parentField,values,formIdData,this.levels2)
return twoLevelsHelper.getAvailableSecondLevelsValuesForLists(
form,
fieldName,
parentField,
values,
formIdData,
this.levels2,
formIdData.isForm && formId === this.levels2?.[formIdData.childId]?.linkedObjectId
)
.then(([secondLevelValues,formModified,associations])=>{
this.updateSecondLevel(secondLevelValues,isInit,associations)
return [secondLevelValues,formModified,associations]
Expand Down
5 changes: 2 additions & 3 deletions javascripts/twolevels.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,12 +537,11 @@ const getCorrespondancesReverse = async (associatingForm,fieldName,wantedFieldId
}
})
}
const getAvailableSecondLevelsValuesForLists = async (associatingForm,fieldName,parentField,values,formData,linkedObjectIdsCache)=>{
const reverseMode = formData.isForm
const getAvailableSecondLevelsValuesForLists = async (associatingForm,fieldName,parentField,values,formData,linkedObjectIdsCache,reverseMode)=>{
let correspondances = null
let propNames = {}
if (!reverseMode){
associatingForm = appendChildrenFieldsPropertyNamestoParentForm(associatingForm,parentField,extractLinkedObjects(linkedObjectIdsCache),true)
associatingForm = appendChildrenFieldsPropertyNamestoParentForm(associatingForm,parentField,extractLinkedObjects(linkedObjectIdsCache),reverseMode)
associatingForm = appendParentsFieldsPropertyNamestoParentForm(associatingForm,fieldName,parentField)
correspondances = await getCorrespondances(associatingForm,fieldName,parentField)
propNames = associatingForm.childrenFieldsPropertyNames
Expand Down

0 comments on commit 5a1b144

Please sign in to comment.