mirror of
https://github.com/Combodo/iTop.git
synced 2026-09-29 21:09:10 +02:00
N°580 - Autocomplete with namesakes. Complement for select
This commit is contained in:
@@ -183,6 +183,16 @@ class UIExtKeyWidget
|
||||
array_push($aOptions,$aOption);
|
||||
|
||||
$oAllowedValues->Rewind();
|
||||
$bAddingValue=false;
|
||||
|
||||
$aComplementAttributeSpec = MetaModel::GetComplementAttributeSpec($oAllowedValues->GetClass());
|
||||
$sFormatAdditionalField = $aComplementAttributeSpec[0];
|
||||
$aAdditionalField = $aComplementAttributeSpec[1];
|
||||
|
||||
if (count($aAdditionalField)>0)
|
||||
{
|
||||
$bAddingValue=true;
|
||||
}
|
||||
while($oObj = $oAllowedValues->Fetch())
|
||||
{
|
||||
$aOption=[];
|
||||
@@ -213,6 +223,15 @@ EOF
|
||||
if ($oObj->IsObsolete()){
|
||||
$aOption['obsolescence_flag'] ="1";
|
||||
}
|
||||
if ($bAddingValue)
|
||||
{
|
||||
$aArguments = [];
|
||||
foreach ($aAdditionalField as $sAdditionalField)
|
||||
{
|
||||
array_push($aArguments,$oObj->Get($sAdditionalField));
|
||||
}
|
||||
$aOption['additional_field'] = vsprintf($sFormatAdditionalField, $aArguments);
|
||||
}
|
||||
array_push($aOptions,$aOption);
|
||||
}
|
||||
$sHTMLValue .= "<select title=\"$sHelpText\" name=\"{$sAttrFieldPrefix}{$sFieldName}\" id=\"$this->iId\"></select>";
|
||||
@@ -715,7 +734,6 @@ EOF
|
||||
|
||||
// Current extkey value, so we can display event if it is not available anymore (eg. archived).
|
||||
$iCurrentExtKeyId = (is_null($oObj) || $this->sAttCode === '') ? 0 : $oObj->Get($this->sAttCode);
|
||||
|
||||
$oValuesSet = new ValueSetObjects($sFilter, 'friendlyname'); // Bypass GetName() to avoid the encoding by htmlentities
|
||||
$iMax = 150;
|
||||
$oValuesSet->SetLimit($iMax);
|
||||
@@ -755,7 +773,14 @@ EOF
|
||||
$aJsonMap = array();
|
||||
foreach ($aValues as $sKey => $aValue)
|
||||
{
|
||||
$aJsonMap[] = array('value' => $sKey, 'label' => $aValue['label'], 'obsolescence_flag' => $aValue['obsolescence_flag']);
|
||||
if ($aValue['additional_field'] != '')
|
||||
{
|
||||
$aJsonMap[] = array('value' => $sKey, 'label' => $aValue['label'], 'obsolescence_flag' => $aValue['obsolescence_flag'], 'additional_field' => $aValue['additional_field']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$aJsonMap[] = array('value' => $sKey, 'label' => $aValue['label'], 'obsolescence_flag' => $aValue['obsolescence_flag']);
|
||||
}
|
||||
}
|
||||
|
||||
$oP->SetContentType('application/json');
|
||||
|
||||
@@ -748,7 +748,47 @@ abstract class MetaModel
|
||||
return array('%1$s', array($nameRawSpec));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sClass
|
||||
*
|
||||
* @return array
|
||||
* @throws \CoreException
|
||||
* @throws \DictExceptionMissingString
|
||||
*/
|
||||
final static public function GetComplementAttributeSpec($sClass)
|
||||
{
|
||||
self::_check_subclass($sClass);
|
||||
$nameRawSpec = self::$m_aClassParams[$sClass]["name_complement_for_select"];
|
||||
if (is_array($nameRawSpec))
|
||||
{
|
||||
$sFormat = Dict::S("Class:$sClass/ComplementForSelect", '');
|
||||
if (strlen($sFormat) == 0)
|
||||
{
|
||||
// Default to "%1$s %2$s..."
|
||||
for($i = 1; $i <= count($nameRawSpec); $i++)
|
||||
{
|
||||
if (empty($sFormat))
|
||||
{
|
||||
$sFormat .= '%'.$i.'$s';
|
||||
}
|
||||
else
|
||||
{
|
||||
$sFormat .= ' %'.$i.'$s';
|
||||
}
|
||||
}
|
||||
}
|
||||
return array($sFormat, $nameRawSpec);
|
||||
}
|
||||
elseif (empty($nameRawSpec))
|
||||
{
|
||||
return array($sClass, array());
|
||||
}
|
||||
else
|
||||
{
|
||||
// string -> attcode
|
||||
return array('%1$s', array($nameRawSpec));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get the friendly name expression for a given class
|
||||
*
|
||||
|
||||
@@ -349,11 +349,11 @@ class ValueSetObjects extends ValueSetDefinition
|
||||
$this->m_bSort = $bSort;
|
||||
}
|
||||
|
||||
public function GetValuesForAutocomplete($aArgs, $sContains = '', $sOperation = 'contains', $aAdditionalFields = array())
|
||||
public function GetValuesForAutocomplete($aArgs, $sContains = '', $sOperation = 'contains')
|
||||
{
|
||||
if (!$this->m_bIsLoaded || ($sContains != $this->m_sContains) || ($sOperation != $this->m_sOperation))
|
||||
{
|
||||
$this->LoadValuesForAutocomplete($aArgs, $sContains, $sOperation, $aAdditionalFields);
|
||||
$this->LoadValuesForAutocomplete($aArgs, $sContains, $sOperation);
|
||||
$this->m_bIsLoaded = true;
|
||||
}
|
||||
// The results are already filtered and sorted (on friendly name)
|
||||
@@ -370,7 +370,7 @@ class ValueSetObjects extends ValueSetDefinition
|
||||
* @throws \CoreException
|
||||
* @throws \OQLException
|
||||
*/
|
||||
protected function LoadValuesForAutocomplete($aArgs, $sContains = '', $sOperation = 'contains', $aAdditionalFields = array())
|
||||
protected function LoadValuesForAutocomplete($aArgs, $sContains = '', $sOperation = 'contains')
|
||||
{
|
||||
$this->m_sContains = $sContains;
|
||||
$this->m_sOperation = $sOperation;
|
||||
@@ -386,6 +386,7 @@ class ValueSetObjects extends ValueSetDefinition
|
||||
$oFilter = DBObjectSearch::FromOQL($this->m_sFilterExpr);
|
||||
$oFilter->SetShowObsoleteData(utils::ShowObsoleteData());
|
||||
}
|
||||
|
||||
if (!$oFilter) return false;
|
||||
if (!is_null($this->m_oExtraCondition))
|
||||
{
|
||||
@@ -399,7 +400,7 @@ class ValueSetObjects extends ValueSetDefinition
|
||||
}
|
||||
}
|
||||
|
||||
$oExpression = DBObjectSearch::GetPolymorphicExpression($oFilter->GetClass(), 'friendlyname');
|
||||
//$oExpression = DBObjectSearch::GetPolymorphicExpression($oFilter->GetClass(), 'friendlyname');
|
||||
$sClass = $oFilter->GetClass();
|
||||
|
||||
switch ($sOperation)
|
||||
@@ -454,7 +455,16 @@ class ValueSetObjects extends ValueSetDefinition
|
||||
{
|
||||
$aAttToLoad = array($oFilter->GetClassAlias() => array($this->m_sValueAttCode));
|
||||
}
|
||||
$aAttToLoad=array_merge($aAttToLoad,$aAdditionalFields);
|
||||
|
||||
$aComplementAttributeSpec = MetaModel::GetComplementAttributeSpec($sClass);
|
||||
$sFormatAdditionalField = $aComplementAttributeSpec[0];
|
||||
$aAdditionalField = $aComplementAttributeSpec[1];
|
||||
|
||||
if (count($aAdditionalField)>0)
|
||||
{
|
||||
$aAttToLoad = array_merge ($aAttToLoad, [$oFilter->GetClassAlias() => $aAdditionalField]);
|
||||
}
|
||||
|
||||
$oObjects->OptimizeColumnLoad($aAttToLoad);
|
||||
while ($oObject = $oObjects->Fetch())
|
||||
{
|
||||
@@ -475,9 +485,18 @@ class ValueSetObjects extends ValueSetDefinition
|
||||
{
|
||||
$aData['obsolescence_flag']='0';
|
||||
}
|
||||
foreach ($aAdditionalFields as $sFieldName)
|
||||
if (count($aAdditionalField)>0)
|
||||
{
|
||||
$aData[$sFieldName] = $oObject->Get($sFieldName);
|
||||
$aArguments = [];
|
||||
foreach ($aAdditionalField as $sAdditionalField)
|
||||
{
|
||||
array_push ($aArguments,$oObject->Get($sAdditionalField));
|
||||
}
|
||||
$aData['additional_field'] = vsprintf($sFormatAdditionalField, $aArguments);
|
||||
}
|
||||
else
|
||||
{
|
||||
$aData['additional_field']='';
|
||||
}
|
||||
$this->m_aValues[$oObject->GetKey()] = $aData;
|
||||
}
|
||||
|
||||
@@ -61,6 +61,10 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper
|
||||
{
|
||||
val = item.label;
|
||||
}
|
||||
if (item.additional_field != undefined )
|
||||
{
|
||||
val = val+'<br><i>'+item.additional_field+'</i>';
|
||||
}
|
||||
return $("<div>")
|
||||
.append(val);
|
||||
}
|
||||
@@ -145,9 +149,13 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper
|
||||
{
|
||||
val = ' <span class="object-ref-icon fas fa-eye-slash object-obsolete fa-1x fa-fw"></span>'+val;
|
||||
}
|
||||
val='<d>'+val+'</d>';
|
||||
if (item.additional_field != undefined )
|
||||
{
|
||||
val = val+'<br><i>'+item.additional_field+'</i>';
|
||||
}
|
||||
|
||||
return $("<li>")
|
||||
.append(val)
|
||||
.append("<d>"+val+"</d>")
|
||||
.appendTo(ul);
|
||||
};
|
||||
|
||||
|
||||
@@ -1140,6 +1140,33 @@ EOF
|
||||
}
|
||||
}
|
||||
|
||||
if ($oAdditionalValueForSelect = $oProperties->GetOptionalElement('complement_for_select'))
|
||||
{
|
||||
$oNameAttributes = $oAdditionalValueForSelect->GetUniqueElement('attributes');
|
||||
/** @var \DOMNodeList $oAttributes */
|
||||
$oAttributes = $oNameAttributes->getElementsByTagName('attribute');
|
||||
$aNameAttCodes = array();
|
||||
/** @var \MFElement $oAttribute */
|
||||
foreach($oAttributes as $oAttribute)
|
||||
{
|
||||
$aNameAttCodes[] = $oAttribute->getAttribute('id');
|
||||
}
|
||||
if (count($aNameAttCodes) > 0)
|
||||
{
|
||||
// New style...
|
||||
$sNameAttCode = "array('".implode("', '", $aNameAttCodes)."')";
|
||||
}
|
||||
else
|
||||
{
|
||||
$sNameAttCode = "''";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$sNameAttCode = "''";
|
||||
}
|
||||
$aClassParams['name_complement_for_select'] = $sNameAttCode;
|
||||
|
||||
if ($oUniquenessRules = $oProperties->GetOptionalElement('uniqueness_rules'))
|
||||
{
|
||||
$aUniquenessRules = array();
|
||||
|
||||
Reference in New Issue
Block a user