Issue/5074 - Routage, Block UI relations, Links row actions (#369)

* datatable row actions

Below is a sample of extra param to enable feature:

		$aExtraParams['row_actions'] = [
			[
				'tooltip'        => 'remove an element',
				'icon_css_class' => 'fa-minus',
				'js_row_action'   => 'console.log("You clicked the remove button");',
				'confirmation'  => [
					'message'                  => 'UI:ConfirmationMessage',
					'message_row_data'         => "name",
					'remember_choice_pref_key' => 'remove_do_not_show_again',
				],
			],
			[
				'tooltip'        => 'open in new tab',
				'icon_css_class' => 'fa-external-link-square-alt',
				'on_action_js'   => 'window.open("http://localhost/itop-branchs/dev/pages/UI.php?operation=details&class=UserRequest&id=" + aData.id + "&c[menu]=UserRequest%3AOpenRequests");',
			],
			[
				'tooltip'        => 'other actions',
				'icon_css_class' => 'fa-ellipsis-v',
				'on_action_js'   => 'console.log(event);',
			],
		];

* Contrôleur pour la suppression et le détachement de liens
* Block UI pour l'édition des relations
* Block UI pour la visualisation des relations
* Boutons d'actions pour la suppression et le détachement de liens
* Gestion dialogue de confirmation pour les row actions
This commit is contained in:
bdalsass
2022-11-23 16:10:34 +01:00
committed by GitHub
parent a0a5037554
commit bdb29fd99a
42 changed files with 2040 additions and 818 deletions

View File

@@ -40,6 +40,7 @@ class DataTable extends UIContentBlock
'js/dataTables.main.js',
'js/dataTables.settings.js',
'js/dataTables.pipeline.js',
'js/dataTables.row-actions.js',
];
protected $aOptions;//list of specific options for display datatable
@@ -52,6 +53,8 @@ class DataTable extends UIContentBlock
*/
protected $aInitDisplayData;
public const DEFAULT_ACTION_ROW_CONFIRMATION = true;
/**
* Panel constructor.

View File

@@ -211,7 +211,7 @@ class DataTableUIBlockFactory extends AbstractUIBlockFactory
foreach ($oTable->GetRowActions() as $iKey => $aAction) {
$oButton = ButtonUIBlockFactory::MakeIconAction(
array_key_exists('icon_classes', $aAction) ? $aAction['icon_classes'] : 'fas fa-question',
array_key_exists('tooltip', $aAction) ? $aAction['tooltip'] : '',
array_key_exists('tooltip', $aAction) ? Dict::S($aAction['tooltip']) : '',
array_key_exists('name', $aAction) ? $aAction['name'] : 'undefined'
);
$oButton->SetDataAttributes(['action-id' => $iKey]);
@@ -522,7 +522,6 @@ class DataTableUIBlockFactory extends AbstractUIBlockFactory
$oDataTable->SetRowActions($aExtraParams['row_actions']);
}
return $oDataTable;
}

View File

@@ -36,6 +36,7 @@ class StaticTable extends UIContentBlock
'js/dataTables.main.js',
'js/dataTables.settings.js',
'js/dataTables.pipeline.js',
'js/dataTables.row-actions.js',
];
/**

View File

@@ -6,6 +6,10 @@
namespace Combodo\iTop\Application\UI\Base\Component\DataTable;
use Combodo\iTop\Application\UI\Base\Component\Dialog\DialogUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Component\Input\InputUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlockUIBlockFactory;
/**
* Trait tTableRowActions
*
@@ -17,12 +21,20 @@ namespace Combodo\iTop\Application\UI\Base\Component\DataTable;
*/
trait tTableRowActions
{
/** @var bool static dialog initialized flag to avoid multiple html markups */
static public bool $bDialogInitialized = false;
/**
* @var $aRowActions array array of row actions
* action => {
* tooltip: string,
* icon_classes: string,
* js_row_action: string
* js_row_action: string,
* confirmation => {
* message: string,
* message_row_data: string,
* remember_choice_pref_key: string
* }
* }
*/
protected $aRowActions;
@@ -70,4 +82,31 @@ trait tTableRowActions
{
return DataTableUIBlockFactory::MakeActionRowToolbarTemplate($this);
}
/**
* GetRowActionsConfirmDialog.
*
* @return \Combodo\iTop\Application\UI\Base\Component\Html\Html
*/
public function GetRowActionsConfirmDialog()
{
static::$bDialogInitialized = true;
$oDialog = DialogUIBlockFactory::MakeNeutral('', '<div class="ibo-row-action--confirmation--explanation"></div>', 'table-row-action-confirmation-dialog');
$oContent = UIContentBlockUIBlockFactory::MakeStandard();
$oContent->AddCSSClass('ibo-row-action--confirmation--do-not-show-again');
$checkBox = InputUIBlockFactory::MakeStandard('checkbox', 'do_not_show_again', false);
$checkBox->AddCSSClass('ibo-row-action--confirmation--do-not-show-again--checkbox');
$checkBox->SetLabel(\Dict::S('UI:UserPref:DoNotShowAgain'));
$oContent->AddSubBlock($checkBox);
$oDialog->AddSubBlock($oContent);
return $oDialog;
}
public function GetRowActionsConfirmDialogInitializedFlag()
{
return static::$bDialogInitialized;
}
}

View File

@@ -0,0 +1,109 @@
<?php
/**
* Copyright (C) 2013-2021 Combodo SARL
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
*/
namespace Combodo\iTop\Application\UI\Base\Component\Dialog;
use Combodo\iTop\Application\UI\Base\Component\Html\Html;
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
/**
*
* @package Combodo\iTop\Application\UI\Base\Component\Dialog
* @since 3.1.0
*/
class Dialog extends UIContentBlock
{
// Overloaded constants
public const BLOCK_CODE = 'ibo-dialog';
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/dialog/layout';
public const DEFAULT_JS_ON_READY_TEMPLATE_REL_PATH = 'base/components/dialog/layout';
public const DEFAULT_JS_FILES_REL_PATH = [
'js/components/dialog.js',
];
/** @var string $sTitle */
protected string $sTitle;
/** @var string $sContent */
protected string $sContent;
/**
* Alert constructor.
*
* @param string $sTitle
* @param string $sContent
* @param string|null $sId
*/
public function __construct(string $sTitle = '', string $sContent = '', ?string $sId = null)
{
parent::__construct($sId);
$this->sContent = $sContent;
if (!empty($sContent)) {
$this->AddSubBlock(new Html($sContent));
}
}
/**
* @return string
*/
public function GetTitle(): string
{
return $this->sTitle;
}
/**
* @param string $sTitle Title of the alert
*
* @return $this
*/
public function SetTitle(string $sTitle): Dialog
{
$this->sTitle = $sTitle;
return $this;
}
/**
* Return the raw HTML content, should be already sanitized.
*
* @return string
*/
public function GetContent(): string
{
return $this->sContent;
}
/**
* Set the raw HTML content, must be already sanitized.
*
* @param string $sContent The raw HTML content, must be already sanitized
*
* @return $this
*/
public function SetContent(string $sContent): Dialog
{
$this->sContent = $sContent;
return $this;
}
}

View File

@@ -0,0 +1,54 @@
<?php
/**
* Copyright (C) 2013-2021 Combodo SARL
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
*/
namespace Combodo\iTop\Application\UI\Base\Component\Dialog;
use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory;
/**
* Class DialogUIBlockFactory
*
* @api
*
* @since 3.1.0
* @package Combodo\iTop\Application\UI\Base\Component\Dialog
*/
class DialogUIBlockFactory extends AbstractUIBlockFactory
{
/** @inheritDoc */
public const TWIG_TAG_NAME = 'UIDialog';
/** @inheritDoc */
public const UI_BLOCK_CLASS_NAME = Dialog::class;
/**
* Make a basis Dialog component
*
* @param string $sTitle Title of the alert
* @param string $sContent The raw HTML content, must be already sanitized
* @param string|null $sId id of the html block
*
* @return \Combodo\iTop\Application\UI\Base\Component\Alert\Alert
*/
public static function MakeNeutral(string $sTitle = '', string $sContent = '', ?string $sId = null)
{
return new Dialog($sTitle, $sContent, $sId);
}
}