From 28ead17d00a86d0f3c3f30887f22d5f155ed6bef Mon Sep 17 00:00:00 2001 From: Guillaume Lajarige Date: Fri, 2 Sep 2016 11:59:57 +0000 Subject: [PATCH] (Retrofit from trunk) Portal : Request template list fields now have the autocomplete option. SVN:2.3[4367] --- .../objectcontroller.class.inc.php | 44 ++++++++++++++++--- .../bsselectobjectfieldrenderer.class.inc.php | 2 + 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/datamodels/2.x/itop-portal-base/portal/src/controllers/objectcontroller.class.inc.php b/datamodels/2.x/itop-portal-base/portal/src/controllers/objectcontroller.class.inc.php index 18a1561b1..a716986b4 100644 --- a/datamodels/2.x/itop-portal-base/portal/src/controllers/objectcontroller.class.inc.php +++ b/datamodels/2.x/itop-portal-base/portal/src/controllers/objectcontroller.class.inc.php @@ -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()) { diff --git a/sources/renderer/bootstrap/fieldrenderer/bsselectobjectfieldrenderer.class.inc.php b/sources/renderer/bootstrap/fieldrenderer/bsselectobjectfieldrenderer.class.inc.php index 1784ce429..71b12f96f 100644 --- a/sources/renderer/bootstrap/fieldrenderer/bsselectobjectfieldrenderer.class.inc.php +++ b/sources/renderer/bootstrap/fieldrenderer/bsselectobjectfieldrenderer.class.inc.php @@ -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')