diff --git a/application/cmdbabstract.class.inc.php b/application/cmdbabstract.class.inc.php index efda53248..a0fef70b4 100644 --- a/application/cmdbabstract.class.inc.php +++ b/application/cmdbabstract.class.inc.php @@ -4741,22 +4741,21 @@ EOF 'errors' => '

'.($bResult ? '' : implode('

', $aErrors)).'

', '@class' => $sCSSClass, ); - if ($bResult && (!$bPreview)) - { + if ($bResult && (!$bPreview)) { $oObj->DBUpdate(); } } set_time_limit(intval($iPreviousTimeLimit)); - $oP->Table($aHeaders, $aRows); - if ($bPreview) - { + $oDataTable = DataTableUIBlockFactory::MakeForForm(uniqid('form_', true), $aHeaders, $aRows); + $oDataTable->SetOptions(['select_mode' => 'custom']); + $oP->AddUiBlock($oDataTable); + if ($bPreview) { $sFormAction = utils::GetAbsoluteUrlAppRoot().'pages/UI.php'; // No parameter in the URL, the only parameter will be the ones passed through the form // Form to submit: $oP->add("
\n"); $oAppContext = new ApplicationContext(); $oP->add($oAppContext->GetForForm()); - foreach($aContextData as $sKey => $value) - { + foreach ($aContextData as $sKey => $value) { $oP->add("\n"); } $oP->add("\n"); diff --git a/application/displayblock.class.inc.php b/application/displayblock.class.inc.php index adff7dfce..b1284c217 100644 --- a/application/displayblock.class.inc.php +++ b/application/displayblock.class.inc.php @@ -1173,7 +1173,8 @@ JS $sTitle = Dict::Format($sFormat, $iTotalCount); $aExtraParams['query_params'] = $this->m_oFilter->GetInternalParams(); - $oBlock = DataTableUIBlockFactory::MakeForStaticData($sTitle, $aAttribs, $aData, null, $aExtraParams, $this->m_oFilter->ToOQL()); + $aOption['dom'] = 'pl'; + $oBlock = DataTableUIBlockFactory::MakeForStaticData($sTitle, $aAttribs, $aData, null, $aExtraParams, $this->m_oFilter->ToOQL(), $aOption); } else { // Simply count the number of elements in the set @@ -2134,7 +2135,6 @@ class MenuBlock extends DisplayBlock if ($bToolkitMenu) { $sLabel = Dict::S('UI:ConfigureThisList'); $aRegularActions['iTop::ConfigureList'] = ['label' => $sLabel, 'url' => '#', 'onclick' => "$('#datatable_dlg_datatable_{$sId}').dialog('open'); return false;"]; - $oRenderBlock->AddSubBlock(utils::GetPopupMenuItemsBlock(iPopupMenuExtension::MENU_OBJLIST_TOOLKIT, $param, $aRegularActions, $sId)); } break; diff --git a/application/ui.linksdirectwidget.class.inc.php b/application/ui.linksdirectwidget.class.inc.php index 6315f437b..7e5eb91e9 100644 --- a/application/ui.linksdirectwidget.class.inc.php +++ b/application/ui.linksdirectwidget.class.inc.php @@ -1,28 +1,18 @@ +/* + * @copyright Copyright (C) 2010-2021 Combodo SARL + * @license http://opensource.org/licenses/AGPL-3.0 + */ + +use Combodo\iTop\Application\UI\Base\Component\DataTable\DataTableUIBlockFactory; +use Combodo\iTop\Application\UI\Base\Layout\UIContentBlockUIBlockFactory; /** * Class UILinksWidgetDirect - * + * * @copyright Copyright (C) 2010-2021 Combodo SARL * @license http://opensource.org/licenses/AGPL-3.0 - */ - + */ class UILinksWidgetDirect { protected $sClass; @@ -243,23 +233,21 @@ class UILinksWidgetDirect protected function DisplayEditInPlace(WebPage $oPage, $oValue, $aArgs = array(), $sFormPrefix, $oCurrentObj, $aButtons = array('create', 'delete')) { $aAttribs = $this->GetTableConfig(); - $oValue->Rewind(); - $oPage->add('
'); - $aData = array(); - while($oLinkObj = $oValue->Fetch()) - { + while ($oLinkObj = $oValue->Fetch()) { $aRow = array(); $aRow['form::select'] = ''; - foreach($this->aZlist as $sLinkedAttCode) - { + foreach ($this->aZlist as $sLinkedAttCode) { $aRow[$sLinkedAttCode] = $oLinkObj->GetAsHTML($sLinkedAttCode); } $aData[] = $aRow; } - $oPage->table($aAttribs, $aData); - $oPage->add('
'); //listcontainer + $oDiv = UIContentBlockUIBlockFactory::MakeStandard($this->sInputid, ['listContainer']); + $oPage->AddSubBlock($oDiv); + $oDatatable = DataTableUIBlockFactory::MakeForForm($this->sInputid, $aAttribs, $aData); + $oDatatable->SetOptions(['select_mode' => 'custom']); + $oDiv->AddSubBlock($oDatatable); $sInputName = $sFormPrefix.'attr_'.$this->sAttCode; $aLabels = array( 'delete' => Dict::S('UI:Button:Delete'), diff --git a/application/ui.linkswidget.class.inc.php b/application/ui.linkswidget.class.inc.php index ab920db6c..32cf8a653 100644 --- a/application/ui.linkswidget.class.inc.php +++ b/application/ui.linkswidget.class.inc.php @@ -382,32 +382,28 @@ JS $oLinkedObj = MetaModel::GetObject($this->m_sRemoteClass, $oCurrentLink->Get($this->m_sExtKeyToRemote), false /* Must not be found */); // If successful, it means that we can edit its link - if ($oLinkedObj !== null) - { + if ($oLinkedObj !== null) { $bReadOnly = false; - } - // Else we retrieve it without restrictions (silos) and will display its link as readonly - else - { - $bReadOnly = true; - $oLinkedObj = MetaModel::GetObject($this->m_sRemoteClass, $oCurrentLink->Get($this->m_sExtKeyToRemote), false /* Must not be found */, true); - } + } // Else we retrieve it without restrictions (silos) and will display its link as readonly + else { + $bReadOnly = true; + $oLinkedObj = MetaModel::GetObject($this->m_sRemoteClass, $oCurrentLink->Get($this->m_sExtKeyToRemote), false /* Must not be found */, true); + } - if ($oCurrentLink->IsNew()) - { - $key = $iAddedId--; - } - else - { - $key = $oCurrentLink->GetKey(); - } - $aForm[$key] = $this->GetFormRow($oPage, $oLinkedObj, $oCurrentLink, $aArgs, $oCurrentObj, $key, $bReadOnly); + if ($oCurrentLink->IsNew()) { + $key = $iAddedId--; + } else { + $key = $oCurrentLink->GetKey(); + } + $aForm[$key] = $this->GetFormRow($oPage, $oLinkedObj, $oCurrentLink, $aArgs, $oCurrentObj, $key, $bReadOnly); } - $oBlock->AddSubBlock($this->GetFormTableBlock($this->m_aTableConfig, $aForm)); + $oDataTable = DataTableUIBlockFactory::MakeForForm("{$this->m_sAttCode}{$this->m_sNameSuffix}", $this->m_aTableConfig, $aForm); + $oDataTable->SetOptions(['select_mode' => 'custom']); + $oBlock->AddSubBlock($oDataTable); $oBlock->AddControls(); - return ConsoleBlockRenderer::RenderBlockTemplateInPage($oPage, $oBlock); + return ConsoleBlockRenderer::RenderBlockTemplateInPage($oPage, $oBlock); } /** diff --git a/js/linkswidget.js b/js/linkswidget.js index a1f863565..7ab54ad53 100644 --- a/js/linkswidget.js +++ b/js/linkswidget.js @@ -45,14 +45,13 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH this.RemoveSelected = function () { let my_id = '#'+me.id; + $('#datatable_'+me.id).DataTable().rows($('#datatable_'+me.id).find('tr.selected')).remove(); $('#linkedset_'+me.id+' .selection:checked').each(function () { $(my_id+'_row_'+this.value).remove(); let iLink = $(this).attr('data-link-id'); - if (iLink > 0) - { + if (iLink > 0) { me.aRemoved.push(iLink); - if (me.aModified.hasOwnProperty(iLink)) - { + if (me.aModified.hasOwnProperty(iLink)) { delete me.aModified[iLink]; } } diff --git a/templates/base/components/datatable/static/formtable/layout.ready.js.twig b/templates/base/components/datatable/static/formtable/layout.ready.js.twig index d8272199d..92b6b6c3a 100644 --- a/templates/base/components/datatable/static/formtable/layout.ready.js.twig +++ b/templates/base/components/datatable/static/formtable/layout.ready.js.twig @@ -11,10 +11,15 @@ var table{{ oUIBlock.GetId()|sanitize(constant('utils::ENUM_SANITIZATION_FILTER_ dom: "t", "order": [], {% if oUIBlock.GetOption("select_mode") is not empty %} + {% if oUIBlock.GetOption("select_mode") !="custom" %} select: { style: "{{ oUIBlock.GetOption("select_mode") }}" }, {% endif %} + columnDefs: [ + {orderable: false, targets: 0} + ], + {% endif %} }); if ($('#{{ oUIBlock.GetId() }}').find('thead').is(':visible')) { diff --git a/templates/base/components/datatable/static/formtablerow/layout.js.twig b/templates/base/components/datatable/static/formtablerow/layout.js.twig deleted file mode 100644 index e69de29bb..000000000 diff --git a/templates/base/components/datatable/static/layout.ready.js.twig b/templates/base/components/datatable/static/layout.ready.js.twig index 691fbde8e..393943e3f 100644 --- a/templates/base/components/datatable/static/layout.ready.js.twig +++ b/templates/base/components/datatable/static/layout.ready.js.twig @@ -35,18 +35,22 @@ $('#{{ oUIBlock.GetId() }}').DataTable({ rowId: "id", filter: false, {% if oUIBlock.GetOption("pageLength") is not empty %} - pageLength: {{ oUIBlock.GetOptions()["pageLength"] }}, + pageLength: {{ oUIBlock.GetOption("pageLength") }}, {% endif %} {% if oUIBlock.GetData()|length <= iPageSize %} paging: false, {% endif %} + {% if oUIBlock.GetOption("dom") is not empty %} + dom: "<'ibo-datatable-toolbar'{{ oUIBlock.GetOption("dom") }}>t", + {% else %} dom: "<'ibo-datatable--toolbar'<'ibo-datatable--toolbar-left' pl><'ibo-datatable--toolbar-right' i>>t<'ibo-datatable--toolbar'<'ibo-datatable--toolbar-left' pl><'ibo-datatable--toolbar-right' i>>", + {% endif %} lengthMenu: [[ {{ iPageSize }}, {{ iPageSize*2 }}, {{ iPageSize*3 }}, {{ iPageSize*4 }}, -1], [ {{ iPageSize }}, {{ iPageSize*2 }}, {{ iPageSize*3 }}, {{ iPageSize*4 }}, "{{ 'UI:Datatables:Language:DisplayLength:All'|dict_s }}"]], columns: [ {% for key, column in oUIBlock.GetColumns() %} { data: "{{ key }}", - width: "auto", + width: "auto", sortable: true }, {% endfor %}