Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

N°7146 - Fix style not applied in list in the end-users portal in iTop 3.0+ #635

Open
wants to merge 4 commits into
base: support/3.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -1408,14 +1408,14 @@ public function GetInformationForLinkedSetAsJsonAction(Request $oRequest)
protected function PrepareObjectInformation(DBObject $oObject, $aAttCodes = array())
{
$sObjectClass = get_class($oObject);
$aObjectData = array(
'id' => $oObject->GetKey(),
'name' => $oObject->GetName(),
'attributes' => array(),
);
$aObjectData = [
'id' => $oObject->GetKey(),
'name' => $oObject->GetName(),
'attributes' => [],
];

// Retrieving attributes definitions
$aAttDefs = array();
$aAttDefs = [];
foreach ($aAttCodes as $sAttCode)
{
if ($sAttCode === 'id')
Expand All @@ -1429,13 +1429,30 @@ protected function PrepareObjectInformation(DBObject $oObject, $aAttCodes = arra
// Preparing attribute data
foreach ($aAttDefs as $oAttDef)
{
$aAttData = array(
'att_code' => $oAttDef->GetCode(),
);
$aAttData = [
'object_class' => $sObjectClass,
'object_id' => $oObject->GetKey(),
'attribute_code' => $oAttDef->GetCode(),
'attribute_type' => get_class($oAttDef),
];

// - Value raw
// For simple fields, we get the raw (stored) value as well
$bExcludeRawValue = false;
foreach (ApplicationHelper::GetAttDefClassesToExcludeFromMarkupMetadataRawValue() as $sAttDefClassToExclude)
{
if (is_a($oAttDef, $sAttDefClassToExclude, true))
{
$bExcludeRawValue = true;
break;
}
}
$aAttData['value_raw'] = ($bExcludeRawValue === false) ? $oObject->Get($oAttDef->GetCode()) : null;


if ($oAttDef->IsExternalKey())
{
$aAttData['value'] = $oObject->GetAsHTML($oAttDef->GetCode().'_friendlyname');
$aAttData['value_html'] = $oObject->GetAsHTML($oAttDef->GetCode().'_friendlyname');

// Checking if user can access object's external key
if ($this->oSecurityHelper->IsActionAllowed(UR_ACTION_READ, $oAttDef->GetTargetClass()))
Expand Down Expand Up @@ -1467,14 +1484,14 @@ protected function PrepareObjectInformation(DBObject $oObject, $aAttCodes = arra
{
$sUrl = $oAttDef->Get('default_image');
}
$aAttData['value'] = '<img src="'.$sUrl.'" />';
$aAttData['value_html'] = '<img src="'.$sUrl.'" />';
}
elseif ($oAttDef instanceof AttributeEnum) {
$aAttData['value'] = $oAttDef->GetAsPlainText($oObject->Get($oAttDef->GetCode()));
$aAttData['value_html'] = $oAttDef->GetAsPlainText($oObject->Get($oAttDef->GetCode()));
}
else
{
$aAttData['value'] = $oAttDef->GetAsHTML($oObject->Get($oAttDef->GetCode()));
$aAttData['value_html'] = $oAttDef->GetAsHTML($oObject->Get($oAttDef->GetCode()));

if ($oAttDef instanceof AttributeFriendlyName)
{
Expand Down
Expand Up @@ -9,7 +9,7 @@
<div id="{{ sFormId }}">
{#<div class="form_alerts"></div>#}
<div class="form_fields">
<table id="{{ sTableId }}" class="table table-striped table-bordered responsive" cellspacing="0" width="100%">
<table id="{{ sTableId }}" class="object-list table table-striped table-bordered responsive" cellspacing="0" width="100%">
<tbody>
</tbody>
</table>
Expand Down Expand Up @@ -66,22 +66,35 @@
"title": oColumnProperties[sKey].title,
"defaultContent": "",
"type": "html",
"data": "attributes."+sKey+".att_code",
"render": function(data, type, row){
"data": "attributes."+sKey+".attribute_code",
"render": function(attribute_code, type, row){
var cellElem;
var metadataNames = ['object_class', 'object_id', 'attribute_code', 'attribute_type', 'value_raw'];

// Preparing the cell data
if(row.attributes[data].url !== undefined)
if(row.attributes[attribute_code].url !== undefined)
{
cellElem = $('<a></a>');
cellElem.attr('target', '_blank').attr('href', row.attributes[data].url);
cellElem.attr('target', '_blank').attr('href', row.attributes[attribute_code].url);
}
else
{
cellElem = $('<span></span>');
}
cellElem.attr('data-object-id', row.id).html('<span>' + row.attributes[data].value + '</span>');

//Add markup
for(var sPropName in row.attributes[attribute_code])
{
var propValue = row.attributes[attribute_code][sPropName];
if(sPropName === 'value_html')
{
cellElem.html(propValue);
}
else if(metadataNames.indexOf(sPropName) > -1)
{
cellElem.attr('data-'+sPropName.replace('_', '-'), propValue)
}
}

return cellElem.prop('outerHTML');
},
});
Expand All @@ -92,7 +105,6 @@

$(document).ready(function(){
showTableLoader();

// Note : Those options should be externalized in an library so we can use them on any DataTables for the portal.
// We would just have to override / complete the necessary elements
oTable = $('#{{ sTableId }}').DataTable({
Expand Down
Expand Up @@ -221,7 +221,7 @@ public function Render()
"className": {$sIsEditable} && aColumnProperties.mandatory ? 'mandatory' : '',
"render": function(data, type, row){
var cellElem;

// Preparing the cell data
if(data.url !== undefined)
{
Expand All @@ -232,7 +232,7 @@ public function Render()
{
cellElem = $('<span></span>');
}
cellElem.html('<span>' + data.value + '</span>');
cellElem.html('<span>' + data.value_html + '</span>');

return cellElem.prop('outerHTML');
},
Expand Down Expand Up @@ -266,7 +266,7 @@ public function Render()
{
cellElem = $('<span></span>');
}
cellElem.html('<span>' + data.value + '</span>');
cellElem.html('<span>' + data.value_html + '</span>');

return cellElem.prop('outerHTML');
},
Expand Down Expand Up @@ -787,7 +787,6 @@ protected function InjectRendererFileAssets(string $sClass, array $aAttributesCo
static::TransferFieldRendererGlobalOutput($oFieldOutput, $oOutput);
}
}

}

/**
Expand Down Expand Up @@ -835,23 +834,23 @@ protected function PrepareItem(DBObject $oItem, string $sClass, array $aAttribut
$oFieldOutput = $oFieldRenderer->Render();
$aAttProperties['js_inline'] = $oFieldOutput->GetJs();
$aAttProperties['css_inline'] = $oFieldOutput->GetCss();
$aAttProperties['value'] = $oFieldOutput->GetHtml();
$aAttProperties['value_html'] = $oFieldOutput->GetHtml();
}

} else if ($oAttDef->IsExternalKey()) {

/** @var \AttributeExternalKey $oAttDef */
$aAttProperties['value'] = $oItem->Get($sAttCode.'_friendlyname');
$aAttProperties['value_html'] = $oItem->Get($sAttCode.'_friendlyname');

// Checking if user can access object's external key
$sObjectUrl = ApplicationContext::MakeObjectUrl($sClass, $oItem->Get($sAttCode));
$sObjectUrl = ApplicationContext::MakeObjectUrl($oAttDef->GetTargetClass(), $oItem->Get($sAttCode));
if (!empty($sObjectUrl)) {
$aAttProperties['url'] = $sObjectUrl;
}

} else { // Others attributes

$aAttProperties['value'] = $oAttDef->GetAsHTML($oItem->Get($sAttCode));
$aAttProperties['value_html'] = $oAttDef->GetAsHTML($oItem->Get($sAttCode));

if ($oAttDef instanceof AttributeFriendlyName) {
// Checking if user can access object
Expand Down