Advanced Search: Links n:1

SVN:b1162[5450]
This commit is contained in:
Eric Espié
2018-03-16 14:21:40 +00:00
parent d423d741b2
commit 272e8eac4f
4 changed files with 52 additions and 26 deletions

View File

@@ -278,14 +278,19 @@ class UILinksWidgetDirect
/**
* @param WebPage $oPage
* @param DBObject $oCurrentObj
* @throws Exception
* @param $aAlreadyLinked
*
* @throws \CoreException
* @throws \DictExceptionMissingString
* @throws \Exception
* @throws \OQLException
*/
public function GetObjectsSelectionDlg($oPage, $oCurrentObj)
public function GetObjectsSelectionDlg($oPage, $oCurrentObj, $aAlreadyLinked)
{
$sHtml = "<div class=\"wizContainer\" style=\"vertical-align:top;\">\n";
$oLinksetDef = MetaModel::GetAttributeDef($this->sClass, $this->sAttCode);
$valuesDef = $oLinksetDef->GetValuesDef();
$oLinkSetDef = MetaModel::GetAttributeDef($this->sClass, $this->sAttCode);
$valuesDef = $oLinkSetDef->GetValuesDef();
if ($valuesDef === null)
{
$oFilter = new DBObjectSearch($this->sLinkedClass);
@@ -302,12 +307,35 @@ class UILinksWidgetDirect
{
$this->SetSearchDefaultFromContext($oCurrentObj, $oFilter);
}
if (($oCurrentObj != null) && MetaModel::IsSameFamilyBranch($this->sLinkedClass, $this->sClass))
{
// Prevent linking to self if the linked object is of the same family
// and already present in the database
if (!$oCurrentObj->IsNew())
{
$oFilter->AddCondition('id', $oCurrentObj->GetKey(), '!=');
}
}
if (count($aAlreadyLinked) > 0)
{
$oFilter->AddCondition('id', $aAlreadyLinked, 'NOTIN');
}
if ($oCurrentObj != null)
{
$aArgs = array_merge($oCurrentObj->ToArgs('this'), $oFilter->GetInternalParams());
$oFilter->SetInternalParams($aArgs);
}
$bOpen = MetaModel::GetConfig()->Get('legacy_search_drawer_open');
$oBlock = new DisplayBlock($oFilter, 'search', false);
$sHtml .= $oBlock->GetDisplay($oPage, "SearchFormToAdd_{$this->sInputid}",
array(
'open' => $bOpen,
'table_id' => "SearchResultsToAdd_{$this->sInputid}")
'table_id' => "SearchResultsToAdd_{$this->sInputid}",
'table_id2' => "add_{$this->sInputid}",
'table_inner_id' => "ResultsToAdd_{$this->sInputid}",
'cssCount' => "#count_{$this->sInputid}",
'query_params' => $oFilter->GetInternalParams(),
)
);
$sHtml .= "<form id=\"ObjectsAddForm_{$this->sInputid}\">\n";
$sHtml .= "<div id=\"SearchResultsToAdd_{$this->sInputid}\" style=\"vertical-align:top;background: #fff;height:100%;overflow:auto;padding:0;border:0;\">\n";
@@ -334,8 +362,8 @@ class UILinksWidgetDirect
{
$sRemoteClass = $this->sLinkedClass;
}
$oLinksetDef = MetaModel::GetAttributeDef($this->sClass, $this->sAttCode);
$valuesDef = $oLinksetDef->GetValuesDef();
$oLinkSetDef = MetaModel::GetAttributeDef($this->sClass, $this->sAttCode);
$valuesDef = $oLinkSetDef->GetValuesDef();
if ($valuesDef === null)
{
$oFilter = new DBObjectSearch($sRemoteClass);
@@ -352,7 +380,7 @@ class UILinksWidgetDirect
if (($oCurrentObj != null) && MetaModel::IsSameFamilyBranch($sRemoteClass, $this->sClass))
{
// Prevent linking to self if the linked object is of the same family
// and laready present in the database
// and already present in the database
if (!$oCurrentObj->IsNew())
{
$oFilter->AddCondition('id', $oCurrentObj->GetKey(), '!=');

View File

@@ -402,8 +402,10 @@ EOF
{
$oFilter->AddCondition('id', $aAlreadyLinkedIds, 'NOTIN');
}
if ($oCurrentObj != null)
{
$this->SetSearchDefaultFromContext($oCurrentObj, $oFilter);
}
$oBlock = new DisplayBlock($oFilter, 'search', false);
$sHtml .= $oBlock->GetDisplay($oPage, "SearchFormToAdd_{$this->m_sAttCode}{$this->m_sNameSuffix}",
array(

View File

@@ -316,6 +316,7 @@ try
case 'selectObjectsToAdd':
$oPage->SetContentType('text/html');
$sClass = utils::ReadParam('class', '', false, 'class');
$aAlreadyLinked = utils::ReadParam('aAlreadyLinked', array());
$sJson = utils::ReadParam('json', '', false, 'raw_data');
$oObj = null;
if ($sJson != '')
@@ -329,7 +330,7 @@ try
$iCurrObjectId = utils::ReadParam('iObjId', 0);
$oPage->SetContentType('text/html');
$oWidget = new UILinksWidgetDirect($sClass, $sAttCode, $iInputId);
$oWidget->GetObjectsSelectionDlg($oPage, $oObj);
$oWidget->GetObjectsSelectionDlg($oPage, $oObj, $aAlreadyLinked);
break;
// ui.linksdirectwidget

View File

@@ -129,6 +129,14 @@ class SearchForm
$oBaseSearch->ResetCondition();
$sBaseOQL = str_replace(' WHERE 1', '', $oBaseSearch->ToOQL());
if (isset($aExtraParams['table_inner_id']))
{
$sDataConfigListSelector = $aExtraParams['table_inner_id'];
}
else
{
$sDataConfigListSelector = $aExtraParams['table_id'];
}
if (!isset($aExtraParams['table_id']))
{
@@ -145,7 +153,7 @@ class SearchForm
$aSearchParams = array(
'criterion_outer_selector' => "#fs_{$sSearchFormId}_criterion_outer",
'result_list_outer_selector' => "#{$aExtraParams['table_id']}",
'data_config_list_selector' => null, //this one will be set just bellow, it mean to tell the widget where to find the initial list configuration
'data_config_list_selector' => "#{$sDataConfigListSelector}",
'endpoint' => utils::GetAbsoluteUrlAppRoot().'pages/ajax.searchform.php',
'date_format' => AttributeDateTime::GetFormat()->ToMomentJS(),
'list_params' => $aListParams,
@@ -156,19 +164,6 @@ class SearchForm
),
);
if (isset($aSearchParams['list_params']['table_id']))
{
$aSearchParams['data_config_list_selector'] = '#'.$aSearchParams['list_params']['table_id'];
}
elseif (isset($aSearchParams['list_params']['table_inner_id']))
{
$aSearchParams['data_config_list_selector'] = '#'.$aSearchParams['list_params']['table_inner_id'];
}
else
{
$aSearchParams['data_config_list_selector'] = '#'.$aSearchParams['result_list_outer_selector'];
}
$oPage->add_ready_script('$("#fs_'.$sSearchFormId.'").search_form_handler('.json_encode($aSearchParams).');');
return $sHtml;