N°4481 - Fix n:n link addition when there are more than 3+ ext. keys on the link class

This commit is contained in:
Molkobain
2021-12-13 15:01:23 +01:00
parent 5055397024
commit 4d37e2267f
4 changed files with 36 additions and 4 deletions

View File

@@ -375,6 +375,7 @@ JS
$oValue->Rewind();
$aForm = array();
$iMaxAddedId = 0;
$iAddedId = -1; // Unique id for new links
while ($oCurrentLink = $oValue->Fetch())
{
@@ -395,8 +396,12 @@ JS
} else {
$key = $oCurrentLink->GetKey();
}
$iMaxAddedId = max($iMaxAddedId, $key);
$aForm[$key] = $this->GetFormRow($oPage, $oLinkedObj, $oCurrentLink, $aArgs, $oCurrentObj, $key, $bReadOnly);
}
$oBlock->iMaxAddedId = (int) $iMaxAddedId;
$oDataTable = DataTableUIBlockFactory::MakeForForm("{$this->m_sAttCode}{$this->m_sNameSuffix}", $this->m_aTableConfig, $aForm);
$oDataTable->SetOptions(['select_mode' => 'custom']);
$oBlock->AddSubBlock($oDataTable);

View File

@@ -3,8 +3,23 @@
* @license http://opensource.org/licenses/AGPL-3.0
*/
function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizHelper, sExtKeyToRemote, bDoSearch) {
/**
*
* @param id
* @param sClass
* @param sAttCode
* @param iInputId
* @param sSuffix
* @param bDuplicates
* @param oWizHelper
* @param sExtKeyToRemote
* @param bDoSearch
* @param iMaxAddedId
* @constructor
*
* @since 3.0.0 Add iMaxAddedId parameter
*/
function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizHelper, sExtKeyToRemote, bDoSearch, iMaxAddedId = 0) {
this.id = id;
this.iInputId = iInputId;
this.sClass = sClass;
@@ -13,7 +28,7 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
this.bDuplicates = bDuplicates;
this.oWizardHelper = oWizHelper;
this.sExtKeyToRemote = sExtKeyToRemote;
this.iMaxAddedId = 0;
this.iMaxAddedId = iMaxAddedId;
this.aAdded = [];
this.aRemoved = [];
this.aModified = {};
@@ -418,4 +433,13 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
// Remove unused inputs
$('#linkedset_'+me.id+' :input[name^="attr_'+me.sAttCode+'["]').prop("disabled", true);
};
this.UpdateMaxAddedId = function () {
const iCurrentMaxAddedId = this.iMaxAddedId;
this.iMaxAddedId = Math.max(iCurrentMaxAddedId, this.GetMaxAddedId());
};
this.GetMaxAddedId = function () {
this.oWizardHelper;
};
}

View File

@@ -43,6 +43,8 @@ class BlockIndirectLinksEdit extends UIContentBlock
public $sExtKeyToRemote;
/** @var bool */
public $bJSDoSearch;
/** @var int */
public $iMaxAddedId = 0;
/** @var string */
public $sFormPrefix;

View File

@@ -10,7 +10,8 @@ oWidget{{ oUIBlock.iInputId }} = new LinksWidget(
{{ oUIBlock.bDuplicates }},
{{ oUIBlock.oWizHelper }},
'{{ oUIBlock.sExtKeyToRemote }}',
{{ oUIBlock.bJSDoSearch }}
{{ oUIBlock.bJSDoSearch }},
{{ oUIBlock.iMaxAddedId }}
);
oWidget{{ oUIBlock.iInputId }}.Init();
{% endapply %}