mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 11:08:45 +02:00
N°2847 - ActivityPanel: Rework for new UX
- Add MetaModel::GetCaseLogs($sClass) function - Rename ActivityNewEntryForm to CaseLogEntryForm - Rework ActivityPanel and CaseLogEntryForm markup / CSS - Change for 1 CaseLogEntryForm per tab (caselogs and activity) with specific "Add entry..." choices
This commit is contained in:
@@ -1,154 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
namespace Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityNewEntryForm;
|
||||
use Combodo\iTop\Application\UI\Component\PopoverMenu\PopoverMenu;
|
||||
use Combodo\iTop\Application\UI\Layout\UIContentBlock;
|
||||
use Combodo\iTop\Application\UI\UIBlock;
|
||||
/**
|
||||
* Class ActivityNewEntryForm
|
||||
*
|
||||
* @package Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityNewEntryForm
|
||||
*/
|
||||
class ActivityNewEntryForm extends UIContentBlock
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-activitynewentryform';
|
||||
public const HTML_TEMPLATE_REL_PATH = 'layouts/activity-panel/activitynewentryform/layout';
|
||||
public const JS_TEMPLATE_REL_PATH = 'layouts/activity-panel/activitynewentryform/layout';
|
||||
public const JS_FILES_REL_PATH = [
|
||||
'js/layouts/activity-panel/activity-new-entry-form.js',
|
||||
];
|
||||
|
||||
/** @var \Combodo\iTop\Application\UI\Component\Input\RichText\RichText $oFormTextInput */
|
||||
protected $oFormTextInput;
|
||||
/** @var \Combodo\iTop\Application\UI\Component\PopoverMenu\PopoverMenu */
|
||||
protected $oCaseLogSelectionPopOverMenu;
|
||||
/** @var array $aTextInputActionButtons */
|
||||
protected $aTextInputActionButtons;
|
||||
/** @var array $aFormActionButtons */
|
||||
protected $aFormActionButtons;
|
||||
|
||||
/**
|
||||
* ActivityNewEntryForm constructor.
|
||||
*
|
||||
* @param null $sName
|
||||
*/
|
||||
public function __construct($sName = null)
|
||||
{
|
||||
parent::__construct($sName);
|
||||
$this->aFormActionButtons = [];
|
||||
$this->aTextInputActionButtons = [];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return \Combodo\iTop\Application\UI\Component\Input\RichText\RichText
|
||||
*/
|
||||
public function GetFormTextInput(): \Combodo\iTop\Application\UI\Component\Input\RichText\RichText
|
||||
{
|
||||
return $this->oFormTextInput;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Combodo\iTop\Application\UI\Component\Input\RichText\RichText $oFormTextInput
|
||||
* @return $this
|
||||
*/
|
||||
public function SetFormTextInput(\Combodo\iTop\Application\UI\Component\Input\RichText\RichText $oFormTextInput): ActivityNewEntryForm
|
||||
{
|
||||
$this->oFormTextInput = $oFormTextInput;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function GetTextInputActionButtons(): array
|
||||
{
|
||||
return $this->aTextInputActionButtons;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $aTextInputActionButtons
|
||||
* @return $this
|
||||
*/
|
||||
public function SetTextInputActionButtons(array $aTextInputActionButtons): ActivityNewEntryForm
|
||||
{
|
||||
$this->aTextInputActionButtons = $aTextInputActionButtons;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Combodo\iTop\Application\UI\UIBlock $oTextInputActionButtons
|
||||
*/
|
||||
public function AddTextInputActionButtons(UIBlock $oTextInputActionButtons): void
|
||||
{
|
||||
$this->aTextInputActionButtons[] = $oTextInputActionButtons;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function GetFormActionButtons()
|
||||
{
|
||||
return $this->aFormActionButtons;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $aFormActionButtons
|
||||
* @return $this
|
||||
*/
|
||||
public function SetFormActionButtons(array $aFormActionButtons): ActivityNewEntryForm
|
||||
{
|
||||
$this->aFormActionButtons = $aFormActionButtons;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UIBlock $oFormActionButtons
|
||||
*/
|
||||
public function AddFormActionButtons(UIBlock $oFormActionButtons): void
|
||||
{
|
||||
$this->aFormActionButtons[] = $oFormActionButtons;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PopoverMenu
|
||||
*/
|
||||
public function GetCaseLogSelectionPopOverMenu(): PopoverMenu
|
||||
{
|
||||
return $this->oCaseLogSelectionPopOverMenu;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PopoverMenu $oCaseLogSelectionPopOverMenu
|
||||
* @return $this
|
||||
*/
|
||||
public function SetCaseLogSelectionPopOverMenu(PopoverMenu $oCaseLogSelectionPopOverMenu): ActivityNewEntryForm
|
||||
{
|
||||
$this->oCaseLogSelectionPopOverMenu = $oCaseLogSelectionPopOverMenu;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function GetSubBlocks() : array
|
||||
{
|
||||
$aSubBlocks = [];
|
||||
$aSubBlocks[$this->GetFormTextInput()->GetId()] = $this->GetFormTextInput();
|
||||
foreach ($this->GetTextInputActionButtons() as $oTextInputActionButton)
|
||||
{
|
||||
$aSubBlocks[$oTextInputActionButton->GetId()] = $oTextInputActionButton;
|
||||
}
|
||||
foreach ($this->GetFormActionButtons() as $oFormActionButton)
|
||||
{
|
||||
$aSubBlocks[$oFormActionButton->GetId()] = $oFormActionButton;
|
||||
}
|
||||
$oCaseLogSelectionPopOverMenu = $this->GetCaseLogSelectionPopOverMenu();
|
||||
$aSubBlocks[$oCaseLogSelectionPopOverMenu->GetId()] = $oCaseLogSelectionPopOverMenu;
|
||||
|
||||
return $aSubBlocks;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityNewEntryFormFactory;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Component\Button\ButtonFactory;
|
||||
use Combodo\iTop\Application\UI\Component\Input\RichText\RichText;
|
||||
use Combodo\iTop\Application\UI\Component\PopoverMenu\PopoverMenuFactory;
|
||||
use Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityNewEntryForm\ActivityNewEntryForm;
|
||||
|
||||
/**
|
||||
* Class ActivityNewEntryFormFactory
|
||||
*
|
||||
* @internal
|
||||
* @author Stephen Abello <stephen.abello@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityNewEntryFormFactory
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class ActivityNewEntryFormFactory
|
||||
{
|
||||
public static function MakeForObjectDetailsActivityPanel($aCaseLogs): ActivityNewEntryForm
|
||||
{
|
||||
$oActivityNewEntryForm = new ActivityNewEntryForm();
|
||||
$oActivityNewEntryForm->SetFormTextInput(new RichText());
|
||||
$oActivityNewEntryForm->AddFormActionButtons(ButtonFactory::MakeForSecondaryAction('Cancel')
|
||||
->SetOnClickJsCode("$(this).parents('[data-role=\"ibo-activity-new-entry-form--action-buttons--right-actions\"]').trigger('cancel');"));
|
||||
$oActivityNewEntryForm->AddFormActionButtons(ButtonFactory::MakeForPrimaryAction('Send')
|
||||
->SetColor('cyan')
|
||||
->SetIconClass('fas fa-paper-plane')
|
||||
->SetOnClickJsCode("$(this).parents('[data-role=\"ibo-activity-new-entry-form--action-buttons--right-actions\"]').trigger('submit');"));
|
||||
//$oActivityNewEntryForm->AddTextInputActionButtons(ButtonFactory::MakeForSecondaryAction('Templates')->SetColor('blue'));
|
||||
|
||||
$oActivityNewEntryForm->SetCaseLogSelectionPopOverMenu(PopoverMenuFactory::MakeMenuForActivityNewEntryFormSubmit($aCaseLogs));
|
||||
|
||||
return $oActivityNewEntryForm;
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ use Combodo\iTop\Application\UI\Component\Button\ButtonFactory;
|
||||
use Combodo\iTop\Application\UI\Component\Input\RichText\RichText;
|
||||
use Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\ActivityEntry;
|
||||
use Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\CaseLogEntry;
|
||||
use Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityNewEntryForm\ActivityNewEntryForm;
|
||||
use Combodo\iTop\Application\UI\Layout\ActivityPanel\CaseLogEntryForm\CaseLogEntryForm;
|
||||
use Combodo\iTop\Application\UI\UIBlock;
|
||||
use DBObject;
|
||||
use Exception;
|
||||
@@ -65,8 +65,10 @@ class ActivityPanel extends UIBlock
|
||||
protected $bAreEntriesSorted;
|
||||
/** @var bool $bHasLifecycle True if the host object has a lifecycle */
|
||||
protected $bHasLifecycle;
|
||||
/** @var \Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityNewEntryForm\ActivityNewEntryForm $NewEntryForm */
|
||||
protected $oNewEntryForm;
|
||||
/** @var \Combodo\iTop\Application\UI\Layout\ActivityPanel\CaseLogEntryForm\CaseLogEntryForm $oActivityTabEntryForm New entry form for the activity tab which is different from the case log tabs */
|
||||
protected $oActivityTabEntryForm;
|
||||
/** @var \Combodo\iTop\Application\UI\Layout\ActivityPanel\CaseLogEntryForm\CaseLogEntryForm[] $aCaseLogTabsEntryForms */
|
||||
protected $aCaseLogTabsEntryForms;
|
||||
|
||||
/**
|
||||
* ActivityPanel constructor.
|
||||
@@ -83,6 +85,7 @@ class ActivityPanel extends UIBlock
|
||||
parent::__construct($sId);
|
||||
|
||||
$this->InitializeCaseLogTabs();
|
||||
$this->InitializeCaseLogTabsEntryForms();
|
||||
$this->SetObject($oObject);
|
||||
$this->SetObjectMode(cmdbAbstractObject::DEFAULT_OBJECT_MODE);
|
||||
$this->SetEntries($aEntries);
|
||||
@@ -105,7 +108,9 @@ class ActivityPanel extends UIBlock
|
||||
|
||||
// Initialize the case log tabs
|
||||
$this->InitializeCaseLogTabs();
|
||||
$aCaseLogAttCodes = MetaModel::GetAttributesList($sObjectClass, ['AttributeCaseLog']);
|
||||
$this->InitializeCaseLogTabsEntryForms();
|
||||
|
||||
$aCaseLogAttCodes = MetaModel::GetCaseLogs($sObjectClass);
|
||||
foreach($aCaseLogAttCodes as $sCaseLogAttCode)
|
||||
{
|
||||
$this->AddCaseLogTab($sCaseLogAttCode);
|
||||
@@ -459,6 +464,67 @@ class ActivityPanel extends UIBlock
|
||||
return !empty($this->aCaseLogs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty the caselogs entry forms
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function InitializeCaseLogTabsEntryForms()
|
||||
{
|
||||
$this->aCaseLogTabsEntryForms = [];
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all entry forms for all case log tabs
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Layout\ActivityPanel\CaseLogEntryForm\CaseLogEntryForm[]
|
||||
*/
|
||||
public function GetCaseLogTabsEntryForms(): array
|
||||
{
|
||||
return $this->aCaseLogTabsEntryForms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the $oCaseLogEntryForm for the $sCaseLogId tab.
|
||||
* Note: If there is no caselog for that ID, it will proceed silently.
|
||||
*
|
||||
* @param string $sCaseLogId
|
||||
* @param \Combodo\iTop\Application\UI\Layout\ActivityPanel\CaseLogEntryForm\CaseLogEntryForm $oCaseLogEntryForm
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetCaseLogTabEntryForm(string $sCaseLogId, CaseLogEntryForm $oCaseLogEntryForm)
|
||||
{
|
||||
if ($this->HasCaseLogTab($sCaseLogId)){
|
||||
$this->aCaseLogTabsEntryForms[$sCaseLogId] = $oCaseLogEntryForm;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the caselog entry form for the $sCaseLogId tab
|
||||
*
|
||||
* @param string $sCaseLogId
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Layout\ActivityPanel\CaseLogEntryForm\CaseLogEntryForm
|
||||
*/
|
||||
public function GetCaseLogTabEntryForm(string $sCaseLogId)
|
||||
{
|
||||
return $this->aCaseLogTabsEntryForms[$sCaseLogId];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sCaseLogId
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function HasCaseLogTabEntryForm(string $sCaseLogId): bool
|
||||
{
|
||||
return !empty($this->aCaseLogTabsEntryForms[$sCaseLogId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the host object has a lifecycle
|
||||
*
|
||||
@@ -480,31 +546,59 @@ class ActivityPanel extends UIBlock
|
||||
$oDateTimeFormat = AttributeDateTime::GetFormat();
|
||||
return $oDateTimeFormat->ToMomentJS();
|
||||
}
|
||||
|
||||
public function GetNewEntryForm()
|
||||
|
||||
/**
|
||||
* Return the entry form for the activity tab
|
||||
*
|
||||
* @see $oActivityTabEntryForm
|
||||
* @return \Combodo\iTop\Application\UI\Layout\ActivityPanel\CaseLogEntryForm\CaseLogEntryForm
|
||||
*/
|
||||
public function GetActivityTabEntryForm(): CaseLogEntryForm
|
||||
{
|
||||
return $this->oNewEntryForm;
|
||||
}
|
||||
|
||||
public function SetNewEntryForm($oNewEntryForm)
|
||||
{
|
||||
$this->oNewEntryForm = $oNewEntryForm;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function HasNewEntryForm()
|
||||
{
|
||||
return $this->oNewEntryForm !== null;
|
||||
return $this->oActivityTabEntryForm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the entry form for the activity tab
|
||||
*
|
||||
* @param \Combodo\iTop\Application\UI\Layout\ActivityPanel\CaseLogEntryForm\CaseLogEntryForm $oCaseLogEntryForm
|
||||
* @see $oActivityTabEntryForm
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
*/
|
||||
public function SetActivityTabEntryForm(CaseLogEntryForm $oCaseLogEntryForm)
|
||||
{
|
||||
$this->oActivityTabEntryForm = $oCaseLogEntryForm;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true is there is an entry form for the activity tab
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function HasActivityTabEntryForm()
|
||||
{
|
||||
return $this->oActivityTabEntryForm !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function GetSubBlocks()
|
||||
{
|
||||
$aSubBlocks = array();
|
||||
if ($this->HasNewEntryForm())
|
||||
{
|
||||
$oNewEntryForm = $this->GetNewEntryForm();
|
||||
|
||||
foreach($this->GetCaseLogTabsEntryForms() as $sCaseLogId => $oCaseLogEntryForm) {
|
||||
$aSubBlocks[$oCaseLogEntryForm->GetId()] = $oCaseLogEntryForm;
|
||||
}
|
||||
|
||||
if ($this->HasActivityTabEntryForm()) {
|
||||
$oNewEntryForm = $this->GetActivityTabEntryForm();
|
||||
$aSubBlocks[$oNewEntryForm->GetId()] = $oNewEntryForm;
|
||||
}
|
||||
|
||||
return $aSubBlocks;
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ use cmdbAbstractObject;
|
||||
use CMDBChangeOpSetAttributeCaseLog;
|
||||
use Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\ActivityEntryFactory;
|
||||
use Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\EditsEntry;
|
||||
use Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityNewEntryFormFactory\ActivityNewEntryFormFactory;
|
||||
use Combodo\iTop\Application\UI\Layout\ActivityPanel\CaseLogEntryFormFactory\CaseLogEntryFormFactory;
|
||||
use DBObject;
|
||||
use DBObjectSearch;
|
||||
use DBObjectSet;
|
||||
@@ -65,10 +65,14 @@ class ActivityPanelFactory
|
||||
$oActivityPanel = new ActivityPanel($oObject);
|
||||
$oActivityPanel->SetObjectMode($sMode);
|
||||
|
||||
// Retrieve case logs entries
|
||||
// Prepare caselogs
|
||||
$aCaseLogAttCodes = array_keys($oActivityPanel->GetCaseLogTabs());
|
||||
foreach($aCaseLogAttCodes as $sCaseLogAttCode)
|
||||
{
|
||||
// Add new entry block
|
||||
$oActivityPanel->SetCaseLogTabEntryForm($sCaseLogAttCode, CaseLogEntryFormFactory::MakeForCaselogTab($oObject, $sCaseLogAttCode, $sMode));
|
||||
|
||||
// Retrieve case logs entries
|
||||
/** @var \ormCaseLog $oCaseLog */
|
||||
$oCaseLog = $oObject->Get($sCaseLogAttCode);
|
||||
foreach($oCaseLog->GetAsArray() as $aOrmEntry)
|
||||
@@ -78,16 +82,13 @@ class ActivityPanelFactory
|
||||
}
|
||||
}
|
||||
|
||||
if($oActivityPanel->HasCaseLogTabs())
|
||||
{
|
||||
//TODO 3.0.0 check write rights
|
||||
$aCaseLogsForNewEntryForm = [];
|
||||
foreach ($aCaseLogAttCodes as $sCaseLogAttCode){
|
||||
$aCaseLogsForNewEntryForm[$sCaseLogAttCode] = MetaModel::GetLabel($sObjClass, $sCaseLogAttCode);
|
||||
}
|
||||
|
||||
$oActivityPanel->SetNewEntryForm(ActivityNewEntryFormFactory::MakeForObjectDetailsActivityPanel($aCaseLogsForNewEntryForm));
|
||||
//TODO 3.0.0: Check write rights
|
||||
if($oActivityPanel->HasCaseLogTabs()) {
|
||||
|
||||
|
||||
}
|
||||
$oActivityPanel->SetActivityTabEntryForm(CaseLogEntryFormFactory::MakeForActivityTab($oObject, $sMode));
|
||||
|
||||
// Retrieve history changes (including case logs entries)
|
||||
// - Prepare query to retrieve changes
|
||||
$oChangesSearch = DBObjectSearch::FromOQL('SELECT CMDBChangeOp WHERE objclass = :obj_class AND objkey = :obj_key');
|
||||
|
||||
@@ -0,0 +1,297 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2020 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
namespace Combodo\iTop\Application\UI\Layout\ActivityPanel\CaseLogEntryForm;
|
||||
|
||||
use cmdbAbstractObject;
|
||||
use Combodo\iTop\Application\UI\Component\Input\RichText\RichText;
|
||||
use Combodo\iTop\Application\UI\Component\PopoverMenu\PopoverMenu;
|
||||
use Combodo\iTop\Application\UI\Layout\UIContentBlock;
|
||||
use Combodo\iTop\Application\UI\UIBlock;
|
||||
|
||||
/**
|
||||
* Class CaseLogEntryForm
|
||||
*
|
||||
* @package Combodo\iTop\Application\UI\Layout\ActivityPanel\CaseLogEntryForm
|
||||
*/
|
||||
class CaseLogEntryForm extends UIContentBlock
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-caselog-entry-form';
|
||||
public const HTML_TEMPLATE_REL_PATH = 'layouts/activity-panel/caselog-entry-form/layout';
|
||||
public const JS_TEMPLATE_REL_PATH = 'layouts/activity-panel/caselog-entry-form/layout';
|
||||
public const JS_FILES_REL_PATH = [
|
||||
'js/layouts/activity-panel/caselog-entry-form.js',
|
||||
];
|
||||
|
||||
/** @var string Form is autonomous and can send data on its own */
|
||||
public const ENUM_SUBMIT_MODE_AUTONOMOUS = 'autonomous';
|
||||
/** @var string Form is bridged to its host object form */
|
||||
public const ENUM_SUBMIT_MODE_BRIDGED = 'bridged';
|
||||
/** @var string Container of the form is a specific caselog tab */
|
||||
public const ENUM_CONTAINER_TAB_TYPE_CASELOG = 'caselog';
|
||||
/** @var string Container of the form is the activity tab */
|
||||
public const ENUM_CONTAINER_TAB_TYPE_ACTIVITY = 'activity';
|
||||
|
||||
/** @var string */
|
||||
public const DEFAULT_SUBMIT_MODE = self::ENUM_SUBMIT_MODE_AUTONOMOUS;
|
||||
/** @var string */
|
||||
public const DEFAULT_CONTAINER_TAB_TYPE = self::ENUM_CONTAINER_TAB_TYPE_ACTIVITY;
|
||||
|
||||
/**
|
||||
* @var string Whether the form can send data on its own or if it's bridged with its host object form
|
||||
* @see static::ENUM_SUBMIT_MODE_XXX
|
||||
*/
|
||||
protected $sSubmitMode;
|
||||
/**
|
||||
* @var string Whether the form container is a caselog tab or an activity tab
|
||||
* @see static::ENUM_CONTAINER_TAB_TYPE_XXX
|
||||
*/
|
||||
protected $sContainerTabType;
|
||||
/** @var \Combodo\iTop\Application\UI\Component\Input\RichText\RichText $oTextInput The main input to write a case log entry */
|
||||
protected $oTextInput;
|
||||
/** @var \Combodo\iTop\Application\UI\Component\PopoverMenu\PopoverMenu Menu for possible options on the send button */
|
||||
protected $oSendButtonPopoverMenu;
|
||||
/** @var array $aMainActionButtons The form main actions (send, cancel, ...) */
|
||||
protected $aMainActionButtons;
|
||||
/** @var array $aExtraActionButtons The form extra actions, can be populated through a public API */
|
||||
protected $aExtraActionButtons;
|
||||
|
||||
/**
|
||||
* CaseLogEntryForm constructor.
|
||||
*
|
||||
* @param null $sName
|
||||
*/
|
||||
public function __construct($sName = null)
|
||||
{
|
||||
parent::__construct($sName);
|
||||
$this->sSubmitMode = static::DEFAULT_SUBMIT_MODE;
|
||||
$this->sContainerTabType = static::DEFAULT_CONTAINER_TAB_TYPE;
|
||||
$this->SetTextInput(new RichText());
|
||||
$this->aMainActionButtons = [];
|
||||
$this->aExtraActionButtons = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @see $sSubmitMode
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetSubmitMode(): string
|
||||
{
|
||||
return $this->sSubmitMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sSubmitMode
|
||||
* @see $sSubmitMode
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetSubmitMode(string $sSubmitMode)
|
||||
{
|
||||
$this->sSubmitMode = $sSubmitMode;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the submit mode (autonomous, bridged) from the host object mode (create, edit, view, ...)
|
||||
* eg. create => bridged, view => autonomous.
|
||||
*
|
||||
* @param string $sObjectMode
|
||||
* @see $sSubmitMode
|
||||
* @see cmdbAbstractObject::ENUM_OBJECT_MODE_XXX
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetSubmitModeFromHostObjectMode($sObjectMode)
|
||||
{
|
||||
switch ($sObjectMode){
|
||||
case cmdbAbstractObject::ENUM_OBJECT_MODE_CREATE:
|
||||
case cmdbAbstractObject::ENUM_OBJECT_MODE_EDIT:
|
||||
$sSubmitMode = static::ENUM_SUBMIT_MODE_BRIDGED;
|
||||
break;
|
||||
|
||||
case cmdbAbstractObject::ENUM_OBJECT_MODE_VIEW:
|
||||
case cmdbAbstractObject::ENUM_OBJECT_MODE_STIMULUS:
|
||||
default:
|
||||
$sSubmitMode = static::ENUM_SUBMIT_MODE_AUTONOMOUS;
|
||||
break;
|
||||
}
|
||||
|
||||
$this->SetSubmitMode($sSubmitMode);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the submit mode is autonomous
|
||||
*
|
||||
* @see $sSubmitMode
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function IsSubmitAutonomous(): bool
|
||||
{
|
||||
return $this->GetSubmitMode() === static::ENUM_SUBMIT_MODE_AUTONOMOUS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see $sContainerTabType
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetContainerTabType(): string
|
||||
{
|
||||
return $this->sContainerTabType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sContainerTabType
|
||||
* @see $sContainerTabType
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetContainerTabType(string $sContainerTabType)
|
||||
{
|
||||
$this->sContainerTabType = $sContainerTabType;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Combodo\iTop\Application\UI\Component\Input\RichText\RichText
|
||||
*/
|
||||
public function GetTextInput(): RichText
|
||||
{
|
||||
return $this->oTextInput;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Combodo\iTop\Application\UI\Component\Input\RichText\RichText $oTextInput
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetTextInput(RichText $oTextInput)
|
||||
{
|
||||
$this->oTextInput = $oTextInput;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Combodo\iTop\Application\UI\UIBlock[]
|
||||
*/
|
||||
public function GetMainActionButtons()
|
||||
{
|
||||
return $this->aMainActionButtons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set all main action buttons at once, replacing all existing ones
|
||||
*
|
||||
* @param array $aFormActionButtons
|
||||
* @return $this
|
||||
*/
|
||||
public function SetMainActionButtons(array $aFormActionButtons)
|
||||
{
|
||||
$this->aMainActionButtons = $aFormActionButtons;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Combodo\iTop\Application\UI\UIBlock $oMainActionButton
|
||||
* @return $this;
|
||||
*/
|
||||
public function AddMainActionButtons(UIBlock $oMainActionButton)
|
||||
{
|
||||
$this->aMainActionButtons[] = $oMainActionButton;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Combodo\iTop\Application\UI\UIBlock[]
|
||||
*/
|
||||
public function GetExtraActionButtons()
|
||||
{
|
||||
return $this->aExtraActionButtons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set all extra action buttons at once, replacing all existing ones
|
||||
*
|
||||
* @param array $aExtraActionButtons
|
||||
* @see $aExtraActionButtons
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetExtraActionButtons(array $aExtraActionButtons)
|
||||
{
|
||||
$this->aExtraActionButtons = $aExtraActionButtons;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Combodo\iTop\Application\UI\UIBlock $oExtraActionButton
|
||||
*
|
||||
* @return $this;
|
||||
* @see $aExtraActionButtons
|
||||
*
|
||||
*/
|
||||
public function AddExtraActionButtons(UIBlock $oExtraActionButton)
|
||||
{
|
||||
$this->aExtraActionButtons[] = $oExtraActionButton;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Combodo\iTop\Application\UI\Component\PopoverMenu\PopoverMenu
|
||||
*/
|
||||
public function GetSendButtonPopoverMenu(): PopoverMenu
|
||||
{
|
||||
return $this->oSendButtonPopoverMenu;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Combodo\iTop\Application\UI\Component\PopoverMenu\PopoverMenu $oCaseLogSelectionPopOverMenu
|
||||
* @return $this
|
||||
*/
|
||||
public function SetSendButtonPopoverMenu(PopoverMenu $oCaseLogSelectionPopOverMenu)
|
||||
{
|
||||
$this->oSendButtonPopoverMenu = $oCaseLogSelectionPopOverMenu;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true is there is a PopoverMenu for the send button
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function HasSendButtonPopoverMenu(): bool
|
||||
{
|
||||
return $this->oSendButtonPopoverMenu !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function GetSubBlocks(): array
|
||||
{
|
||||
$aSubBlocks = [];
|
||||
$aSubBlocks[$this->GetTextInput()->GetId()] = $this->GetTextInput();
|
||||
|
||||
foreach ($this->GetExtraActionButtons() as $oExtraActionButton)
|
||||
{
|
||||
$aSubBlocks[$oExtraActionButton->GetId()] = $oExtraActionButton;
|
||||
}
|
||||
|
||||
foreach ($this->GetMainActionButtons() as $oMainActionButton)
|
||||
{
|
||||
$aSubBlocks[$oMainActionButton->GetId()] = $oMainActionButton;
|
||||
}
|
||||
|
||||
$aSubBlocks[$this->GetSendButtonPopoverMenu()->GetId()] = $this->GetSendButtonPopoverMenu();
|
||||
|
||||
return $aSubBlocks;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2020 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Layout\ActivityPanel\CaseLogEntryFormFactory;
|
||||
|
||||
|
||||
use cmdbAbstractObject;
|
||||
use Combodo\iTop\Application\UI\Component\Button\Button;
|
||||
use Combodo\iTop\Application\UI\Component\Button\ButtonFactory;
|
||||
use Combodo\iTop\Application\UI\Component\PopoverMenu\PopoverMenu;
|
||||
use Combodo\iTop\Application\UI\Component\PopoverMenu\PopoverMenuItem\PopoverMenuItemFactory;
|
||||
use Combodo\iTop\Application\UI\Layout\ActivityPanel\CaseLogEntryForm\CaseLogEntryForm;
|
||||
use DBObject;
|
||||
use DBObjectSet;
|
||||
use Dict;
|
||||
use MetaModel;
|
||||
use JSPopupMenuItem;
|
||||
use UserRights;
|
||||
|
||||
/**
|
||||
* Class CaseLogEntryFormFactory
|
||||
*
|
||||
* @internal
|
||||
* @author Stephen Abello <stephen.abello@combodo.com>
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Layout\ActivityPanel\CaseLogEntryFormFactory
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class CaseLogEntryFormFactory
|
||||
{
|
||||
public static function MakeForCaselogTab(DBObject $oObject, string $sCaseLogAttCode, string $sObjectMode = cmdbAbstractObject::DEFAULT_OBJECT_MODE)
|
||||
{
|
||||
$oCaseLogEntryForm = new CaseLogEntryForm();
|
||||
$oCaseLogEntryForm->SetSubmitModeFromHostObjectMode($sObjectMode)
|
||||
->AddMainActionButtons(static::PrepareCancelButton())
|
||||
->AddMainActionButtons(static::PrepareSendButton()->SetLabel(Dict::S('UI:Button:AddEntryAndWithChoice')))
|
||||
->SetSendButtonPopoverMenu(static::PrepareSendActionSelectionPopoverMenu($oObject, $sCaseLogAttCode));
|
||||
|
||||
return $oCaseLogEntryForm;
|
||||
}
|
||||
|
||||
public static function MakeForActivityTab(DBObject $oObject, string $sObjectMode = cmdbAbstractObject::DEFAULT_OBJECT_MODE)
|
||||
{
|
||||
$oCaseLogEntryForm = new CaseLogEntryForm();
|
||||
$oCaseLogEntryForm->SetSubmitModeFromHostObjectMode($sObjectMode)
|
||||
->AddMainActionButtons(static::PrepareCancelButton())
|
||||
->AddMainActionButtons(static::PrepareSendButton()->SetLabel(Dict::S('UI:Button:AddEntryToWithChoice')));
|
||||
|
||||
$oCaseLogEntryForm->SetSendButtonPopoverMenu(static::PrepareTargetCaseLogSelectionPopoverMenu($oObject));
|
||||
|
||||
return $oCaseLogEntryForm;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Combodo\iTop\Application\UI\Component\Button\Button
|
||||
*/
|
||||
protected static function PrepareCancelButton(): Button
|
||||
{
|
||||
return ButtonFactory::MakeForSecondaryAction(Dict::S('UI:Button:Cancel'), 'cancel', 'cancel');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Combodo\iTop\Application\UI\Component\Button\Button
|
||||
*/
|
||||
protected static function PrepareSendButton(): Button
|
||||
{
|
||||
$oButton = ButtonFactory::MakeForPrimaryAction(Dict::S('UI:Button:Send'), 'send', 'send');
|
||||
$oButton->SetIconClass('fas fa-paper-plane');
|
||||
|
||||
return $oButton;
|
||||
}
|
||||
|
||||
protected static function PrepareSendActionSelectionPopoverMenu(DBObject $oObject, string $sCaseLogAttCode): PopoverMenu
|
||||
{
|
||||
$sObjClass = get_class($oObject);
|
||||
|
||||
$oMenu = new PopoverMenu();
|
||||
$sSectionId = 'send-actions';
|
||||
$oMenu->AddSection($sSectionId);
|
||||
|
||||
$sCaseLogEntryFormDataRole = CaseLogEntryForm::BLOCK_CODE;
|
||||
|
||||
// Standard, just save
|
||||
$oMenuItem = PopoverMenuItemFactory::MakeFromApplicationPopupMenuItem(
|
||||
new JSPopupMenuItem(
|
||||
CaseLogEntryForm::BLOCK_CODE.'--add-action--'.$sCaseLogAttCode.'--save',
|
||||
Dict::S('UI:Button:Save'),
|
||||
<<<JS
|
||||
$(this).closest('[data-role="{$sCaseLogEntryFormDataRole}"]').trigger('add_to_caselog.caselog_entry_form.itop', {caselog_att_code: '{$sCaseLogAttCode}'});
|
||||
JS
|
||||
)
|
||||
);
|
||||
$oMenu->AddItem($sSectionId, $oMenuItem);
|
||||
|
||||
// Transitions
|
||||
// Note: This code is inspired from cmdbAbstract::DisplayModifyForm(), it might be better to factorize it
|
||||
$aTransitions = $oObject->EnumTransitions();
|
||||
if (!isset($aExtraParams['custom_operation']) && count($aTransitions)) {
|
||||
$oSetToCheckRights = DBObjectSet::FromObject($oObject);
|
||||
$aStimuli = Metamodel::EnumStimuli($sObjClass);
|
||||
foreach ($aTransitions as $sStimulusCode => $aTransitionDef) {
|
||||
$iActionAllowed = (get_class($aStimuli[$sStimulusCode]) == 'StimulusUserAction') ? UserRights::IsStimulusAllowed($sObjClass,
|
||||
$sStimulusCode, $oSetToCheckRights) : UR_ALLOWED_NO;
|
||||
switch ($iActionAllowed) {
|
||||
case UR_ALLOWED_YES:
|
||||
$oMenuItem = PopoverMenuItemFactory::MakeFromApplicationPopupMenuItem(
|
||||
new JSPopupMenuItem(
|
||||
CaseLogEntryForm::BLOCK_CODE.'--add-action--'.$sCaseLogAttCode.'--stimulus--'.$sStimulusCode,
|
||||
$aStimuli[$sStimulusCode]->GetLabel(),
|
||||
<<<JS
|
||||
$(this).closest('[data-role="{$sCaseLogEntryFormDataRole}"]').trigger('add_to_caselog.caselog_entry_form.itop', {caselog_att_code: '{$sCaseLogAttCode}', stimulus_code: '{$sStimulusCode}'});
|
||||
JS
|
||||
)
|
||||
);
|
||||
$oMenu->AddItem($sSectionId, $oMenuItem);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $oMenu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a PopoverMenu with the list of the caselog attributes of $oObject
|
||||
*
|
||||
* @param \DBObject $oObject
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Component\PopoverMenu\PopoverMenu
|
||||
* @throws \CoreException
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected static function PrepareTargetCaseLogSelectionPopoverMenu(DBObject $oObject): PopoverMenu
|
||||
{
|
||||
$sObjClass = get_class($oObject);
|
||||
|
||||
$oMenu = new PopoverMenu();
|
||||
$sSectionId = 'target-caselogs';
|
||||
$oMenu->AddSection($sSectionId);
|
||||
|
||||
$sCaseLogEntryFormDataRole = CaseLogEntryForm::BLOCK_CODE;
|
||||
|
||||
foreach(MetaModel::GetCaseLogs($sObjClass) as $sCaseLogAttCode) {
|
||||
$oMenuItem = PopoverMenuItemFactory::MakeFromApplicationPopupMenuItem(
|
||||
new JSPopupMenuItem(
|
||||
CaseLogEntryForm::BLOCK_CODE.'--target-caselog--'.$sCaseLogAttCode,
|
||||
MetaModel::GetLabel($sObjClass, $sCaseLogAttCode),
|
||||
<<<JS
|
||||
$(this).closest('[data-role="{$sCaseLogEntryFormDataRole}"]').trigger('add_to_caselog.caselog_entry_form.itop', {caselog_att_code: '{$sCaseLogAttCode}'});
|
||||
JS
|
||||
)
|
||||
);
|
||||
|
||||
$oMenu->AddItem($sSectionId, $oMenuItem);
|
||||
}
|
||||
|
||||
return $oMenu;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user