From 5baff6257ba0503b241ab21ad00c1f1543643a1f Mon Sep 17 00:00:00 2001 From: Eric Date: Tue, 13 Nov 2018 15:36:31 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B01754=20-=20Linkset=20and=20CheckToWrite:?= =?UTF-8?q?=20Loss=20of=20links=20on=20error=20during=20creation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/ui.linkswidget.class.inc.php | 14 ++++++++++++-- js/linkswidget.js | 17 +++++++++++------ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/application/ui.linkswidget.class.inc.php b/application/ui.linkswidget.class.inc.php index 6ad11c308..3f61c5818 100644 --- a/application/ui.linkswidget.class.inc.php +++ b/application/ui.linkswidget.class.inc.php @@ -194,7 +194,8 @@ class UILinksWidget $aArgs['prefix'] = $sPrefix; $aArgs['wizHelper'] = "oWizardHelper{$this->m_iInputId}_".($iUniqueId < 0 ? -$iUniqueId : $iUniqueId); $aArgs['this'] = $oNewLinkObj; - $aRow['form::checkbox'] = "m_iInputId.".OnSelectChange();\" value=\"-$iUniqueId\">"; + $sInputValue = $iUniqueId > 0 ? "-$iUniqueId" : "$iUniqueId"; + $aRow['form::checkbox'] = "m_iInputId.".OnSelectChange();\" value=\"$sInputValue\">"; foreach($this->m_aEditableFields as $sFieldCode) { $sFieldId = $this->m_iInputId.'_'.$sFieldCode.'['.-$iUniqueId.']'; @@ -213,7 +214,7 @@ class UILinksWidget // Rows added before loading the form cannot call OnLinkAdded. if ($iUniqueId > 0) { - $oP->add_script( + $oP->add_ready_script( <<m_iInputId}.OnLinkAdded($iUniqueId, $iRemoteObjKey); @@ -337,6 +338,7 @@ EOF $oValue->Rewind(); $aForm = array(); $iAddedId = 1; // Unique id for new links + $aAddedLinks = array(); while($oCurrentLink = $oValue->Fetch()) { // We try to retrieve the remote object as usual @@ -356,6 +358,7 @@ EOF if ($oCurrentLink->IsNew()) { $key = -($iAddedId++); + $aAddedLinks[] = array('iAddedId' => -$key, 'iRemote' => $oCurrentLink->Get($this->m_sExtKeyToRemote)); } else { @@ -374,6 +377,13 @@ EOF oWidget{$this->m_iInputId}.Init(); EOF ); + foreach ($aAddedLinks as $aAddedLink) + { + $oPage->add_ready_script(<<m_iInputId}.AddLink({$aAddedLink['iAddedId']}, {$aAddedLink['iRemote']}); +EOF + ); + } $sHtmlValue .= "     m_sAttCode}{$this->m_sNameSuffix}_btnRemove\" type=\"button\" value=\"".Dict::S('UI:RemoveLinkedObjectsOf_Class')."\" onClick=\"oWidget{$this->m_iInputId}.RemoveSelected();\" >"; $sHtmlValue .= "   m_sAttCode}{$this->m_sNameSuffix}_btnAdd\" type=\"button\" value=\"".Dict::Format('UI:AddLinkedObjectsOf_Class', MetaModel::GetName($this->m_sRemoteClass))."\" onClick=\"oWidget{$this->m_iInputId}.AddObjects();\">m_sAttCode}{$this->m_sNameSuffix}_indicatorAdd\">\n"; $sHtmlValue .= "

 

\n"; diff --git a/js/linkswidget.js b/js/linkswidget.js index ea1f4d0c6..1ec30d499 100644 --- a/js/linkswidget.js +++ b/js/linkswidget.js @@ -330,15 +330,20 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH return false; }; - this.OnLinkAdded = function(iAddedId, iRemote) - { + this.AddLink = function (iAddedId, iRemote) + { // Assumption: this identifier will be higher than the previous one me.iMaxAddedId = iAddedId; - var sFormPrefix = me.iInputId; - oAdded = {}; - oAdded['formPrefix'] = sFormPrefix; - oAdded['attr_' + sFormPrefix + this.sExtKeyToRemote] = iRemote; + var sFormPrefix = me.iInputId; + oAdded = {}; + oAdded['formPrefix'] = sFormPrefix; + oAdded['attr_' + sFormPrefix + this.sExtKeyToRemote] = iRemote; me.aAdded[iAddedId] = oAdded; + }; + + this.OnLinkAdded = function(iAddedId, iRemote) + { + this.AddLink(iAddedId, iRemote); $('#linkedset_'+me.id+' :input').off('change').on('change', function() { if (!($(this).hasClass('selection'))) { var oCheckbox = $(this).closest('tr').find('.selection');