diff --git a/application/cmdbabstract.class.inc.php b/application/cmdbabstract.class.inc.php index 50defc8419..ed1b2ddc8f 100644 --- a/application/cmdbabstract.class.inc.php +++ b/application/cmdbabstract.class.inc.php @@ -2033,6 +2033,7 @@ EOF $oPage->add_ready_script("$('#{$iId}').bind('validate', function(evt, sFormId) { return ValidateCustomFields('$iId', sFormId) } );"); // Custom validation function break; + case 'Set': case 'TagSet': $oPage->add_linked_script(utils::GetAbsoluteUrlAppRoot().'/js/selectize.min.js'); $oPage->add_linked_stylesheet(utils::GetAbsoluteUrlAppRoot().'css/selectize.default.css'); @@ -2040,27 +2041,11 @@ EOF $oPage->add_dict_entry('Core:AttributeSet:placeholder'); - /** @var \ormTagSet $value */ - $sJson = $oAttDef->GetJsonForWidget($value, $aArgs); - $sInputId = "attr_{$sFormPrefix}{$sAttCode}"; - $sHTMLValue = "
{$sValidationSpan}{$sReloadSpan}"; - $sScript = "$('#$sInputId').set_widget();"; - $oPage->add_ready_script($sScript); - - break; - - case 'ClassAttCodeSet': - $oPage->add_linked_script(utils::GetAbsoluteUrlAppRoot().'/js/selectize.min.js'); - $oPage->add_linked_stylesheet(utils::GetAbsoluteUrlAppRoot().'css/selectize.default.css'); - $oPage->add_linked_script(utils::GetAbsoluteUrlAppRoot().'/js/jquery.itop-tagset-widget.js'); - - $oPage->add_dict_entry('Core:AttributeTagSet:placeholder'); - /** @var \ormSet $value */ $sJson = $oAttDef->GetJsonForWidget($value, $aArgs); $sInputId = "attr_{$sFormPrefix}{$sAttCode}"; $sHTMLValue = "{$sValidationSpan}{$sReloadSpan}"; - $sScript = "$('#$sInputId').tagset_widget();"; + $sScript = "$('#$sInputId').set_widget();"; $oPage->add_ready_script($sScript); break; @@ -3313,7 +3298,7 @@ EOF $this->Set($sAttCode, $oTagSet); break; - case 'ClassAttCodeSet': + case 'Set': /** @var ormSet $oSet */ $oSet = $this->Get($sAttCode); if (is_null($oSet)) @@ -3514,8 +3499,8 @@ EOF ); break; + case 'Set': case 'TagSet': - case 'ClassAttCodeSet': $sTagSetJson = utils::ReadPostedParam("attr_{$sFormPrefix}{$sAttCode}", null, 'raw_data'); $value = json_decode($sTagSetJson, true); break; @@ -4008,7 +3993,6 @@ EOF $iFormId = cmdbAbstractObject::GetNextFormId(); // Identifier that prefixes all the form fields $sReadyScript = ''; - $aDependsOn = array(); $sFormPrefix = '2_'; foreach($aList as $sAttCode => $oAttDef) { @@ -4087,7 +4071,7 @@ EOF $sTip = addslashes($sTip); $sReadyScript .= "$('#multi_values_$sAttCode').qtip( { content: '$sTip', show: 'mouseover', hide: 'mouseout', style: { name: 'dark', tip: 'leftTop' }, position: { corner: { target: 'rightMiddle', tooltip: 'leftTop' }} } );"; - if (($oAttDef->GetEditClass() == 'TagSet') || ($oAttDef->GetEditClass() == 'ClassAttCodeSet')) + if (($oAttDef->GetEditClass() == 'TagSet') || ($oAttDef->GetEditClass() == 'Set')) { // Set the value by adding the values to the first one reset($aMultiValues); diff --git a/core/attributedef.class.inc.php b/core/attributedef.class.inc.php index d9a84f984d..2eda60ddb4 100644 --- a/core/attributedef.class.inc.php +++ b/core/attributedef.class.inc.php @@ -123,7 +123,7 @@ abstract class AttributeDefinition const SEARCH_WIDGET_TYPE_EXTERNAL_FIELD = 'external_field'; const SEARCH_WIDGET_TYPE_DATE_TIME = 'date_time'; const SEARCH_WIDGET_TYPE_DATE = 'date'; - const SEARCH_WIDGET_TYPE_TAG_SET = 'tag_set'; + const SEARCH_WIDGET_TYPE_SET = 'set'; const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_RAW; @@ -3171,6 +3171,11 @@ class AttributeClassState extends AttributeString { const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_ENUM; + static public function ListExpectedParams() + { + return array_merge(parent::ListExpectedParams(), array('class_field')); + } + public function GetAllowedValues($aArgs = array(), $sContains = '') { if (isset($aArgs['this'])) @@ -6758,8 +6763,6 @@ class AttributeExternalField extends AttributeDefinition */ class AttributeTagSet extends AttributeSet { - const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_TAG_SET; - static public function ListExpectedParams() { return array_merge(parent::ListExpectedParams(), array('tag_code_max_len')); @@ -6804,7 +6807,7 @@ class AttributeTagSet extends AttributeSet $aJson['removed'] = array(); $iMaxTags = $this->GetMaxItems(); - $aJson['max_tags_allowed'] = $iMaxTags; + $aJson['max_items_allowed'] = $iMaxTags; return json_encode($aJson); } @@ -6873,11 +6876,6 @@ class AttributeTagSet extends AttributeSet return $this->Get('tag_code_max_len'); } - public function GetEditClass() - { - return "TagSet"; - } - public function GetEditValue($value, $oHostObj = null) { if (empty($value)) @@ -6896,17 +6894,7 @@ class AttributeTagSet extends AttributeSet public function GetMaxSize() { - return $iLen = ($this->GetMaxItems() * $this->GetTagCodeMaxLength()) + 1; - } - - public function RequiresIndex() - { - return true; - } - - public function RequiresFullTextIndex() - { - return true; + return max(255, ($this->GetMaxItems() * $this->GetTagCodeMaxLength()) + 1); } public function Equals($val1, $val2) @@ -9375,22 +9363,40 @@ class AttributePropertySet extends AttributeTable /** * An unordered multi values attribute + * Allowed values are mandatory for this attribute to be modified * * Class AttributeSet */ class AttributeSet extends AttributeDBFieldVoid { + const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_SET; + static public function ListExpectedParams() { return array_merge(parent::ListExpectedParams(), array('is_null_allowed', 'max_items')); } + /** + * Allowed values are mandatory for this attribute to be modified + * + * @param array $aArgs + * @param string $sContains + * + * @return array|null + * @throws \CoreException + * @throws \OQLException + */ + public function GetAllowedValues($aArgs = array(), $sContains = '') + { + return parent::GetAllowedValues($aArgs, $sContains); + } + /** * @param \ormSet $oValue * * @param $aArgs * - * @return string JSON to be used in the itop.tagset_widget JQuery widget + * @return string JSON to be used in the itop.set_widget JQuery widget * @throws \CoreException * @throws \OQLException */ @@ -9440,11 +9446,21 @@ class AttributeSet extends AttributeDBFieldVoid $aJson['removed'] = array(); $iMaxTags = $this->GetMaxItems(); - $aJson['max_tags_allowed'] = $iMaxTags; + $aJson['max_items_allowed'] = $iMaxTags; return json_encode($aJson); } + public function RequiresIndex() + { + return true; + } + + public function RequiresFullTextIndex() + { + return true; + } + public function GetDefaultValue(DBObject $oHostObject = null) { return null; @@ -9705,14 +9721,9 @@ class AttributeClassAttCodeSet extends AttributeSet return array_merge(parent::ListExpectedParams(), array('class_field', 'attribute_definition_list')); } - public function GetEditClass() - { - return "ClassAttCodeSet"; - } - public function GetMaxSize() { - return 255; + return max(255, 15 * $this->GetMaxItems()); } public function GetAllowedValues($aArgs = array(), $sContains = '') @@ -9724,7 +9735,14 @@ class AttributeClassAttCodeSet extends AttributeSet $sClass = $oHostObj->Get($sTargetClass); $aAllowedAttributes = array(); - $aAllAttributes = MetaModel::GetAttributesList($sClass); + if (empty($sClass)) + { + $aAllAttributes = array(); + } + else + { + $aAllAttributes = MetaModel::GetAttributesList($sClass); + } $sAttDefList = $this->Get('attribute_definition_list'); if (!empty($sAttDefList)) { diff --git a/core/oql/expression.class.inc.php b/core/oql/expression.class.inc.php index 5c8d343350..e76e108bc8 100644 --- a/core/oql/expression.class.inc.php +++ b/core/oql/expression.class.inc.php @@ -677,7 +677,7 @@ class BinaryExpression extends Expression } } } - if (isset($aCriteriaLeft['widget']) && isset($aCriteriaRight['widget']) && ($aCriteriaLeft['widget'] == AttributeDefinition::SEARCH_WIDGET_TYPE_TAG_SET) && ($aCriteriaRight['widget'] == AttributeDefinition::SEARCH_WIDGET_TYPE_TAG_SET)) + if (isset($aCriteriaLeft['widget']) && isset($aCriteriaRight['widget']) && ($aCriteriaLeft['widget'] == AttributeDefinition::SEARCH_WIDGET_TYPE_SET) && ($aCriteriaRight['widget'] == AttributeDefinition::SEARCH_WIDGET_TYPE_SET)) { $aCriteriaOverride['operator'] = 'MATCHES'; } diff --git a/setup/compiler.class.inc.php b/setup/compiler.class.inc.php index dc15cd4f7b..2ce108e157 100644 --- a/setup/compiler.class.inc.php +++ b/setup/compiler.class.inc.php @@ -1389,20 +1389,49 @@ EOF $aParameters['handler_class'] = $this->GetMandatoryPropString($oField, 'handler_class'); } elseif ($sAttType == 'AttributeTagSet') - { - $aTagFieldsInfo[] = $sAttCode; - $aParameters['allowed_values'] = 'null'; // or "new ValueSetEnum('SELECT xxxx')" - $aParameters['sql'] = $this->GetMandatoryPropString($oField, 'sql'); - $aParameters['is_null_allowed'] = $this->GetPropBoolean($oField, 'is_null_allowed', false); - $aParameters['depends_on'] = $sDependencies; - $aParameters['max_items'] = $this->GetPropNumber($oField, 'max_items', 12); - $aParameters['tag_code_max_len'] = $this->GetPropNumber($oField, 'tag_code_max_len', 20); - if ($aParameters['tag_code_max_len'] > 255) - { - $aParameters['tag_code_max_len'] = 255; - } - } - else + { + $aTagFieldsInfo[] = $sAttCode; + $aParameters['allowed_values'] = 'null'; // or "new ValueSetEnum('SELECT xxxx')" + $aParameters['sql'] = $this->GetMandatoryPropString($oField, 'sql'); + $aParameters['is_null_allowed'] = $this->GetPropBoolean($oField, 'is_null_allowed', false); + $aParameters['depends_on'] = $sDependencies; + $aParameters['max_items'] = $this->GetPropNumber($oField, 'max_items', 12); + $aParameters['tag_code_max_len'] = $this->GetPropNumber($oField, 'tag_code_max_len', 20); + if ($aParameters['tag_code_max_len'] > 255) + { + $aParameters['tag_code_max_len'] = 255; + } + } + elseif ($sAttType == 'AttributeSet') + { + $aTagFieldsInfo[] = $sAttCode; + $aParameters['allowed_values'] = 'null'; // or "new ValueSetEnum('SELECT xxxx')" + $aParameters['sql'] = $this->GetMandatoryPropString($oField, 'sql'); + $aParameters['is_null_allowed'] = $this->GetPropBoolean($oField, 'is_null_allowed', false); + $aParameters['depends_on'] = $sDependencies; + $aParameters['max_items'] = $this->GetPropNumber($oField, 'max_items', 12); + } + elseif ($sAttType == 'AttributeClassAttCodeSet') + { + $aTagFieldsInfo[] = $sAttCode; + $aParameters['allowed_values'] = 'null'; // or "new ValueSetEnum('SELECT xxxx')" + $aParameters['sql'] = $this->GetMandatoryPropString($oField, 'sql'); + $aParameters['is_null_allowed'] = $this->GetPropBoolean($oField, 'is_null_allowed', false); + $aParameters['depends_on'] = $sDependencies; + $aParameters['max_items'] = $this->GetPropNumber($oField, 'max_items', 12); + $aParameters['class_field'] = $this->GetMandatoryPropString($oField, 'class_field'); + $aParameters['attribute_definition_list'] = $this->GetPropString($oField, 'attribute_definition_list', ''); + } + elseif ($sAttType == 'AttributeClassState') + { + $aTagFieldsInfo[] = $sAttCode; + $aParameters['allowed_values'] = 'null'; // or "new ValueSetEnum('SELECT xxxx')" + $aParameters['sql'] = $this->GetMandatoryPropString($oField, 'sql'); + $aParameters['is_null_allowed'] = $this->GetPropBoolean($oField, 'is_null_allowed', false); + $aParameters['depends_on'] = $sDependencies; + $aParameters['class_field'] = $this->GetMandatoryPropString($oField, 'class_field'); + } + else { $aParameters['allowed_values'] = 'null'; // or "new ValueSetEnum('SELECT xxxx')" $aParameters['sql'] = $this->GetMandatoryPropString($oField, 'sql'); diff --git a/sources/application/search/criterionconversion/criteriontosearchform.class.inc.php b/sources/application/search/criterionconversion/criteriontosearchform.class.inc.php index 5cdb07d95e..7093cdc463 100644 --- a/sources/application/search/criterionconversion/criteriontosearchform.class.inc.php +++ b/sources/application/search/criterionconversion/criteriontosearchform.class.inc.php @@ -71,7 +71,7 @@ class CriterionToSearchForm extends CriterionConversionAbstract AttributeDefinition::SEARCH_WIDGET_TYPE_EXTERNAL_KEY => 'ExternalKeyToSearchForm', AttributeDefinition::SEARCH_WIDGET_TYPE_HIERARCHICAL_KEY => 'ExternalKeyToSearchForm', AttributeDefinition::SEARCH_WIDGET_TYPE_ENUM => 'EnumToSearchForm', - AttributeDefinition::SEARCH_WIDGET_TYPE_TAG_SET => 'TagSetToSearchForm', + AttributeDefinition::SEARCH_WIDGET_TYPE_SET => 'SetToSearchForm', ); foreach($aAndCriterionRaw as $aCriteria) @@ -667,7 +667,7 @@ class CriterionToSearchForm extends CriterionConversionAbstract return $aCriteria; } - protected static function TagSetToSearchForm($aCriteria, $aFields) + protected static function SetToSearchForm($aCriteria, $aFields) { $sOperator = $aCriteria['operator']; switch ($sOperator) @@ -700,6 +700,7 @@ class CriterionToSearchForm extends CriterionConversionAbstract break; case '=': + // TODO BUG SPLIT INTO AN 'AND' LIST OF MATCHES $aCriteria['operator'] = CriterionConversionAbstract::OP_EQUALS; if (isset($aCriteria['has_undefined']) && $aCriteria['has_undefined']) {