Files
iTop/js/dataTables.main.js
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

108 lines
3.4 KiB
JavaScript

/*
* @copyright Copyright (C) 2010-2021 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
function checkAllDataTable(tableId, value, listId) {
let tableSelector = $('#'+tableId);
// Set the 'selectionMode' for the future objects to load
let selectionMode = 'positive';
if (value) {
selectionMode = 'negative';
}
window['oSelectedItems'+CombodoSanitizer.Sanitize(listId, '', CombodoSanitizer.ENUM_SANITIZATION_FILTER_VARIABLE_NAME)] = [];
// Mark all the displayed items as check or unchecked depending on the value
tableSelector.find(':checkbox[name^=selectObj]:not([disabled])').each(function () {
let currentCheckbox = $(this);
currentCheckbox.prop('checked', value);
let currentLine = currentCheckbox.closest("tr");
(value) ? currentLine.addClass("selected") : currentLine.removeClass("selected");
});
tableSelector.closest(".dataTables_wrapper").parent().find(':input[name=selectionMode]').val(selectionMode);
// Reset the list of saved selection...
$(':input[name^=storedSelection]').remove();
tableSelector.parent().find(':checkbox[name^=selectObj]').trigger("change");
if (value) {
tableSelector.DataTable().rows().select();
} else {
tableSelector.DataTable().rows({page: 'current'}).deselect();
}
updateDataTableSelection(listId, tableId);
return true;
}
function updateDataTableSelection(listId, tableId) {
let selectionContainer = $('#'+listId+' [data-target="ibo-datatable--selection"]');
let selectionCount = $('#'+listId+' [name="selectionCount"]');
let selectionMode = $('#'+listId+' [name=selectionMode]').val();
selectionContainer.html('');
let currentSelection = window['oSelectedItems'+CombodoSanitizer.Sanitize(listId, '', CombodoSanitizer.ENUM_SANITIZATION_FILTER_VARIABLE_NAME)];
for (let i in currentSelection) {
let value = currentSelection[i];
selectionContainer.append('<input type="hidden" name="storedSelection[]" value="'+value+'">');
}
if (selectionMode === 'negative') {
let total = $('#'+tableId).DataTable().page.info()["recordsTotal"];
selectionCount.val(total-currentSelection.length);
$('#'+tableId).closest('.ibo-panel').find('.ibo-datatable--selected-count').html(total-currentSelection.length);
} else {
selectionCount.val(currentSelection.length);
$('#'+tableId).closest('.ibo-panel').find('.ibo-datatable--selected-count').html(currentSelection.length);
}
selectionCount.trigger('change');
}
function getMultipleSelectionParams(listId)
{
var oRes = {};
oRes.selectionMode = '';
if ($('#'+listId+' [name=selectionMode]').length > 0) {
oRes.selectionMode = $('#'+listId+' [name=selectionMode]').val();
}
oRes.selectObject = [];
$('#'+listId+' [name^=selectObject]:checked').each(function() {
oRes.selectObject.push($(this).val());
});
oRes.storedSelection = [];
$('#'+listId+' [name^=storedSelection]').each(function() {
oRes.storedSelection.push($(this).val());
});
return oRes;
}
/**
* Return column JSON declaration for row actions.
* Could be part of column or columnDefs declaration of datatable.js.
*
* @param sTableId
* @param iColumnTargetIndex
* @returns {*}
* @since 3.1.0
*/
function getRowActionsColumnDefinition(sTableId, iColumnTargetIndex = -1)
{
let aColumn = {
type: "html",
orderable: false,
render: function ( data, type, row, meta ) {
return $(`#${sTableId}_actions_buttons_template`).html();
}
};
if (iColumnTargetIndex !== -1) {
aColumn['targets'] = iColumnTargetIndex;
}
return aColumn;
}