mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-27 22:24:12 +01:00
(Retrofit from trunk) Portal : Request template list fields now have the autocomplete option.
SVN:2.3[4367]
This commit is contained in:
@@ -646,6 +646,8 @@ class ObjectController extends AbstractController
|
||||
|
||||
// Retrieving parameters
|
||||
$sQuery = $aRequestContent['sQuery'];
|
||||
$sFormPath = $aRequestContent['sFormPath'];
|
||||
$sFieldId = $aRequestContent['sFieldId'];
|
||||
|
||||
// Checking security layers
|
||||
if (!SecurityHelper::IsActionAllowed($oApp, UR_ACTION_READ, $sHostObjectClass, $sHostObjectId))
|
||||
@@ -698,20 +700,52 @@ class ObjectController extends AbstractController
|
||||
// Building search query
|
||||
// - Retrieving target object class from attcode
|
||||
$oTargetAttDef = MetaModel::GetAttributeDef($sHostObjectClass, $sTargetAttCode);
|
||||
$sTargetObjectClass = $oTargetAttDef->GetTargetClass();
|
||||
if ($oTargetAttDef->GetEditClass() === 'CustomFields')
|
||||
{
|
||||
$oRequestTemplate = $oHostObject->Get($sTargetAttCode);
|
||||
$oTemplateFieldSearch = $oRequestTemplate->GetForm()->GetField('user_data')->GetForm()->GetField($sFieldId)->GetSearch();
|
||||
$sTargetObjectClass = $oTemplateFieldSearch->GetClass();
|
||||
}
|
||||
elseif ($oTargetAttDef->IsLinkSet())
|
||||
{
|
||||
throw new Exception('Search autocomplete cannot apply on AttributeLinkedSet objects, ' . get_class($oTargetAttDef) . ' (' . $sHostObjectClass . '->' . $sTargetAttCode . ') given.');
|
||||
}
|
||||
else
|
||||
{
|
||||
$sTargetObjectClass = $oTargetAttDef->GetTargetClass();
|
||||
}
|
||||
// - Base query from meta model
|
||||
$oSearch = DBSearch::FromOQL($oTargetAttDef->GetValuesDef()->GetFilterExpression());
|
||||
if ($oTargetAttDef->GetEditClass() === 'CustomFields')
|
||||
{
|
||||
$oSearch = $oTemplateFieldSearch;
|
||||
}
|
||||
else
|
||||
{
|
||||
$oSearch = DBSearch::FromOQL($oTargetAttDef->GetValuesDef()->GetFilterExpression());
|
||||
}
|
||||
// - Adding query condition
|
||||
$oSearch->AddConditionExpression(new BinaryExpression(new FieldExpression('friendlyname', $oSearch->GetClassAlias()), 'LIKE', new VariableExpression('ac_query')));
|
||||
// - Intersecting with scope constraints
|
||||
$oSearch = $oSearch->Intersect($oApp['scope_validator']->GetScopeFilterForProfiles(UserRights::ListProfiles(), $sTargetObjectClass, UR_ACTION_READ));
|
||||
|
||||
// Note : This do NOT apply to custom fields as the portal administrator is not supposed to know which objects will be put in the templates.
|
||||
// It is the responsability of the template designer to write the right query so the user see only what he should.
|
||||
if ($oTargetAttDef->GetEditClass() !== 'CustomFields')
|
||||
{
|
||||
$oSearch = $oSearch->Intersect($oApp['scope_validator']->GetScopeFilterForProfiles(UserRights::ListProfiles(), $sTargetObjectClass, UR_ACTION_READ));
|
||||
}
|
||||
|
||||
// Retrieving results
|
||||
// - Preparing object set
|
||||
$oSet = new DBObjectSet($oSearch, array(), array('this' => $oHostObject, 'ac_query' => '%' . $sQuery . '%'));
|
||||
$oSet->OptimizeColumnLoad(array($oSearch->GetClassAlias() => array('friendlyname')));
|
||||
// Note : This limit is also used in the field renderer by typeahead to determine how many suggestions to display
|
||||
$oSet->SetLimit($oTargetAttDef->GetMaximumComboLength()); // TODO : Is this the right limit value ? We might want to use another parameter
|
||||
if ($oTargetAttDef->GetEditClass() === 'CustomFields')
|
||||
{
|
||||
$oSet->SetLimit(static::DEFAULT_COUNT_PER_PAGE_LIST);
|
||||
}
|
||||
else
|
||||
{
|
||||
$oSet->SetLimit($oTargetAttDef->GetMaximumComboLength()); // TODO : Is this the right limit value ? We might want to use another parameter
|
||||
}
|
||||
// - Retrieving objects
|
||||
while ($oItem = $oSet->Fetch())
|
||||
{
|
||||
|
||||
@@ -224,6 +224,8 @@ EOF
|
||||
settings.contentType = "application/json; charset=UTF-8";
|
||||
settings.data = {
|
||||
sQuery: query,
|
||||
sFormPath: '{$this->oField->GetFormPath()}',
|
||||
sFieldId: '{$this->oField->GetId()}',
|
||||
formmanager_class: $("[data-field-id='{$this->oField->GetId()}'][data-form-path='{$this->oField->GetFormPath()}']").closest('.portal_form_handler').portal_form_handler('getOptions').formmanager_class,
|
||||
formmanager_data: $("[data-field-id='{$this->oField->GetId()}'][data-form-path='{$this->oField->GetFormPath()}']").closest('.portal_form_handler').portal_form_handler('getOptions').formmanager_data,
|
||||
current_values: $("[data-field-id='{$this->oField->GetId()}'][data-form-path='{$this->oField->GetFormPath()}']").closest('.portal_form_handler').portal_form_handler('getCurrentValues')
|
||||
|
||||
Reference in New Issue
Block a user