N°2250 - DisplayObject with ormLinkSet ignore Removed (#309)

This commit is contained in:
Anne-Catherine
2022-09-13 10:33:12 +02:00
committed by GitHub
parent 5d9e58f194
commit b061c29a5b
4 changed files with 36 additions and 32 deletions

View File

@@ -377,30 +377,31 @@ JS
$aForm = array();
$iMaxAddedId = 0;
$iAddedId = -1; // Unique id for new links
while ($oCurrentLink = $oValue->Fetch())
{
$oBlock->aRemoved = json_decode(utils::ReadPostedParam("attr_{$sFormPrefix}{$this->m_sAttCode}_tbd", '[]', 'raw_data'));
while ($oCurrentLink = $oValue->Fetch()) {
// We try to retrieve the remote object as usual
$oLinkedObj = MetaModel::GetObject($this->m_sRemoteClass, $oCurrentLink->Get($this->m_sExtKeyToRemote),
false /* Must not be found */);
// If successful, it means that we can edit its link
if ($oLinkedObj !== null) {
$bReadOnly = false;
} // Else we retrieve it without restrictions (silos) and will display its link as readonly
else {
$bReadOnly = true;
$oLinkedObj = MetaModel::GetObject($this->m_sRemoteClass, $oCurrentLink->Get($this->m_sExtKeyToRemote), false /* Must not be found */, true);
}
if (!in_array($oCurrentLink->GetKey(), $oBlock->aRemoved)) {
$oLinkedObj = MetaModel::GetObject($this->m_sRemoteClass, $oCurrentLink->Get($this->m_sExtKeyToRemote), false /* Must not be found */);
// If successful, it means that we can edit its link
if ($oLinkedObj !== null) {
$bReadOnly = false;
} // Else we retrieve it without restrictions (silos) and will display its link as readonly
else {
$bReadOnly = true;
$oLinkedObj = MetaModel::GetObject($this->m_sRemoteClass, $oCurrentLink->Get($this->m_sExtKeyToRemote), false /* Must not be found */, true);
}
if ($oCurrentLink->IsNew()) {
$key = $iAddedId--;
} else {
$key = $oCurrentLink->GetKey();
}
if ($oCurrentLink->IsNew()) {
$key = $iAddedId--;
} else {
$key = $oCurrentLink->GetKey();
}
$iMaxAddedId = max($iMaxAddedId, $key);
$aForm[$key] = $this->GetFormRow($oPage, $oLinkedObj, $oCurrentLink, $aArgs, $oCurrentObj, $key, $bReadOnly);
$iMaxAddedId = max($iMaxAddedId, $key);
$aForm[$key] = $this->GetFormRow($oPage, $oLinkedObj, $oCurrentLink, $aArgs, $oCurrentObj, $key, $bReadOnly);
}
}
$oBlock->iMaxAddedId = (int) $iMaxAddedId;
$oBlock->iMaxAddedId = (int)$iMaxAddedId;
$oDataTable = DataTableUIBlockFactory::MakeForForm("{$this->m_sAttCode}{$this->m_sNameSuffix}", $this->m_aTableConfig, $aForm);
$oDataTable->SetOptions(['select_mode' => 'custom', 'disable_hyperlinks' => true]);

View File

@@ -19,7 +19,7 @@
*
* @since 3.0.0 Add iMaxAddedId parameter
*/
function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizHelper, sExtKeyToRemote, bDoSearch, iMaxAddedId = 0) {
function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizHelper, sExtKeyToRemote, bDoSearch, iMaxAddedId = 0, aRemoved = []) {
this.id = id;
this.iInputId = iInputId;
this.sClass = sClass;
@@ -30,7 +30,7 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
this.sExtKeyToRemote = sExtKeyToRemote;
this.iMaxAddedId = iMaxAddedId;
this.aAdded = [];
this.aRemoved = [];
this.aRemoved = aRemoved;
this.aModified = {};
this.bDoSearch = bDoSearch; // false if the search is not launched
let me = this;

View File

@@ -45,6 +45,8 @@ class BlockIndirectLinksEdit extends UIContentBlock
public $bJSDoSearch;
/** @var int */
public $iMaxAddedId = 0;
/** @var array */
public $aRemoved = [];
/** @var string */
public $sFormPrefix;

View File

@@ -2,16 +2,17 @@
{# @license http://opensource.org/licenses/AGPL-3.0 #}
{% apply spaceless %}
oWidget{{ oUIBlock.iInputId }} = new LinksWidget(
'{{ oUIBlock.sLinkedSetId }}',
'{{ oUIBlock.sClass }}',
'{{ oUIBlock.sAttCode }}',
'{{ oUIBlock.iInputId }}',
'{{ oUIBlock.sNameSuffix }}',
{{ oUIBlock.bDuplicates }},
{{ oUIBlock.oWizHelper }},
'{{ oUIBlock.sExtKeyToRemote }}',
{{ oUIBlock.bJSDoSearch }},
{{ oUIBlock.iMaxAddedId }}
'{{ oUIBlock.sLinkedSetId }}',
'{{ oUIBlock.sClass }}',
'{{ oUIBlock.sAttCode }}',
'{{ oUIBlock.iInputId }}',
'{{ oUIBlock.sNameSuffix }}',
{{ oUIBlock.bDuplicates }},
{{ oUIBlock.oWizHelper }},
'{{ oUIBlock.sExtKeyToRemote }}',
{{ oUIBlock.bJSDoSearch }},
{{ oUIBlock.iMaxAddedId }},
{{ oUIBlock.aRemoved | json_encode | raw }}
);
oWidget{{ oUIBlock.iInputId }}.Init();
{% endapply %}