mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-18 14:58:43 +02:00
N°2847 - Tranform old itop datatable to jquery DataTable - Fix management of button "Add"
This commit is contained in:
@@ -262,7 +262,7 @@ function UpdateFileName(id, sNewFileName) {
|
||||
* Reload a search form for the specified class
|
||||
*/
|
||||
function ReloadSearchForm(divId, sClassName, sBaseClass, sContext, sTableId, sExtraParams) {
|
||||
var oDiv = $('#'+divId);
|
||||
var oDiv = $('#'+divId).parent();
|
||||
oDiv.block();
|
||||
// deprecated in jQuery 1.8
|
||||
//var oFormEvents = $('#ds_'+divId+' form').data('events');
|
||||
|
||||
@@ -211,6 +211,7 @@ function SetObjectBreadCrumbEntry(DBObject $oObj, WebPage $oPage)
|
||||
*/
|
||||
function DisplaySearchSet($oP, $oFilter, $bSearchForm = true, $sBaseClass = '', $sFormat = '', $bDoSearch = true, $bSearchFormOpen = true)
|
||||
{
|
||||
//search block
|
||||
$oBlockForm=null;
|
||||
if ($bSearchForm)
|
||||
{
|
||||
@@ -245,12 +246,15 @@ function DisplaySearchSet($oP, $oFilter, $bSearchForm = true, $sBaseClass = '',
|
||||
$oP->SetBreadCrumbEntry($sPageId, $sLabel, '', '', 'fas fa-search', iTopWebPage::ENUM_BREADCRUMB_ENTRY_ICON_TYPE_CSS_CLASSES);
|
||||
}
|
||||
if ($bSearchForm) {
|
||||
$oUIBlockForm=$oBlockForm->GetDisplay($oP,'0');
|
||||
//add search block
|
||||
$sTableId = utils::ReadParam('_table_id_', null, false, 'raw_data');
|
||||
if($sTableId=='')
|
||||
{
|
||||
$sTableId = '1';
|
||||
$sTableId = 'result_1';
|
||||
}
|
||||
$aExtraParams['table_id']=$sTableId;
|
||||
$oUIBlockForm=$oBlockForm->GetDisplay($oP,'search_1');
|
||||
//add result block
|
||||
$oUIBlock=$oBlock->GetDisplay($oP, $sTableId);
|
||||
$oUIBlock->AddCSSClasses("display_block sf_results_area");
|
||||
//$oUIBlockForm->AddSubBlock($oUIBlock);
|
||||
|
||||
@@ -234,7 +234,7 @@ try
|
||||
|
||||
case 'search_and_refresh':
|
||||
$oPage->SetContentType('application/json');
|
||||
$extraParams = utils::ReadParam('extra_param', '', false, 'raw_data');
|
||||
$extraParams = utils::ReadParam('extra_params', '', false, 'raw_data');
|
||||
$aExtraParams = array();
|
||||
if (is_array($extraParams))
|
||||
{
|
||||
@@ -411,7 +411,15 @@ try
|
||||
$aObj[$sAlias."/".$sAttCode ] = $aObject[$sAlias]->GetKey();
|
||||
}
|
||||
else {
|
||||
$aObj[$sAlias."/".$sAttCode ] = $aObject[$sAlias]->GetAsHTML($sAttCode);
|
||||
$oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
|
||||
if ($oAttDef instanceof AttributeExternalKey)
|
||||
{
|
||||
$aObj[$sAlias."/".$sAttCode ] = $aObject[$sAlias]->Get($sAttCode);
|
||||
}
|
||||
else{
|
||||
$aObj[$sAlias."/".$sAttCode ] = $aObject[$sAlias]->GetAsHTML($sAttCode);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -570,7 +570,7 @@ class DataTableFactory
|
||||
public static function GetOptionsForRendering(array $aColumns, string $sSelectMode, string $sFilter, int $iLength, array $aClassAliases, array $aExtraParams)
|
||||
{
|
||||
$aOptions = [];
|
||||
|
||||
$sTableId=$aExtraParams["table_id"];
|
||||
$aColumnsDefinitions = [];
|
||||
$aColumnDefinition = [];
|
||||
|
||||
@@ -578,18 +578,22 @@ class DataTableFactory
|
||||
$aColumnDefinition["width"] = "auto";
|
||||
$aColumnDefinition["searchable"] = false;
|
||||
$aColumnDefinition["sortable"] = false;
|
||||
$aColumnDefinition["title"] = "<span class=\"row_input\"><input type=\"checkbox\" onclick=\"checkAllDataTable(\'#{{ oUIBlock.GetId() }}\',this.checked);\" class=\"checkAll\" id=\"field_{{ oUIBlock.GetId() }}_check_all\" name=\"field_{{ oUIBlock.GetId() }}_check_all\" title=\"{{ 'UI:SearchValue:CheckAll'|dict_s }} / {{ 'UI:SearchValue:UncheckAll'|dict_s }}\" /></span>";
|
||||
if ($sSelectMode != "single") {
|
||||
$aColumnDefinition["title"] = "<span class=\"row_input\"><input type=\"checkbox\" onclick=\"checkAllDataTable('#".$sTableId."',this.checked);\" class=\"checkAll\" id=\"field_".$sTableId."_check_all\" name=\"field_".$sTableId."_check_all\" title=\"".Dict::S('UI:SearchValue:CheckAll' )." / ".Dict::S('UI:SearchValue:UncheckAll')."\" /></span>";
|
||||
} else{
|
||||
$aColumnDefinition["title"] = "";
|
||||
}
|
||||
$aColumnDefinition["type"] = "html";
|
||||
$aColumnDefinition["data"] = "";
|
||||
$aColumnDefinition["render"] = "function (data, type, row) {
|
||||
var oCheckboxElem = $('<span class=\"row_input\"><input type=\"checkbox\" class=\"selectList{{ oUIBlock.GetId() }}\" name=\"selectObject\" /></span>');
|
||||
if (row.limited_access) {
|
||||
oCheckboxElem.html('-');
|
||||
} else {
|
||||
oCheckboxElem.find(':input').attr('data-object-id', row.id).attr('data-target-object-id', row.target_id);
|
||||
}
|
||||
return oCheckboxElem.prop('outerHTML');
|
||||
}";
|
||||
$aColumnDefinition["render"]["display"] = "";
|
||||
if ($sSelectMode != "single") {
|
||||
$aColumnDefinition["render"]["display"] = $aColumnDefinition["render"]["display"] . " var oCheckboxElem = $('<span class=\"row_input\"><input type=\"checkbox\" class=\"selectList".$sTableId."\" name=\"selectObject\" /></span>');";
|
||||
}
|
||||
else {
|
||||
$aColumnDefinition["render"]["display"] = $aColumnDefinition["render"]["display"] . " var oCheckboxElem = $('<span class=\"row_input\"><input type=\"radio\" class=\"selectList".$sTableId."\" name=\"selectObject\" /></span>');";
|
||||
}
|
||||
$aColumnDefinition["render"]["display"] = $aColumnDefinition["render"]["display"] . " if (row.limited_access) { oCheckboxElem.html('-'); } else { oCheckboxElem.find(':input').attr('data-object-id', row.id).attr('data-target-object-id', row.target_id); }";
|
||||
$aColumnDefinition["render"]["display"] = $aColumnDefinition["render"]["display"]. " return oCheckboxElem.prop('outerHTML'); ";
|
||||
array_push($aColumnsDefinitions, $aColumnDefinition);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ function checkAllDataTable(table, value) {
|
||||
if (value) {
|
||||
selectionMode = 'negative';
|
||||
}
|
||||
|
||||
oSelectedItems{{ oUIBlock.GetOption('sListId') }} =[];
|
||||
// Mark all the displayed items as check or unchecked depending on the value
|
||||
$(table).find(':checkbox[name^=selectObj]:not([disabled])').each(function () {
|
||||
var $currentCheckbox = $(this);
|
||||
@@ -20,8 +20,10 @@ function checkAllDataTable(table, value) {
|
||||
|
||||
if (value) {
|
||||
$(table).DataTable().rows().select();
|
||||
$('#btn_ok_{{ oUIBlock.GetOption('sTableId') }}').prop('disabled', false);
|
||||
} else {
|
||||
$(table).DataTable().rows({page: 'current'}).deselect();
|
||||
$('#btn_ok_{{ oUIBlock.GetOption('sTableId') }}').prop('disabled', true);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -118,10 +120,10 @@ var oTable{{ oUIBlock.GetId() }} = $('#{{ oUIBlock.GetId() }}').DataTable({
|
||||
data: "",
|
||||
render: function (data, type, row) {
|
||||
var oCheckboxElem =
|
||||
{% if oUIBlock.GetOption("select_mode") != "single" %}
|
||||
{% if oUIBlock.GetOption("select_mode") != "single" %}
|
||||
$('<span class="row_input"><input type="checkbox" class="selectList{{ oUIBlock.GetId() }}" name="selectObject[]" /></span>');
|
||||
{% else %}
|
||||
$('<span class="row_input"><input type="radio" class="selectList{{ oUIBlock.GetId() }}" name="selectObject[]" /></span>');
|
||||
$('<span class="row_input"><input type="radio" class="selectList{{ oUIBlock.GetId() }}" name="selectObject[]" /></span>');
|
||||
{% endif %}
|
||||
if (row.limited_access) {
|
||||
oCheckboxElem.html('-');
|
||||
@@ -172,104 +174,79 @@ var oTable{{ oUIBlock.GetId() }} = $('#{{ oUIBlock.GetId() }}').DataTable({
|
||||
|
||||
{% if oUIBlock.GetOption("select_mode") is not empty %}
|
||||
{% if oUIBlock.GetOption("select_mode") != "single" %}
|
||||
console.warn('aa');
|
||||
oTable{{ oUIBlock.GetId() }}.off('select').on('select', function (oEvent, dt, type, indexes) {
|
||||
var aData = oTable{{ oUIBlock.GetId() }}.rows(indexes).data().toArray();
|
||||
// Checking input
|
||||
$('#{{ oUIBlock.GetId() }} tr[role="row"].selected td:first-child input').prop('checked', true);
|
||||
// Saving values in temp array
|
||||
for (var i in aData) {
|
||||
var iItemId = aData[i].id;
|
||||
if (oSelectedItems{{ oUIBlock.GetOption('sListId') }}.indexOf(iItemId) === -1) {
|
||||
oSelectedItems{{ oUIBlock.GetOption('sListId') }}.push(iItemId);
|
||||
}
|
||||
var aData = oTable{{ oUIBlock.GetId() }}.rows(indexes).data().toArray();
|
||||
if( $(this).closest('.ibo-panel--body').find('[name=selectionMode]').val() === "negative")
|
||||
{
|
||||
// Checking input
|
||||
$('#{{ oUIBlock.GetId() }} tr[role="row"].selected td:first-child input').prop('checked', true);
|
||||
// Saving values in temp array
|
||||
for (var i in aData) {
|
||||
var iItemId = aData[i].id;
|
||||
if (oSelectedItems{{ oUIBlock.GetOption('sListId') }}.indexOf(iItemId) > -1) {
|
||||
oSelectedItems{{ oUIBlock.GetOption('sListId') }}.splice(oSelectedItems{{ oUIBlock.GetOption('sListId') }}.indexOf(iItemId), 1);
|
||||
}
|
||||
}
|
||||
if (oSelectedItems{{ oUIBlock.GetOption('sListId') }}.length === oTable{{ oUIBlock.GetId() }}.page.info()["recordsTotal"] ) {
|
||||
$('#btn_ok_{{ oUIBlock.GetOption('sTableId') }}').prop('disabled', true);
|
||||
} else {
|
||||
$('#btn_ok_{{ oUIBlock.GetOption('sTableId') }}').prop('disabled', false);
|
||||
}
|
||||
}
|
||||
if ((oSelectedItems{{ oUIBlock.GetOption('sListId') }}.length === oTable{{ oUIBlock.GetId() }}.page.info()["recordsTotal"] && $(this).closest('.ibo-panel--body').find('[name=selectionMode]').val() === "negative")) {
|
||||
$('#btn_ok_{{ oUIBlock.GetOption('sTableId') }}').prop('disabled', true);
|
||||
} else {
|
||||
$('#btn_ok_{{ oUIBlock.GetOption('sTableId') }}').prop('disabled', false);
|
||||
else {
|
||||
// Checking input
|
||||
$('#{{ oUIBlock.GetId() }} tr[role="row"].selected td:first-child input').prop('checked', true);
|
||||
// Saving values in temp array
|
||||
for (var i in aData) {
|
||||
var iItemId = aData[i].id;
|
||||
if (oSelectedItems{{ oUIBlock.GetOption('sListId') }}.indexOf(iItemId) === -1) {
|
||||
oSelectedItems{{ oUIBlock.GetOption('sListId') }}.push(iItemId);
|
||||
}
|
||||
}
|
||||
$('#btn_ok_{{ oUIBlock.GetOption('sTableId') }}').prop('disabled', false);
|
||||
}
|
||||
});
|
||||
|
||||
oTable{{ oUIBlock.GetId() }}.off('deselect').on('deselect', function (oEvent, dt, type, indexes) {
|
||||
var aData = oTable{{ oUIBlock.GetId() }}.rows(indexes).data().toArray();
|
||||
var aData = oTable{{ oUIBlock.GetId() }}.rows(indexes).data().toArray();
|
||||
|
||||
// Checking input
|
||||
$('#{{ oUIBlock.GetId() }} tr[role="row"]:not(.selected) td:first-child input').prop('checked', false);
|
||||
// Saving values in temp array
|
||||
for (var i in aData) {
|
||||
var iItemId = aData[i].id;
|
||||
if (oSelectedItems{{ oUIBlock.GetOption('sListId') }}.indexOf(iItemId) > -1) {
|
||||
oSelectedItems{{ oUIBlock.GetOption('sListId') }}.splice(oSelectedItems{{ oUIBlock.GetOption('sListId') }}.indexOf(iItemId), 1);
|
||||
}
|
||||
}
|
||||
if ((oSelectedItems{{ oUIBlock.GetOption('sListId') }}.length === 0 && $(this).closest('.ibo-panel--body').find('[name=selectionMode]').val() === "positive")) {
|
||||
$('#btn_ok_{{ oUIBlock.GetOption('sTableId') }}').prop('disabled', true);
|
||||
} else {
|
||||
$('#btn_ok_{{ oUIBlock.GetOption('sTableId') }}').prop('disabled', false);
|
||||
}
|
||||
// Checking input
|
||||
$('#{{ oUIBlock.GetId() }} tr[role="row"]:not(.selected) td:first-child input').prop('checked', false);
|
||||
// Saving values in temp array
|
||||
if ($(this).closest('.ibo-panel--body').find('[name=selectionMode]').val() === "negative") {
|
||||
for (var i in aData) {
|
||||
var iItemId = aData[i].id;
|
||||
if (oSelectedItems{{ oUIBlock.GetOption('sListId') }}.indexOf(iItemId) === -1) {
|
||||
oSelectedItems{{ oUIBlock.GetOption('sListId') }}.push(iItemId);
|
||||
}
|
||||
}
|
||||
if (oSelectedItems{{ oUIBlock.GetOption('sListId') }}.length === oTable{{ oUIBlock.GetId() }}.page.info()["recordsTotal"]) {
|
||||
$('#btn_ok_{{ oUIBlock.GetOption('sTableId') }}').prop('disabled', true);
|
||||
} else {
|
||||
$('#btn_ok_{{ oUIBlock.GetOption('sTableId') }}').prop('disabled', false);
|
||||
}
|
||||
} else {
|
||||
for (var i in aData) {
|
||||
var iItemId = aData[i].id;
|
||||
if (oSelectedItems{{ oUIBlock.GetOption('sListId') }}.indexOf(iItemId) > -1) {
|
||||
oSelectedItems{{ oUIBlock.GetOption('sListId') }}.splice(oSelectedItems{{ oUIBlock.GetOption('sListId') }}.indexOf(iItemId), 1);
|
||||
}
|
||||
}
|
||||
if (oSelectedItems{{ oUIBlock.GetOption('sListId') }}.length === 0) {
|
||||
$('#btn_ok_{{ oUIBlock.GetOption('sTableId') }}').prop('disabled', true);
|
||||
} else {
|
||||
$('#btn_ok_{{ oUIBlock.GetOption('sTableId') }}').prop('disabled', false);
|
||||
}
|
||||
}
|
||||
});
|
||||
{% else %}
|
||||
oTable{{ oUIBlock.GetId() }}.off('select').on('select', function (oEvent, dt, type, indexes) {
|
||||
var aData = oTable{{ oUIBlock.GetId() }}.rows(indexes).data().toArray();
|
||||
// Checking input
|
||||
$('#{{ oUIBlock.GetId() }} tr[role="row"].selected td:first-child input').prop('checked', true);
|
||||
// Saving values in temp array
|
||||
for (var i in aData) {
|
||||
var iItemId = aData[i].id;
|
||||
if (oSelectedItems{{ oUIBlock.GetOption('sListId') }}.indexOf(iItemId) === -1) {
|
||||
oSelectedItems{{ oUIBlock.GetOption('sListId') }}.push(iItemId);
|
||||
}
|
||||
}
|
||||
if ((oSelectedItems{{ oUIBlock.GetOption('sListId') }}.length === oTable{{ oUIBlock.GetId() }}.page.info()["recordsTotal"] && $(this).closest('.ibo-panel--body').find('[name=selectionMode]').val() === "negative")) {
|
||||
$('#btn_ok_{{ oUIBlock.GetOption('sListId') }}').prop('disabled', true);
|
||||
} else {
|
||||
$('#btn_ok_{{ oUIBlock.GetOption('sListId') }}').prop('disabled', false);
|
||||
}
|
||||
});
|
||||
|
||||
oTable{{ oUIBlock.GetId() }}.off('deselect').on('deselect', function (oEvent, dt, type, indexes) {
|
||||
var aData = oTable{{ oUIBlock.GetId() }}.rows(indexes).data().toArray();
|
||||
|
||||
// Checking input
|
||||
$('#{{ oUIBlock.GetId() }} tr[role="row"]:not(.selected) td:first-child input').prop('checked', false);
|
||||
// Saving values in temp array
|
||||
for (var i in aData) {
|
||||
var iItemId = aData[i].id;
|
||||
if (oSelectedItems{{ oUIBlock.GetOption('sListId') }}.indexOf(iItemId) > -1) {
|
||||
oSelectedItems{{ oUIBlock.GetOption('sListId') }}.splice(oSelectedItems{{ oUIBlock.GetOption('sListId') }}.indexOf(iItemId), 1);
|
||||
}
|
||||
}
|
||||
if ((oSelectedItems{{ oUIBlock.GetOption('sListId') }}.length === 0 && $(this).closest('.ibo-panel--body').find('[name=selectionMode]').val() === "positive")) {
|
||||
$('#btn_ok_{{ oUIBlock.GetOption('sListId') }}').prop('disabled', true);
|
||||
} else {
|
||||
$('#btn_ok_{{ oUIBlock.GetOption('sListId') }}').prop('disabled', false);
|
||||
}
|
||||
});
|
||||
oTable{{ oUIBlock.GetId() }}.off('select').on('select', function (oEvent, dt, type, indexes) {
|
||||
$('#btn_ok_{{ oUIBlock.GetOption('sListId') }}').prop('disabled', false);
|
||||
});
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
// Handles submit button
|
||||
//$('#form_{{ oUIBlock.GetId() }} .form_buttons .form_btn_submit').off('click').on('click', function(oEvent){
|
||||
// Extracting value(s) to be send back to the source form
|
||||
{% if bMultipleSelect %}
|
||||
//var oData = {values: oSelectedItems};
|
||||
{% else %}
|
||||
/*var oData = {value: {}};
|
||||
var sItemId = Object.keys(oSelectedItems)[0];
|
||||
var sItemName = oSelectedItems[sItemId];
|
||||
|
||||
oData.value[sItemId] = sItemName;*/
|
||||
{% endif %}
|
||||
|
||||
// Triggering value setting on the source field
|
||||
//$('[data-form-path="{{ aSource.sFormPath }}"][data-field-id="{{ aSource.sFieldId }}"]').triggerHandler('set_current_value', oData);
|
||||
|
||||
// Closing the modal
|
||||
{% if tIsModal is defined and tIsModal == true %}
|
||||
//$('#{{ sFormId }}').closest('.modal').modal('hide');
|
||||
{% endif %}
|
||||
//});
|
||||
|
||||
$('#datatable_dlg_{{ oUIBlock.GetId() }}').dialog(
|
||||
{
|
||||
autoOpen: false,
|
||||
|
||||
Reference in New Issue
Block a user