Files
iTop/templates/base/components/datatable/static/layout.ready.js.twig
bdalsass 5157f511fc N°5073 - Implements line actions in a datatable (#337)
* datatable row actions

Below is a sample of extra param to enable feature:

		$aExtraParams['row_actions'] = [
			[
				'tooltip'        => 'add an element',
				'icon_css_class' => 'fa-plus',
				'css_class'      => 'ibo-is-success',
				'level'          => 'secondary',
				'on_action_js'   => 'console.log(aData);',
			],
			[
				'tooltip'        => 'remove an element',
				'icon_css_class' => 'fa-minus',
				'css_class'      => 'ibo-is-danger',
				'level'          => 'secondary',
				'on_action_js'   => 'console.log("You clicked the remove button");',
			],
			[
				'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);',
			],
		];

* datatable row actions (update)

* datatable row actions (update)

* datatable row actions (add template role)

* datatable row actions (align actions)

* datatable row actions (change template factory make to make standard)

* datatable row actions (use trait to handle row actions)

* datatable row actions (row actions templates)

* datatable row actions (row actions templates)

* datatable row actions (row actions templates)

* datatable row actions (extends to static and form)

* datatable row actions (extends to static and form)

* datatable row actions (code review S)

* datatable row actions (code review S)

* datatable row actions (code review S)

* Update js/dataTables.main.js

Co-authored-by: Molkobain <lajarige.guillaume@free.fr>

* Update js/dataTables.main.js

Co-authored-by: Molkobain <lajarige.guillaume@free.fr>

* Update sources/Application/UI/Base/Component/DataTable/StaticTable/StaticTable.php

Co-authored-by: Molkobain <lajarige.guillaume@free.fr>

* Update templates/base/components/datatable/row-actions/handler.js.twig

Co-authored-by: Molkobain <lajarige.guillaume@free.fr>

* datatable row actions (code review M)

* Update js/dataTables.main.js

Co-authored-by: Molkobain <lajarige.guillaume@free.fr>

* Update js/dataTables.main.js

Co-authored-by: Molkobain <lajarige.guillaume@free.fr>

* Update js/dataTables.main.js

Co-authored-by: Molkobain <lajarige.guillaume@free.fr>

* Update sources/Application/UI/Base/Component/DataTable/StaticTable/StaticTable.php

Co-authored-by: Molkobain <lajarige.guillaume@free.fr>

* Update sources/Application/UI/Base/Component/DataTable/StaticTable/StaticTable.php

Co-authored-by: Molkobain <lajarige.guillaume@free.fr>

* Update sources/Application/UI/Base/Component/DataTable/StaticTable/StaticTable.php

Co-authored-by: Molkobain <lajarige.guillaume@free.fr>

* Update js/dataTables.main.js

Co-authored-by: Molkobain <lajarige.guillaume@free.fr>

* Update sources/Application/UI/Base/Component/DataTable/DataTableUIBlockFactory.php

Co-authored-by: Molkobain <lajarige.guillaume@free.fr>

* Update sources/Application/UI/Base/Component/DataTable/StaticTable/StaticTable.php

Co-authored-by: Molkobain <lajarige.guillaume@free.fr>

* Update application/utils.inc.php

Co-authored-by: Molkobain <lajarige.guillaume@free.fr>

* datatable row actions (code review M2)

* datatable row actions (code review M3)

Co-authored-by: Molkobain <lajarige.guillaume@free.fr>
2022-09-26 08:20:28 +02:00

111 lines
5.0 KiB
Twig

{# @copyright Copyright (C) 2010-2021 Combodo SARL #}
{# @license http://opensource.org/licenses/AGPL-3.0 #}
{% set sListId = oUIBlock.GetId() %}
{% set sListIDForVarSuffix = ('' ~ sListId)|sanitize(constant('utils::ENUM_SANITIZATION_FILTER_VARIABLE_NAME')) %}
{% if oUIBlock.GetOption("iPageSize") is not empty %}
{% set iPageSize = oUIBlock.GetOption("iPageSize") %}
{% else %}
{% set iPageSize = 10 %}
{% endif %}
var oTable{{ sListIDForVarSuffix }} = $('#{{ oUIBlock.GetId() }}').DataTable({
language: {
processing: "{{ 'UI:Datatables:Language:Processing'|dict_s }}",
search: "{{ 'UI:Datatables:Language:Search'|dict_s }}",
lengthMenu: "{{ 'UI:Datatables:Language:LengthMenu'|dict_s }}",
zeroRecords: "{{ 'UI:Datatables:Language:ZeroRecords'|dict_s }}",
info: "{{ 'UI:Datatables:Language:Info'|dict_s }}",
infoEmpty: "",
infoFiltered: "({{ 'UI:Datatables:Language:InfoFiltered'|dict_s }})",
emptyTable: "{{ 'UI:Datatables:Language:EmptyTable'|dict_s }}",
paginate: {
first: "<i class=\"fas fa-angle-double-left\"></i>",
previous: "<i class=\"fas fa-angle-left\"></i>",
next: "<i class=\"fas fa-angle-right\"></i>",
last: "<i class=\"fas fa-angle-double-right\"></i>"
},
aria: {
sortAscending: ": {{ 'UI:Datatables:Language:Sort:Ascending'|dict_s }}",
sortDescending: ": {{ 'UI:Datatables:Language:Sort:Descending'|dict_s }}"
}
},
scrollX: true,
{% if oUIBlock.GetOption('sMaxHeight') is not empty %}
scrollY: "{{ oUIBlock.GetOption('sMaxHeight') }}",
{% endif %}
scrollCollapse: true,
order: [],
rowId: "id",
filter: false,
{% if oUIBlock.GetOption("pageLength") is not empty %}
pageLength: {{ oUIBlock.GetOption("pageLength") }},
{% 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",
sortable: true
},
{% endfor %}
{% if oUIBlock.HasRowActions() %}
getRowActionsColumnDefinition('{{ oUIBlock.GetId() }}'),
{% endif %}
],
drawCallback: function (settings) {
if(settings.json)
{
$(this).closest('.ibo-panel').find('.ibo-datatable--result-count').html(settings.json.recordsTotal);
}
// Hiding pagination if only one page
if ($(this).closest('.dataTables_wrapper').find('.dataTables_paginate:last .paginate_button:not(.previous):not(.next)').length < 2)
{
$(this).closest('.dataTables_wrapper').find('.dataTables_paginate, .dataTables_info').hide();
}
else
{
$(this).closest('.dataTables_wrapper').find('.dataTables_paginate, .dataTables_info').show();
}
if ($(this).closest('.ibo-panel--body').find('[name=selectionMode]').val() === "negative")
{
$(this).closest('.dataTables_wrapper').find('.checkAll')[0].checked = true;
}
// Disable hyperlinks if necessary
{% if oUIBlock.GetOption("disable_hyperlinks") is same as true or (oUIBlock.GetOption("select_mode") is not empty and oUIBlock.GetOption("disable_hyperlinks") is not same as false) %}
$("#{{ oUIBlock.GetId() }} a").on('click', function (e) {
e.preventDefault();
});
{% endif %}
},
initComplete: function () {
if (this.api().page.info().pages < 2)
{
this.closest('.dataTables_wrapper').find('.dataTables_length').hide();
}
// Set header and body datatables status as loaded
this.attr('data-status', 'loaded');
this.closest('.dataTables_scroll').find('.dataTables_scrollHead .ibo-datatable').attr('data-status', 'loaded');
}
});
if (window.ResizeObserver)
{
let oStaticTable{{ sListIDForVarSuffix }}ResizeTimeout = null;
const oStaticTable{{ sListIDForVarSuffix }}Resize = new ResizeObserver(function(){
clearTimeout(oStaticTable{{ sListIDForVarSuffix }}ResizeTimeout);
oStaticTable{{ sListIDForVarSuffix }}ResizeTimeout = setTimeout(function(){
$('#{{ oUIBlock.GetId() }}').DataTable().columns.adjust();
}, 120);
});
oStaticTable{{ sListIDForVarSuffix }}Resize.observe($('#{{ oUIBlock.GetId() }}')[0]);
}
{% include 'base/components/datatable/row-actions/handler.js.twig' %}