Browse Source

Portal : Request template list fields now have the autocomplete option.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@4351 a333f486-631f-4898-b8df-5754b55c2be0
glajarige 8 years ago
parent
commit
8210608219

+ 39 - 5
datamodels/2.x/itop-portal-base/portal/src/controllers/objectcontroller.class.inc.php

@@ -643,6 +643,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))
@@ -695,20 +697,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())
 		{

+ 2 - 0
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')