mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-19 00:28:47 +02:00
N°3549 - Activity panel: Fix inline images in caselogs
This commit is contained in:
@@ -31,6 +31,7 @@ use Combodo\iTop\Application\UI\Base\Component\Input\InputUIBlockFactory;
|
||||
use Combodo\iTop\Application\UI\Base\Component\Panel\Panel;
|
||||
use Combodo\iTop\Application\UI\Base\Component\Title\TitleUIBlockFactory;
|
||||
use Combodo\iTop\Application\UI\Base\Component\Toolbar\ToolbarUIBlockFactory;
|
||||
use Combodo\iTop\Application\UI\Base\Layout\ActivityPanel\ActivityPanel;
|
||||
use Combodo\iTop\Application\UI\Base\Layout\MultiColumn\Column\Column;
|
||||
use Combodo\iTop\Application\UI\Base\Layout\MultiColumn\MultiColumn;
|
||||
use Combodo\iTop\Application\UI\Base\Layout\Object\ObjectFactory;
|
||||
@@ -1011,6 +1012,16 @@ HTML
|
||||
</div><!-- End of object-details -->
|
||||
HTML
|
||||
);
|
||||
|
||||
// Note: Adding the JS snippet which enables the image upload should have been done directly by the ActivityPanel which would have kept the independance principle
|
||||
// of the UIBlock. For now we keep it this way in order to move on and trace this known limitation in N°3736.
|
||||
/** @var ActivityPanel $oActivityPanel */
|
||||
$oActivityPanel = $oPage->GetContentLayout()->GetSubBlock(ActivityPanel::BLOCK_CODE);
|
||||
if ($oActivityPanel->HasTransactionId()) {
|
||||
$iTransactionId = $oActivityPanel->GetTransactionId();
|
||||
$sTempId = utils::GetUploadTempId($iTransactionId);
|
||||
$oPage->add_ready_script(InlineImage::EnableCKEditorImageUpload($this, $sTempId));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -410,8 +410,6 @@ class AjaxRenderController
|
||||
$sObjectClass = utils::ReadPostedParam('object_class', null, utils::ENUM_SANITIZATION_FILTER_CLASS);
|
||||
$sObjectId = utils::ReadPostedParam('object_id', 0);
|
||||
$sTransactionId = utils::ReadPostedParam('transaction_id', null, utils::ENUM_SANITIZATION_FILTER_TRANSACTION_ID);
|
||||
// TODO 3.0.0: Remove this line when transaction handled
|
||||
$sTransactionId = 'foo';
|
||||
$aEntries = utils::ReadPostedParam('entries', [], utils::ENUM_SANITIZATION_FILTER_RAW_DATA);
|
||||
|
||||
// Consistency checks
|
||||
@@ -420,10 +418,13 @@ class AjaxRenderController
|
||||
throw new Exception('Missing mandatory parameters object_class / object_id / transaction_id / entries');
|
||||
}
|
||||
// - Transaction ID
|
||||
// TODO 3.0.0: Uncomment when transaction ID is passed (retrieved from the upcoming lock system)
|
||||
// if (!utils::IsTransactionValid($sTransactionId)) {
|
||||
// throw new Exception(Dict::S('iTopUpdate:Error:InvalidToken'));
|
||||
// }
|
||||
// Note: We keep the transaction ID for several reasons:
|
||||
// - We might send several messages, so renewing it would not make such a difference except making the follwoing line harder
|
||||
// - We need the transaction ID to passed in the JS snippet that allows images to be uploaded (see InlineImage::EnableCKEditorImageUpload()), renewing it would only make things more complicated
|
||||
// => For all those reasons, we let the GC clean the transactions IDs, just like when a transaction ID is not deleted when cancelling a regular object edition.
|
||||
if (!utils::IsTransactionValid($sTransactionId, false)) {
|
||||
throw new Exception(Dict::S('iTopUpdate:Error:InvalidToken'));
|
||||
}
|
||||
|
||||
$aResults = [
|
||||
'success' => true,
|
||||
@@ -451,10 +452,6 @@ class AjaxRenderController
|
||||
// Finalize inline images
|
||||
InlineImage::FinalizeInlineImages($oObject);
|
||||
|
||||
// Renew transaction ID
|
||||
utils::RemoveTransaction($sTransactionId);
|
||||
$aResults['renewed_transaction_id'] = utils::GetNewTransactionId();
|
||||
|
||||
return $aResults;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ use Combodo\iTop\Application\UI\Base\UIBlock;
|
||||
use DBObject;
|
||||
use Exception;
|
||||
use MetaModel;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* Class ActivityPanel
|
||||
@@ -62,6 +63,8 @@ class ActivityPanel extends UIBlock
|
||||
* @see \cmdbAbstractObject::ENUM_OBJECT_MODE_XXX
|
||||
*/
|
||||
protected $sObjectMode;
|
||||
/** @var null|string $sTransactionId Only when $sObjectMode is set to \cmdbAbstractObject::ENUM_OBJECT_MODE_VIEW */
|
||||
protected $sTransactionId;
|
||||
/** @var array $aCaseLogs Metadata of the case logs (att. code, color, ...), will be use to make the tabs and identify them easily */
|
||||
protected $aCaseLogs;
|
||||
/** @var ActivityEntry[] $aEntries */
|
||||
@@ -94,8 +97,8 @@ class ActivityPanel extends UIBlock
|
||||
|
||||
$this->InitializeCaseLogTabs();
|
||||
$this->InitializeCaseLogTabsEntryForms();
|
||||
$this->SetObject($oObject);
|
||||
$this->SetObjectMode(cmdbAbstractObject::DEFAULT_OBJECT_MODE);
|
||||
$this->SetObject($oObject);
|
||||
$this->SetEntries($aEntries);
|
||||
$this->bAreEntriesSorted = false;
|
||||
$this->ComputedShowMultipleEntriesSubmitConfirmation();
|
||||
@@ -195,6 +198,24 @@ class ActivityPanel extends UIBlock
|
||||
return $this->sObjectMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @uses static::$sTransactionId
|
||||
*/
|
||||
public function HasTransactionId(): bool
|
||||
{
|
||||
return (null !== $this->sTransactionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
* @uses static::$sTransactionId
|
||||
*/
|
||||
public function GetTransactionId(): ?string
|
||||
{
|
||||
return $this->sTransactionId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set all entries at once.
|
||||
*
|
||||
@@ -440,6 +461,14 @@ class ActivityPanel extends UIBlock
|
||||
'authors' => [],
|
||||
'is_read_only' => $bIsReadOnly,
|
||||
];
|
||||
|
||||
// Transaction ID is generated only when:
|
||||
// - There is a least 1 *writable* case log
|
||||
// - And object is in view mode (in edit mode, it will be handled by the general form)
|
||||
// Otherwise we generate unnecessary transaction IDs that could saturate the system
|
||||
if ((false === $bIsReadOnly) && (false === $this->HasTransactionId()) && (cmdbAbstractObject::ENUM_OBJECT_MODE_VIEW === $this->sObjectMode)) {
|
||||
$this->sTransactionId = (cmdbAbstractObject::ENUM_OBJECT_MODE_VIEW === $this->sObjectMode) ? utils::GetNewTransactionId() : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,12 +62,11 @@ class ActivityPanelFactory
|
||||
$sObjClass = get_class($oObject);
|
||||
$iObjId = $oObject->GetKey();
|
||||
|
||||
if($sMode==cmdbAbstractObject::ENUM_OBJECT_MODE_PRINT){
|
||||
$oActivityPanel = new ActivityPanelPrint($oObject);
|
||||
$sMode= cmdbAbstractObject::ENUM_OBJECT_MODE_VIEW;
|
||||
}
|
||||
else{
|
||||
$oActivityPanel = new ActivityPanel($oObject);
|
||||
if ($sMode == cmdbAbstractObject::ENUM_OBJECT_MODE_PRINT) {
|
||||
$oActivityPanel = new ActivityPanelPrint($oObject, [], ActivityPanel::BLOCK_CODE);
|
||||
$sMode = cmdbAbstractObject::ENUM_OBJECT_MODE_VIEW;
|
||||
} else {
|
||||
$oActivityPanel = new ActivityPanel($oObject, [], ActivityPanel::BLOCK_CODE);
|
||||
}
|
||||
$oActivityPanel->SetObjectMode($sMode);
|
||||
|
||||
|
||||
@@ -586,6 +586,7 @@ JS
|
||||
foreach ($oPrevContentLayout->GetSubBlocks() as $oBlock){
|
||||
$this->AddUiBlock($oBlock);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -596,10 +597,11 @@ JS
|
||||
* @return \Combodo\iTop\Application\UI\Base\Layout\PageContent\PageContent
|
||||
* @since 3.0.0
|
||||
*/
|
||||
protected function GetContentLayout()
|
||||
public function GetContentLayout()
|
||||
{
|
||||
/** @var PageContent $oPageContent */
|
||||
$oPageContent = $this->oContentLayout;
|
||||
|
||||
return $oPageContent;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
$('#{{ oUIBlock.GetId() }}').activity_panel({
|
||||
datetime_format: {{ oUIBlock.GetDateTimeFormatForJSWidget()|json_encode|raw }},
|
||||
{% if oUIBlock.HasTransactionId() %}transaction_id: {{ oUIBlock.GetTransactionId()|var_export }},{% endif %}
|
||||
lock_watcher_period: {{ get_config_parameter('activity_panel.lock_watcher_period') }},
|
||||
show_multiple_entries_submit_confirmation: {{ oUIBlock.GetShowMultipleEntriesSubmitConfirmation()|var_export }}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user