N°931 change CSS for displaying TagSet datas

This commit is contained in:
Pierre Goiffon
2018-09-06 18:33:15 +02:00
parent da71004898
commit f2b914a4c5
3 changed files with 95 additions and 76 deletions

View File

@@ -6054,65 +6054,84 @@ class AttributeTagSet extends AttributeDBFieldVoid
* @throws \CoreException
* @throws \Exception
*/
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
{
if ($value instanceof ormTagSet)
{
if ($bLocalize)
{
$aValues = $value->GetTags();
}
else
{
$aValues = $value->GetValue();
}
if (empty($aValues))
{
return '';
}
return '<span class="attribute-tagset">'.implode('</span><span class="attribute-tagset">', $aValues).'</span>';
}
if (is_string($value))
{
try
{
$oValue = $this->MakeRealValue($value, $oHostObject);
return $this->GetAsHTML($oValue, $oHostObject, $bLocalize);
}
catch (Exception $e)
{
// unknown tags are present display the code instead
}
$aTagCodes = explode(' ', $value);
$aValues = array();
$oTagSet = new ormTagSet(MetaModel::GetAttributeOrigin($this->GetHostClass(), $this->GetCode()), $this->GetCode());
foreach ($aTagCodes as $sTagCode)
{
try
{
$oTagSet->AddTag($sTagCode);
}
catch (Exception $e)
{
$aValues[] = $sTagCode;
}
}
$sHTML = '';
if (!empty($aValues))
{
$sHTML .= '<span class="attribute-tagset-undefined">'.implode('</span><span class="attribute-tagset-undefined">', $aValues).'</span>';
}
$aValues = $oTagSet->GetTags();
if (!empty($aValues))
{
$sHTML .= '<span class="attribute-tagset">'.implode('</span><span class="attribute-tagset">', $aValues).'</span>';
}
public function GetAsHTML($value, $oHostObject = null, $bLocalize = true)
{
if ($value instanceof ormTagSet)
{
if ($bLocalize)
{
$aValues = $value->GetTags();
}
else
{
$aValues = $value->GetValue();
}
if (empty($aValues))
{
return '';
}
return $sHTML;
}
return parent::GetAsHTML($value, $oHostObject, $bLocalize);
return $this->GenerateViewHtmlForValues($aValues);
}
if (is_string($value))
{
try
{
$oValue = $this->MakeRealValue($value, $oHostObject);
}
return $this->GetAsHTML($oValue, $oHostObject, $bLocalize);
} catch (Exception $e)
{
// unknown tags are present display the code instead
}
$aTagCodes = explode(' ', $value);
$aValues = array();
$oTagSet = new ormTagSet(MetaModel::GetAttributeOrigin($this->GetHostClass(), $this->GetCode()),
$this->GetCode());
foreach($aTagCodes as $sTagCode)
{
try
{
$oTagSet->AddTag($sTagCode);
} catch (Exception $e)
{
$aValues[] = $sTagCode;
}
}
$sHTML = '';
if (!empty($aValues))
{
$sHTML .= $this->GenerateViewHtmlForValues($aValues, 'attribute-tagset-undefined');
}
$aValues = $oTagSet->GetTags();
if (!empty($aValues))
{
$sHTML .= $this->GenerateViewHtmlForValues($aValues);
}
return $sHTML;
}
return parent::GetAsHTML($value, $oHostObject, $bLocalize);
}
/**
* @param array $aValues
* @param string $sCssClass
*
* @return string
*/
private function GenerateViewHtmlForValues($aValues, $sCssClass = 'attribute-tagset')
{
$sHtml = '<span class="'.$sCssClass.'">';
foreach($aValues as $sTagSetLabel)
{
$sHtml .= '<span>'.$sTagSetLabel.'</span>';
}
$sHtml .= '</span>';
return $sHtml;
}
/**
* @param $value

View File

@@ -2862,20 +2862,21 @@ table.listResults .originColor {
.menu-icon-select > .ui-menu-item {
padding: 0.3em 3%;
}
.attribute-tagset {
.attribute-tagset > span, .attribute-tagset-undefined > span {
display: inline-block;
padding: 3px;
background-color: grey;
margin-right: 3px;
border-radius: 4px;
}
.attribute-tagset > span {
color: white;
margin-right: 3px;
border-radius: 4px;
background-color: grey;
}
.attribute-tagset-undefined {
.attribute-tagset-undefined > span {
color: grey;
font-style: italic;
display: inline-block;
padding: 3px;
background-color: lightgrey;
margin-right: 3px;
border-radius: 4px;
font-style: italic;
}

View File

@@ -3261,21 +3261,20 @@ table.listResults .originColor{
padding: .3em 3%;
}
.attribute-tagset{
.attribute-tagset > span, .attribute-tagset-undefined > span {
display: inline-block;
padding: 3px;
background-color: grey;
color: white;
margin-right: 3px;
border-radius: 4px;
}
.attribute-tagset-undefined{
.attribute-tagset > span {
color: white;
background-color: grey;
}
.attribute-tagset-undefined > span {
color: grey;
font-style: italic;
display: inline-block;
padding: 3px;
background-color: lightgrey;
margin-right: 3px;
border-radius: 4px;
font-style: italic;
}