Advanced Search: Auto-complete search on foreign keys + refactoring of table_id2

SVN:b1162[5593]
This commit is contained in:
Eric Espié
2018-04-03 07:37:04 +00:00
parent d4960080ea
commit d22d3945ee
5 changed files with 33 additions and 26 deletions

View File

@@ -333,8 +333,8 @@ class UILinksWidgetDirect
$sHtml .= $oBlock->GetDisplay($oPage, "SearchFormToAdd_{$this->sInputid}", $sHtml .= $oBlock->GetDisplay($oPage, "SearchFormToAdd_{$this->sInputid}",
array( array(
'open' => $bOpen, 'open' => $bOpen,
'table_id' => "SearchResultsToAdd_{$this->sInputid}", 'result_list_outer_selector' => "SearchResultsToAdd_{$this->sInputid}",
'table_id2' => "add_{$this->sInputid}", 'table_id' => "add_{$this->sInputid}",
'table_inner_id' => "ResultsToAdd_{$this->sInputid}", 'table_inner_id' => "ResultsToAdd_{$this->sInputid}",
'cssCount' => "#count_{$this->sInputid}", 'cssCount' => "#count_{$this->sInputid}",
'query_params' => $oFilter->GetInternalParams(), 'query_params' => $oFilter->GetInternalParams(),

View File

@@ -420,8 +420,8 @@ EOF
array( array(
'open' => $bOpen, 'open' => $bOpen,
'menu' => false, 'menu' => false,
'table_id' => "SearchResultsToAdd_{$this->m_sAttCode}{$this->m_sNameSuffix}", 'result_list_outer_selector' => "SearchResultsToAdd_{$this->m_sAttCode}{$this->m_sNameSuffix}",
'table_id2' => 'add_'.$this->m_sAttCode, 'table_id' => 'add_'.$this->m_sAttCode,
'table_inner_id' => "ResultsToAdd_{$this->m_sAttCode}{$this->m_sNameSuffix}", 'table_inner_id' => "ResultsToAdd_{$this->m_sAttCode}{$this->m_sNameSuffix}",
'selection_mode' => true, 'selection_mode' => true,
'json' => $sJson, 'json' => $sJson,

View File

@@ -53,8 +53,8 @@ class UISearchFormForeignKeys
array( array(
'open' => $bOpen, 'open' => $bOpen,
'menu' => false, 'menu' => false,
'table_id' => "SearchResultsToAdd_{$this->m_iInputId}", 'result_list_outer_selector' => "SearchResultsToAdd_{$this->m_iInputId}",
'table_id2' => "add_{$this->m_iInputId}", 'table_id' => "add_{$this->m_iInputId}",
'table_inner_id' => "ResultsToAdd_{$this->m_iInputId}", 'table_inner_id' => "ResultsToAdd_{$this->m_iInputId}",
'selection_mode' => true, 'selection_mode' => true,
'cssCount' => '#count_'.$this->m_sAttCode.$this->m_sNameSuffix, 'cssCount' => '#count_'.$this->m_sAttCode.$this->m_sNameSuffix,

View File

@@ -255,8 +255,8 @@ function SearchFormForeignKeys(id, sTargetClass, sAttCode, sFilter, sTitle)
// Normal table, retrieve all the checked check-boxes // Normal table, retrieve all the checked check-boxes
$(':checked[name^=selectObject]', context).each( $(':checked[name^=selectObject]', context).each(
function (i) { function (i) {
if ((this.name != '') && ((this.type != 'checkbox') || (this.checked))) { if ((this.name !== '') && ((this.type !== 'checkbox') || (this.checked))) {
arrayExpr = /\[\]$/; var arrayExpr = /\[\]$/;
if (arrayExpr.test(this.name)) { if (arrayExpr.test(this.name)) {
// Array // Array
if (typeof theMap[this.name] === "undefined") { if (typeof theMap[this.name] === "undefined") {

View File

@@ -91,6 +91,18 @@ class SearchForm
$aListParams['json'] = json_decode($sJson, true); $aListParams['json'] = json_decode($sJson, true);
} }
if (!isset($aExtraParams['result_list_outer_selector']))
{
if (isset($aExtraParams['table_id']))
{
$aExtraParams['result_list_outer_selector'] = $aExtraParams['table_id'];
}
else
{
$aExtraParams['result_list_outer_selector'] = "search_form_result_{$sSearchFormId}";
}
}
$aSubClasses = MetaModel::GetSubclasses($sRootClass); $aSubClasses = MetaModel::GetSubclasses($sRootClass);
if (count($aSubClasses) > 0) if (count($aSubClasses) > 0)
@@ -104,7 +116,7 @@ class SearchForm
$aOptions[MetaModel::GetName($sClassName)] = "<option selected value=\"$sClassName\">".MetaModel::GetName($sClassName)."</options>\n"; $aOptions[MetaModel::GetName($sClassName)] = "<option selected value=\"$sClassName\">".MetaModel::GetName($sClassName)."</options>\n";
ksort($aOptions); ksort($aOptions);
$sContext = $oAppContext->GetForLink(); $sContext = $oAppContext->GetForLink();
$sClassesCombo = "<select name=\"class\" onChange=\"ReloadSearchForm('$sSearchFormId', this.value, '$sRootClass', '$sContext', '{$aExtraParams['table_id']}')\">\n".implode('', $sClassesCombo = "<select name=\"class\" onChange=\"ReloadSearchForm('$sSearchFormId', this.value, '$sRootClass', '$sContext', '{$aExtraParams['result_list_outer_selector']}')\">\n".implode('',
$aOptions)."</select>\n"; $aOptions)."</select>\n";
} }
else else
@@ -148,28 +160,19 @@ class SearchForm
$oBaseSearch->ResetCondition(); $oBaseSearch->ResetCondition();
$sBaseOQL = str_replace(' WHERE 1', '', $oBaseSearch->ToOQL()); $sBaseOQL = str_replace(' WHERE 1', '', $oBaseSearch->ToOQL());
if (isset($aExtraParams['table_inner_id'])) if (isset($aExtraParams['table_inner_id']))
{ {
$sDataConfigListSelector = $aExtraParams['table_inner_id']; $sDataConfigListSelector = $aExtraParams['table_inner_id'];
} }
else else
{ {
$sDataConfigListSelector = $aExtraParams['table_id']; $sDataConfigListSelector = $aExtraParams['result_list_outer_selector'];
}
if (!isset($aExtraParams['table_id']))
{
$aExtraParams['table_id'] = "search_form_result_{$sSearchFormId}";
} }
if (!isset($aExtraParams['table_inner_id'])) if (!isset($aExtraParams['table_inner_id']))
{ {
$aListParams['table_inner_id'] = "table_inner_id_{$sSearchFormId}"; $aListParams['table_inner_id'] = "table_inner_id_{$sSearchFormId}";
} }
// When table_id is different of result_list_outer_selector
if (isset($aExtraParams['table_id2']))
{
$aListParams['table_id'] = $aExtraParams['table_id2'];
}
$bOpen = false; $bOpen = false;
if (isset($aExtraParams['open'])) if (isset($aExtraParams['open']))
{ {
@@ -189,7 +192,7 @@ class SearchForm
$aSearchParams = array( $aSearchParams = array(
'criterion_outer_selector' => "#fs_{$sSearchFormId}_criterion_outer", 'criterion_outer_selector' => "#fs_{$sSearchFormId}_criterion_outer",
'result_list_outer_selector' => "#{$aExtraParams['table_id']}", 'result_list_outer_selector' => "#{$aExtraParams['result_list_outer_selector']}",
'data_config_list_selector' => "#{$sDataConfigListSelector}", 'data_config_list_selector' => "#{$sDataConfigListSelector}",
'endpoint' => utils::GetAbsoluteUrlAppRoot().'pages/ajax.searchform.php', 'endpoint' => utils::GetAbsoluteUrlAppRoot().'pages/ajax.searchform.php',
'init_opened' => $bOpen, 'init_opened' => $bOpen,
@@ -327,9 +330,10 @@ class SearchForm
} }
$oSearch->SetModifierProperty('UserRightsGetSelectFilter', 'bSearchMode', true); $oSearch->SetModifierProperty('UserRightsGetSelectFilter', 'bSearchMode', true);
$oSet = new DBObjectSet($oSearch); $oSet = new DBObjectSet($oSearch);
if ($oSet->Count() > MetaModel::GetConfig()->Get('max_combo_length')) $iCount = $oSet->Count();
if ($iCount > MetaModel::GetConfig()->Get('max_combo_length'))
{ {
return array('autocomplete' => true); return array('autocomplete' => true, 'count' => $iCount);
} }
} }
else else
@@ -337,14 +341,17 @@ class SearchForm
if (method_exists($oAttrDef, 'GetAllowedValuesAsObjectSet')) if (method_exists($oAttrDef, 'GetAllowedValuesAsObjectSet'))
{ {
$oSet = $oAttrDef->GetAllowedValuesAsObjectSet(); $oSet = $oAttrDef->GetAllowedValuesAsObjectSet();
if ($oSet->Count() > MetaModel::GetConfig()->Get('max_combo_length')) $iCount = $oSet->Count();
if ($iCount > MetaModel::GetConfig()->Get('max_combo_length'))
{ {
return array('autocomplete' => true); return array('autocomplete' => true, 'count' => $iCount);
} }
} }
} }
return array('values' => $oAttrDef->GetAllowedValues()); $aAllowedValues = $oAttrDef->GetAllowedValues();
return array('values' => $aAllowedValues, 'count' => count($aAllowedValues));
} }
/** /**