mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 15:34:12 +01:00
* Rebase onto develop * Use exit condition instead of englobing condition * Add informative modals that can be called from modal toolbox * Refactor "apply_modify" and "apply_new" into own controller, handle ajax requests with a json response and handle these responses in linkset creation/edition * Fix merge issues * Remove inverted condition * Move linkset create button to a better place, still needs to fix duplicate "New" button caused by a refactor * Handle "Cancel" button in modals * Do not display relations when editing an object in a modal * More elegant way to add "New" button to relations lists * Factorize vertical highlights in alerts and modal in a single mixin * Replace button name with dict entry code * Change route name to snake case * More elegant way to add "Create in modal" button to relations lists * Replace triple if with in_array * Move listener to body * Rename variable to match boolean rules * Rename event * Rename extra param * Add phpdoc * Revert changes * Check indirect linkset rights before allowing creation in modal * Allow to modify linked object from 1-n relation in modal * Add "New" button to 1-n relations * Fix "new" button on 1-n * Add todo * Handle multiple classes choice * Rework multiple classes choice and only allow LinksetController to be called from an ajax context * PhpDoc * Update sources/Application/UI/Links/Direct/BlockDirectLinksViewTable.php Co-authored-by: Molkobain <lajarige.guillaume@free.fr>
119 lines
3.7 KiB
PHP
119 lines
3.7 KiB
PHP
<?php
|
|
/**
|
|
* @copyright Copyright (C) 2010-2022 Combodo SARL
|
|
* @license http://opensource.org/licenses/AGPL-3.0
|
|
*/
|
|
|
|
namespace Combodo\iTop\Application\UI\Links\Direct;
|
|
|
|
use Combodo\iTop\Application\UI\Links\AbstractBlockLinksViewTable;
|
|
use MetaModel;
|
|
|
|
/**
|
|
* Class BlockDirectLinksViewTable
|
|
*
|
|
* @internal
|
|
* @since 3.1.0
|
|
* @package Combodo\iTop\Application\UI\Links\Direct
|
|
*/
|
|
class BlockDirectLinksViewTable extends AbstractBlockLinksViewTable
|
|
{
|
|
public const BLOCK_CODE = 'ibo-block-direct-links-view-table';
|
|
public const REQUIRES_ANCESTORS_DEFAULT_JS_FILES = true;
|
|
|
|
/** @inheritdoc */
|
|
public function GetTargetClass(): string
|
|
{
|
|
return $this->oAttDef->GetLinkedClass();
|
|
}
|
|
|
|
/** @inheritdoc * */
|
|
public function GetExtraParam(): array
|
|
{
|
|
$aExtraParams = array(
|
|
'target_attr' => $this->oAttDef->GetExtKeyToMe(),
|
|
'object_id' => $this->oDbObject->GetKey(),
|
|
'menu' => MetaModel::GetConfig()->Get('allow_menu_on_linkset'),
|
|
'default' => $this->GetDefault(),
|
|
'table_id' => $this->GetTableId(),
|
|
'row_actions' => $this->GetRowActions(),
|
|
'currentId' => $this->GetTableId(),
|
|
);
|
|
|
|
// - Add creation in modal if the linkset is not readonly
|
|
if (!$this->oAttDef->GetReadOnly()) {
|
|
$aExtraParams['creation_in_modal_is_allowed'] = true;
|
|
$aExtraParams['creation_in_modal_js_handler'] = 'LinkSetWorker.CreateLinkedObject("'.$this->GetTableId().'");';
|
|
}
|
|
|
|
return $aExtraParams;
|
|
}
|
|
|
|
/** @inheritdoc * */
|
|
public function GetRowActions(): array
|
|
{
|
|
$aRowActions = array();
|
|
|
|
if (!$this->oAttDef->GetReadOnly()) {
|
|
|
|
switch ($this->oAttDef->GetRelationType()) {
|
|
|
|
case LINKSET_RELATIONTYPE_LINK:
|
|
$aRowActions[] = array(
|
|
'label' => 'UI:Links:ActionRow:Detach',
|
|
'tooltip' => 'UI:Links:ActionRow:Detach+',
|
|
'icon_classes' => 'fas fa-minus',
|
|
'js_row_action' => "LinkSetWorker.DetachLinkedObject('{$this->sTargetClass}', aRowData['{$this->sTargetClass}/_key_/raw'], '{$this->oAttDef->GetExtKeyToMe()}');",
|
|
'confirmation' => [
|
|
'message' => 'UI:Links:ActionRow:Detach:Confirmation',
|
|
'message_row_data' => "{$this->sTargetClass}/hyperlink",
|
|
'do_not_show_again_pref_key' => $this->GetDoNotShowAgainPreferenceKey(),
|
|
],
|
|
);
|
|
break;
|
|
|
|
case LINKSET_RELATIONTYPE_PROPERTY:
|
|
$aRowActions[] = array(
|
|
'label' => 'UI:Links:ActionRow:Delete',
|
|
'tooltip' => 'UI:Links:ActionRow:Delete+',
|
|
'icon_classes' => 'fas fa-trash',
|
|
'js_row_action' => "LinkSetWorker.DeleteLinkedObject('{$this->oAttDef->GetLinkedClass()}', aRowData['{$this->oAttDef->GetLinkedClass()}/_key_/raw']);",
|
|
'confirmation' => [
|
|
'message' => 'UI:Links:ActionRow:Delete:Confirmation',
|
|
'message_row_data' => "{$this->sTargetClass}/hyperlink",
|
|
'do_not_show_again_pref_key' => $this->GetDoNotShowAgainPreferenceKey(),
|
|
],
|
|
);
|
|
break;
|
|
}
|
|
$aRowActions[] = array(
|
|
'tooltip' => 'UI:Links:ActionRow:Modify',
|
|
'icon_classes' => 'fas fa-pen',
|
|
'js_row_action' => "LinkSetWorker.ModifyLinkedObject('{$this->sTargetClass}', aRowData['{$this->oAttDef->GetLinkedClass()}/_key_/raw'], '{$this->GetTableId()}');",
|
|
);
|
|
}
|
|
|
|
return $aRowActions;
|
|
}
|
|
|
|
/**
|
|
* GetDefault.
|
|
*
|
|
* @return array
|
|
* @throws \ArchivedObjectException
|
|
* @throws \CoreException
|
|
* @throws \Exception
|
|
*/
|
|
private function GetDefault(): array
|
|
{
|
|
$aDefaults = array($this->oAttDef->GetExtKeyToMe() => $this->oDbObject->GetKey());
|
|
$oAppContext = new \ApplicationContext();
|
|
foreach ($oAppContext->GetNames() as $sKey) {
|
|
if (MetaModel::IsValidAttCode($this->sObjectClass, $sKey)) {
|
|
$aDefaults[$sKey] = $this->oDbObject->Get($sKey);
|
|
}
|
|
}
|
|
|
|
return $aDefaults;
|
|
}
|
|
} |