mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-17 22:39:03 +02:00
N°5904 - Use attribute linked set edit mode to enable actions in view
This commit is contained in:
@@ -73,8 +73,6 @@ $(function()
|
||||
});
|
||||
|
||||
this._updateButtons();
|
||||
|
||||
me._updateTableInformation();
|
||||
},
|
||||
|
||||
// called when created, and later when changing options
|
||||
@@ -115,24 +113,8 @@ $(function()
|
||||
break;
|
||||
}
|
||||
},
|
||||
_updateTableInformation: function(){
|
||||
|
||||
let nbChecked = $('tbody tr input:checked', this.element).length;
|
||||
let count = $('tbody tr input', this.element).length;
|
||||
|
||||
$('#linkedset_'+this.id+'_alert_information').toggleClass('ibo-is-information', nbChecked > 0);
|
||||
|
||||
if(nbChecked > 0){
|
||||
$('#'+this.id+'_btnRemove').prop('disabled', false);
|
||||
$('#linkedset_'+this.id+'_alert_information span[data-role="ibo-datatable-selection-value"]').text(nbChecked + ' / ' + count + ' éléments sélectionnés');
|
||||
}
|
||||
else{
|
||||
$('#'+this.id+'_btnRemove').prop('disabled', true);
|
||||
$('#linkedset_'+this.id+'_alert_information span[data-role="ibo-datatable-selection-value"]').text(count + ' éléments');
|
||||
}
|
||||
},
|
||||
_onSelectChange: function () {
|
||||
this._updateTableInformation();
|
||||
this._updateButtons
|
||||
},
|
||||
_updateTable: function () {
|
||||
var me = this;
|
||||
@@ -431,8 +413,6 @@ $(function()
|
||||
me._updateTable();
|
||||
me.indicator.html('');
|
||||
$('[data-role="ibo-button"][data-action="add"]', this.element).prop('disabled', false);
|
||||
|
||||
me._updateTableInformation();
|
||||
});
|
||||
},
|
||||
subclassSelected: function()
|
||||
@@ -552,7 +532,6 @@ $(function()
|
||||
oRow.remove();
|
||||
this._updateButtons();
|
||||
this._updateTable();
|
||||
this._updateTableInformation();
|
||||
},
|
||||
_removeSelection: function(){
|
||||
var me = this;
|
||||
|
||||
@@ -58,26 +58,12 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
|
||||
return me.OnFormSubmit();
|
||||
});
|
||||
|
||||
this.UpdateTableInformation();
|
||||
$('#linkedset_'+me.id+' .selection').on('change', function () {
|
||||
me.OnSelectChange();
|
||||
});
|
||||
me.UpdateButtons();
|
||||
};
|
||||
|
||||
this.UpdateTableInformation = function(){
|
||||
|
||||
let nbChecked = $('#linkedset_'+me.id+' .selection:checked').length;
|
||||
let count = $('#linkedset_'+this.id+' tbody tr').length;
|
||||
|
||||
$('#linkedset_'+me.iInputId+'_alert_information').toggleClass('ibo-is-information', nbChecked > 0);
|
||||
|
||||
if(nbChecked > 0){
|
||||
$('#'+me.id+'_btnRemove').prop('disabled', false);
|
||||
$('#linkedset_'+me.iInputId+'_alert_information span[data-role="ibo-datatable-selection-value"]').text(nbChecked + ' / ' + count + ' éléments sélectionnés');
|
||||
}
|
||||
else{
|
||||
$('#'+me.id+'_btnRemove').prop('disabled', true);
|
||||
$('#linkedset_'+me.iInputId+'_alert_information span[data-role="ibo-datatable-selection-value"]').text(count + ' éléments');
|
||||
}
|
||||
}
|
||||
|
||||
this.RemoveSelected = function () {
|
||||
let my_id = '#'+me.id;
|
||||
$('#linkedset_'+me.id+' .selection:checked').closest('tr').each(function () {
|
||||
@@ -92,7 +78,7 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
|
||||
$('#'+me.id+'_empty_row').show();
|
||||
}
|
||||
|
||||
this.UpdateTableInformation();
|
||||
this.UpdateButtons();
|
||||
};
|
||||
|
||||
this.Remove = function(oRowElement){
|
||||
@@ -115,11 +101,11 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
|
||||
me.aAdded[iUniqueId] = null;
|
||||
}
|
||||
|
||||
this.UpdateTableInformation();
|
||||
this.UpdateButtons();
|
||||
}
|
||||
|
||||
this.OnSelectChange = function () {
|
||||
this.UpdateTableInformation();
|
||||
this.UpdateButtons();
|
||||
};
|
||||
|
||||
this.AddObjects = function () {
|
||||
@@ -195,6 +181,14 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
|
||||
{
|
||||
okBtn.prop('disabled', true);
|
||||
}
|
||||
|
||||
let nbChecked = $('#linkedset_'+me.id+' .selection:checked').length;
|
||||
if(nbChecked > 0){
|
||||
$('[data-role="ibo-button"][data-action="detach"]', $('#linkedset_'+me.id)).prop('disabled', false);
|
||||
}
|
||||
else{
|
||||
$('[data-role="ibo-button"][data-action="detach"]', $('#linkedset_'+me.id)).prop('disabled', true);
|
||||
}
|
||||
};
|
||||
|
||||
this.DoAddObjects = function () {
|
||||
@@ -389,7 +383,7 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
|
||||
let iLink = oCheckbox.attr('data-link-id');
|
||||
let iUniqueId = oCheckbox.attr('data-unique-id');
|
||||
let sAttCode = $(this).closest('.attribute-edit').attr('data-attcode');
|
||||
let value = $(this).val();
|
||||
let value = $(this).val();;
|
||||
return me.OnValueChange(iLink, iUniqueId, sAttCode, value, this);
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -16,6 +16,7 @@ use Combodo\iTop\Application\UI\Base\Component\Panel\PanelUIBlockFactory;
|
||||
use Combodo\iTop\Application\UI\Base\Component\Toolbar\Toolbar;
|
||||
use Combodo\iTop\Application\UI\Base\Component\Toolbar\ToolbarUIBlockFactory;
|
||||
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
|
||||
use Combodo\iTop\Service\Links\LinkSetModel;
|
||||
use ConfigException;
|
||||
use CoreException;
|
||||
use CoreUnexpectedValue;
|
||||
@@ -267,41 +268,6 @@ class BlockDirectLinksEditTable extends UIContentBlock
|
||||
return ($bSafe) ? \utils::GetSafeId($sFieldId) : $sFieldId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert edit_mode to relation type.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
private function ConvertEditModeToRelationType(): ?string
|
||||
{
|
||||
switch ($this->oAttributeLinkedSet->GetEditMode()) {
|
||||
case LINKSET_EDITMODE_INPLACE:
|
||||
return LINKSET_RELATIONTYPE_PROPERTY;
|
||||
case LINKSET_EDITMODE_ADDREMOVE:
|
||||
return LINKSET_RELATIONTYPE_LINK;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert edit_mode to read only.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function ConvertEditModeToReadOnly(): bool
|
||||
{
|
||||
switch ($this->oAttributeLinkedSet->GetEditMode()) {
|
||||
case LINKSET_EDITMODE_NONE:
|
||||
case LINKSET_EDITMODE_ADDONLY:
|
||||
case LINKSET_EDITMODE_ACTIONS:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return row actions.
|
||||
*
|
||||
@@ -311,9 +277,9 @@ class BlockDirectLinksEditTable extends UIContentBlock
|
||||
{
|
||||
$aRowActions = array();
|
||||
|
||||
if (!$this->ConvertEditModeToReadOnly()) {
|
||||
if (!LinkSetModel::ConvertEditModeToReadOnly($this->oAttributeLinkedSet)) {
|
||||
|
||||
switch ($this->ConvertEditModeToRelationType()) {
|
||||
switch (LinkSetModel::ConvertEditModeToRelationType($this->oAttributeLinkedSet)) {
|
||||
|
||||
case LINKSET_RELATIONTYPE_LINK:
|
||||
$aRowActions[] = array(
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
namespace Combodo\iTop\Application\UI\Links\Direct;
|
||||
|
||||
use Combodo\iTop\Application\UI\Links\AbstractBlockLinksViewTable;
|
||||
use Combodo\iTop\Service\Links\LinkSetModel;
|
||||
use MetaModel;
|
||||
|
||||
/**
|
||||
@@ -61,9 +62,9 @@ class BlockDirectLinksViewTable extends AbstractBlockLinksViewTable
|
||||
{
|
||||
$aRowActions = array();
|
||||
|
||||
if (!$this->oAttDef->GetReadOnly()) {
|
||||
if (!LinkSetModel::ConvertEditModeToReadOnly($this->oAttDef)) {
|
||||
|
||||
switch ($this->oAttDef->GetRelationType()) {
|
||||
switch (LinkSetModel::ConvertEditModeToRelationType($this->oAttDef)) {
|
||||
|
||||
case LINKSET_RELATIONTYPE_LINK:
|
||||
$aRowActions[] = array(
|
||||
|
||||
@@ -14,6 +14,7 @@ use Combodo\iTop\Application\UI\Base\Component\Input\InputUIBlockFactory;
|
||||
use Combodo\iTop\Application\UI\Base\Component\Panel\PanelUIBlockFactory;
|
||||
use Combodo\iTop\Application\UI\Base\Component\Toolbar\ToolbarUIBlockFactory;
|
||||
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
|
||||
use Combodo\iTop\Service\Links\LinkSetModel;
|
||||
use ConfigException;
|
||||
use CoreException;
|
||||
use DBObject;
|
||||
@@ -186,14 +187,19 @@ class BlockIndirectLinksEditTable extends UIContentBlock
|
||||
}
|
||||
|
||||
// Toolbar and actions
|
||||
$oToolbar = ToolbarUIBlockFactory::MakeForButton();
|
||||
$oActionButtonUnlink = ButtonUIBlockFactory::MakeNeutral('Unlink');
|
||||
$oActionButtonUnlink->SetOnClickJsCode("oWidget{$this->oUILinksWidget->GetInputId()}.RemoveSelected();");
|
||||
$oToolbar->AddSubBlock($oActionButtonUnlink);
|
||||
$oActionButtonLink = ButtonUIBlockFactory::MakeNeutral('Link');
|
||||
$oActionButtonLink->SetOnClickJsCode("oWidget{$this->oUILinksWidget->GetInputId()}.AddObjects();");
|
||||
$oToolbar->AddSubBlock($oActionButtonLink);
|
||||
$oTablePanel->AddToolbarBlock($oToolbar);
|
||||
if (!LinkSetModel::ConvertEditModeToReadOnly($this->oAttributeLinkedSetIndirect)) {
|
||||
$oToolbar = ToolbarUIBlockFactory::MakeForButton();
|
||||
$oActionButtonUnlink = ButtonUIBlockFactory::MakeNeutral('Unlink');
|
||||
$oActionButtonUnlink->SetOnClickJsCode("oWidget{$this->oUILinksWidget->GetInputId()}.RemoveSelected();");
|
||||
$oActionButtonUnlink->AddDataAttribute('action', 'detach');
|
||||
$oToolbar->AddSubBlock($oActionButtonUnlink);
|
||||
$oActionButtonLink = ButtonUIBlockFactory::MakeNeutral('Link');
|
||||
$oActionButtonLink->SetOnClickJsCode("oWidget{$this->oUILinksWidget->GetInputId()}.AddObjects();");
|
||||
$oActionButtonLink->AddDataAttribute('action', 'add');
|
||||
$oToolbar->AddSubBlock($oActionButtonLink);
|
||||
$oTablePanel->AddToolbarBlock($oToolbar);
|
||||
}
|
||||
|
||||
$oTablePanel->AddSubBlock($oDataTable);
|
||||
|
||||
$this->AddSubBlock($oTablePanel);
|
||||
@@ -418,7 +424,7 @@ JS
|
||||
{
|
||||
$aRowActions = array();
|
||||
|
||||
if (!$this->oAttributeLinkedSetIndirect->GetReadOnly()) {
|
||||
if (!LinkSetModel::ConvertEditModeToReadOnly($this->oAttributeLinkedSetIndirect)) {
|
||||
$aRowActions[] = array(
|
||||
'label' => 'UI:Links:ActionRow:Detach',
|
||||
'tooltip' => 'UI:Links:ActionRow:Detach+',
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
namespace Combodo\iTop\Application\UI\Links\Indirect;
|
||||
|
||||
use Combodo\iTop\Application\UI\Links\AbstractBlockLinksViewTable;
|
||||
use Combodo\iTop\Service\Links\LinkSetModel;
|
||||
use MetaModel;
|
||||
use PHPUnit\Exception;
|
||||
|
||||
@@ -74,7 +75,7 @@ class BlockIndirectLinksViewTable extends AbstractBlockLinksViewTable
|
||||
{
|
||||
$aRowActions = array();
|
||||
|
||||
if (!$this->oAttDef->GetReadOnly()) {
|
||||
if (!LinkSetModel::ConvertEditModeToReadOnly($this->oAttDef)) {
|
||||
|
||||
$aRowActions[] = array(
|
||||
'label' => 'UI:Links:ActionRow:Detach',
|
||||
|
||||
@@ -72,4 +72,39 @@ class LinkSetModel
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert edit_mode to relation type.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
static public function ConvertEditModeToRelationType(AttributeLinkedSet $oAttDef): ?string
|
||||
{
|
||||
switch ($oAttDef->GetEditMode()) {
|
||||
case LINKSET_EDITMODE_INPLACE:
|
||||
return LINKSET_RELATIONTYPE_PROPERTY;
|
||||
case LINKSET_EDITMODE_ADDREMOVE:
|
||||
return LINKSET_RELATIONTYPE_LINK;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert edit_mode to read only.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
static public function ConvertEditModeToReadOnly(AttributeLinkedSet $oAttDef): bool
|
||||
{
|
||||
switch ($oAttDef->GetEditMode()) {
|
||||
case LINKSET_EDITMODE_NONE:
|
||||
case LINKSET_EDITMODE_ADDONLY:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user