From 05485b838efd165781d9b31dce4e4195caf0a9c2 Mon Sep 17 00:00:00 2001 From: Eric Date: Tue, 28 Jan 2020 15:00:00 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B0985=20-=20Add=20applicable=20contexts=20?= =?UTF-8?q?on=20Trigger=20(display=20read-only)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/attributedef.class.inc.php | 55 ++++++++++++++++++++++++++------- css/light-grey.scss | 4 +-- 2 files changed, 46 insertions(+), 13 deletions(-) diff --git a/core/attributedef.class.inc.php b/core/attributedef.class.inc.php index 4603f25a46..00679ecbe3 100644 --- a/core/attributedef.class.inc.php +++ b/core/attributedef.class.inc.php @@ -10024,7 +10024,8 @@ abstract class AttributeSet extends AttributeDBFieldVoid { if ($value instanceof ormSet) { - $value = $value->GetValues(); + $aValues = $value->GetValues(); + return $this->GenerateViewHtmlForValues($aValues); } if (is_array($value)) { @@ -10033,6 +10034,47 @@ abstract class AttributeSet extends AttributeDBFieldVoid return $value; } + /** + * HTML representation of a list of values (read-only) + * accept a list of strings + * + * @param array $aValues + * @param string $sCssClass + * @param bool $bWithLink if true will generate a link, otherwise just a "a" tag without href + * + * @return string + * @throws \CoreException + * @throws \OQLException + */ + public function GenerateViewHtmlForValues($aValues, $sCssClass = '', $bWithLink = true) + { + if (empty($aValues)) {return '';} + $sHtml = ''; + foreach($aValues as $sValue) + { + $sClass = MetaModel::GetAttributeOrigin($this->GetHostClass(), $this->GetCode()); + $sAttCode = $this->GetCode(); + $sLabel = utils::HtmlEntities($this->GetValueLabel($sValue)); + $sDescription = utils::HtmlEntities($this->GetValueDescription($sValue)); + $oFilter = DBSearch::FromOQL("SELECT $sClass WHERE $sAttCode MATCHES '$sValue'"); + $oAppContext = new ApplicationContext(); + $sContext = $oAppContext->GetForLink(); + $sUIPage = cmdbAbstractObject::ComputeStandardUIPage($oFilter->GetClass()); + $sFilter = rawurlencode($oFilter->serialize()); + $sLink = ''; + if ($bWithLink) + { + $sUrl = utils::GetAbsoluteUrlAppRoot()."pages/$sUIPage?operation=search&filter=".$sFilter."&{$sContext}"; + $sLink = ' href="'.$sUrl.'"'; + } + $sHtml .= ''.$sLabel.''; + } + $sHtml .= ''; + + return $sHtml; + } + /** * @param $value * @param string $sSeparator @@ -10176,16 +10218,7 @@ class AttributeEnumSet extends AttributeSet { if ($value instanceof ormSet) { - /** @var ormSet $oOrmSet */ - $oOrmSet = $value; - $aRes = array(); - foreach ($oOrmSet->GetValues() as $sValue) - { - $sLabel = $this->GetValueLabel($sValue); - $sDescription = $this->GetValueDescription($sValue); - $aRes[] = "".parent::GetAsHtml($sLabel).""; - } - $sRes = implode(', ', $aRes); + $sRes = $this->GenerateViewHtmlForValues($value->GetValues()); } else { diff --git a/css/light-grey.scss b/css/light-grey.scss index 67c348225b..1f0d0cb9a8 100644 --- a/css/light-grey.scss +++ b/css/light-grey.scss @@ -3563,9 +3563,9 @@ table.listResults .originColor{ @extend %attribute-set-item-edition; } ////////////////////// -// TagSet attribute // +// Set attribute // // Always styled like the selectize items, see below. -.attribute-tag-set.attribute-set{ +.attribute-set{ .attribute-set-item{ @extend %attribute-set-item-edition; }