Datatables & styles fix

This commit is contained in:
Pablo Aragon 2023-03-30 16:50:30 +02:00
parent a8333801bb
commit 3a2cbb7a62
6 changed files with 328 additions and 285 deletions

View File

@ -764,10 +764,9 @@ html_print_table($userManagementTable);
$vcard_data = []; $vcard_data = [];
$vcard_data['version'] = '3.0'; $vcard_data['version'] = '3.0';
$vcard_data['firstName'] = $user_info['firstname']; $vcard_data['firstName'] = $user_info['fullname'];
$vcard_data['lastName'] = $user_info['lastname']; $vcard_data['lastName'] = '';
$vcard_data['middleName'] = ($user_info['middlename'] === '1') ? '' : $user_info['middlename']; $vcard_data['middleName'] = '';
$vcard_data['nickname'] = $user_info['fullname'];
$vcard_data['workPhone'] = $user_info['phone']; $vcard_data['workPhone'] = $user_info['phone'];
$vcard_data['email'] = $user_info['email']; $vcard_data['email'] = $user_info['email'];
$vcard_data['organization'] = io_safe_output(get_product_name()); $vcard_data['organization'] = io_safe_output(get_product_name());

View File

@ -160,7 +160,7 @@ if ($load_filter_modal) {
true, true,
'', '',
false, false,
'margin-left:5px; width:'.$filter_id_width.';' 'width:'.$filter_id_width.';'
); );
$table->rowclass[] = 'display-grid'; $table->rowclass[] = 'display-grid';
@ -169,8 +169,9 @@ if ($load_filter_modal) {
'load_filter', 'load_filter',
false, false,
[ [
'class' => 'mini w25p', 'class' => 'mini w30p',
'style' => 'margin-left: 73%', 'icon' => 'load',
'style' => 'margin-left: 208px; width: 130px;',
'onclick' => 'load_filter_values();', 'onclick' => 'load_filter_values();',
], ],
true true
@ -189,7 +190,7 @@ function show_filter() {
draggable: true, draggable: true,
modal: false, modal: false,
closeOnEscape: true, closeOnEscape: true,
width: 500 width: 380
}); });
} }
@ -293,8 +294,9 @@ if ($save_filter_modal) {
'save_filter', 'save_filter',
false, false,
[ [
'class' => 'mini w25p', 'class' => 'mini ',
'style' => 'margin-left: 56%', 'icon' => 'save',
'style' => 'margin-left: 175px; width: 125px;',
'onclick' => 'save_new_filter();', 'onclick' => 'save_new_filter();',
], ],
true true
@ -330,8 +332,9 @@ if ($save_filter_modal) {
'update_filter', 'update_filter',
false, false,
[ [
'class' => 'mini w25p', 'class' => 'mini ',
'style' => 'margin-left: 56%', 'icon' => 'save',
'style' => 'margin-left: 155px; width: 145px;',
'onclick' => 'save_update_filter();', 'onclick' => 'save_update_filter();',
], ],
true true

View File

@ -3628,6 +3628,11 @@ function ui_print_datatable(array $parameters)
$parameters['csv'] = 1; $parameters['csv'] = 1;
} }
$dom_elements = '"plfrtiB"';
if (isset($parameters['dom_elements'])) {
$dom_elements = '"'.$parameters['dom_elements'].'"';
}
$filter = ''; $filter = '';
// Datatable filter. // Datatable filter.
if (isset($parameters['form']) && is_array($parameters['form'])) { if (isset($parameters['form']) && is_array($parameters['form'])) {
@ -3790,6 +3795,34 @@ function ui_print_datatable(array $parameters)
} }
$table .= '</tr></thead>'; $table .= '</tr></thead>';
if (isset($parameters['data_element']) === true) {
$table .= '<tbody>';
foreach ($parameters['data_element'] as $row) {
$table .= '<tr>';
foreach ($row as $td_data) {
$table .= '<td>'.$td_data.'</td>';
}
$table .= '</tr>';
}
$table .= '</tbody>';
$js = '<script>
$.fn.dataTable.ext.classes.sPageButton = "pandora_pagination mini-pandora-pagination"
var table = $("#'.$table_id.'").DataTable({
"dom": "'.$parameters['dom_elements'].'"
});
$("div.spinner-fixed").hide();
$("table#'.$table_id.'").removeClass("invisible");
$("#'.$table_id.'_filter > label > input").addClass("mini-search-input");
if (table.page.info().pages == 1) {
$("#'.$table_id.'_paginate").hide();
}
</script>';
}
$table .= '</table>'; $table .= '</table>';
$pagination_class = 'pandora_pagination'; $pagination_class = 'pandora_pagination';
@ -3813,279 +3846,276 @@ function ui_print_datatable(array $parameters)
$export_columns = ',columns: \'th:not(:last-child)\''; $export_columns = ',columns: \'th:not(:last-child)\'';
} }
if (isset($parameters['ajax_url'])) { if (isset($parameters['data_element']) === false) {
$type_data = 'ajax: { if (isset($parameters['ajax_url'])) {
url: "'.ui_get_full_url('ajax.php', false, false, false).'", $type_data = 'ajax: {
type: "POST", url: "'.ui_get_full_url('ajax.php', false, false, false).'",
dataSrc: function (json) { type: "POST",
if($("#'.$form_id.'_search_bt") != undefined) { dataSrc: function (json) {
$("#'.$form_id.'_loading").remove(); if($("#'.$form_id.'_search_bt") != undefined) {
} $("#'.$form_id.'_loading").remove();
}
if (json.error) { if (json.error) {
console.error(json.error); console.error(json.error);
$("#error-'.$table_id.'").html(json.error); $("#error-'.$table_id.'").html(json.error);
$("#error-'.$table_id.'").dialog({ $("#error-'.$table_id.'").dialog({
title: "Filter failed", title: "Filter failed",
width: 630, width: 630,
resizable: true, resizable: true,
draggable: true, draggable: true,
modal: false, modal: false,
closeOnEscape: true, closeOnEscape: true,
buttons: { buttons: {
"Ok" : function () { "Ok" : function () {
$(this).dialog("close"); $(this).dialog("close");
}
} }
} }).parent().addClass("ui-state-error");
}).parent().addClass("ui-state-error"); } else {';
} else {';
if (isset($parameters['ajax_return_operation']) === true if (isset($parameters['ajax_return_operation']) === true
&& empty($parameters['ajax_return_operation']) === false && empty($parameters['ajax_return_operation']) === false
&& isset($parameters['ajax_return_operation_function']) === true && isset($parameters['ajax_return_operation_function']) === true
&& empty($parameters['ajax_return_operation_function']) === false && empty($parameters['ajax_return_operation_function']) === false
) { ) {
$type_data .= ' $type_data .= '
if (json.'.$parameters['ajax_return_operation'].' !== undefined) { if (json.'.$parameters['ajax_return_operation'].' !== undefined) {
'.$parameters['ajax_return_operation_function'].'(json.'.$parameters['ajax_return_operation'].'); '.$parameters['ajax_return_operation_function'].'(json.'.$parameters['ajax_return_operation'].');
} }
'; ';
} }
if (isset($parameters['ajax_postprocess'])) {
$type_data .= '
if (json.data) {
json.data.forEach(function(item) {
'.$parameters['ajax_postprocess'].'
});
} else {
json.data = {};
}';
}
if (isset($parameters['ajax_postprocess'])) {
$type_data .= ' $type_data .= '
if (json.data) { return json.data;
json.data.forEach(function(item) { }
'.$parameters['ajax_postprocess'].' },
data: function (data) {
if($("#button-'.$form_id.'_search_bt") != undefined) {
var loading = \''.html_print_image(
'images/spinner.gif',
true,
[
'id' => $form_id.'_loading',
'class' => 'loading-search-datatables-button',
]
).'\';
$("#button-'.$form_id.'_search_bt").parent().append(loading);
}
inputs = $("#'.$form_id.' :input");
values = {};
inputs.each(function() {
values[this.name] = $(this).val();
})
$.extend(data, {
filter: values,'."\n";
if (is_array($parameters['ajax_data'])) {
foreach ($parameters['ajax_data'] as $k => $v) {
$type_data .= $k.':'.json_encode($v).",\n";
}
}
$type_data .= 'page: "'.$parameters['ajax_url'].'"
}); });
} else {
json.data = {}; return data;
}'; }
},';
} else {
$type_data = 'data: '.json_encode($parameters['data_element']).',';
} }
$type_data .= ' $serverside = 'true';
return json.data; if (isset($parameters['data_element'])) {
} $serverside = 'false';
}, }
data: function (data) {
if($("#button-'.$form_id.'_search_bt") != undefined) {
var loading = \''.html_print_image(
'images/spinner.gif',
true,
[
'id' => $form_id.'_loading',
'class' => 'loading-search-datatables-button',
]
).'\';
$("#button-'.$form_id.'_search_bt").parent().append(loading);
}
inputs = $("#'.$form_id.' :input"); // Javascript controller.
$js = '<script type="text/javascript">
$(document).ready(function(){
$.fn.dataTable.ext.errMode = "none";
$.fn.dataTable.ext.classes.sPageButton = "'.$pagination_class.'";
values = {}; var settings_datatable = {
inputs.each(function() { drawCallback: function(settings) {';
values[this.name] = $(this).val();
})
$.extend(data, { if (!isset($parameters['data_element'])) {
filter: values,'."\n"; $js .= 'if (dt_'.$table_id.'.page.info().pages > 1) {
$("#'.$table_id.'_wrapper > .dataTables_paginate.paging_simple_numbers").show()
} else {
$("#'.$table_id.'_wrapper > .dataTables_paginate.paging_simple_numbers").hide()
}';
}
if (is_array($parameters['ajax_data'])) { $js .= 'if ($("#'.$table_id.' tr td").length == 1) {
foreach ($parameters['ajax_data'] as $k => $v) { $(".datatable-msg-info-'.$table_id.'").show();
$type_data .= $k.':'.json_encode($v).",\n"; $(".datatable-msg-info-'.$table_id.'").removeClass(\'invisible_important\');
$("table#'.$table_id.'").hide();
$("div.dataTables_paginate").hide();
$("div.dataTables_info").hide();
$("div.dataTables_length").hide();
$("div.dt-buttons").hide();
if (dt_'.$table_id.'.page.info().pages > 1) {
$(".dataTables_paginate.paging_simple_numbers").show()
}
} else {
$(".datatable-msg-info-'.$table_id.'").hide();
$("table#'.$table_id.'").show();
$("div.dataTables_paginate").show();
$("div.dataTables_info").show();
$("div.dataTables_length").show();
$("div.dt-buttons").show();
if (dt_'.$table_id.'.page.info().pages == 1) {
$(".dataTables_paginate.paging_simple_numbers").hide()
}
}';
if (isset($parameters['drawCallback'])) {
$js .= $parameters['drawCallback'];
}
$searching = 'false';
if (isset($parameters['searching']) && $parameters['searching'] === true) {
$searching = 'true';
}
$ordering = 'true';
if (isset($parameters['ordering']) && $parameters['ordering'] === false) {
$ordering = 'false';
}
$js .= '},';
$languaje = substr(get_user_language(), 0, 2);
$js .= '
processing: true,
serverSide: '.$serverside.',
paging: '.$parameters['paging'].',
pageLength: '.$parameters['default_pagination'].',
searching: '.$searching.',
responsive: true,
dom: '.$dom_elements.',
language: {
url: "/pandora_console/include/javascript/i18n/dataTables.'.$languaje.'.json",
processing:"'.$processing.'",
zeroRecords:"'.$zeroRecords.'",
emptyTable:"'.$emptyTable.'",
},
buttons: '.$parameters['csv'].'== 1 ? [
{
extend: "csv",
text : "'.__('Export current page to CSV').'",
titleAttr: "'.__('Export current page to CSV').'",
title: "export_'.$parameters['id'].'_current_page_'.date('Y-m-d').'",
fieldSeparator: "'.$config['csv_divider'].'",
action: function ( e, dt, node, config ) {
blockResubmit(node);
// Call the default csvHtml5 action method to create the CSV file
$.fn.dataTable.ext.buttons.csvHtml5.action.call(this, e, dt, node, config);
},
exportOptions : {
modifier : {
// DataTables core
order : "current",
page : "All",
search : "applied"
}'.$export_columns.'
},
}
] : [],
lengthMenu: '.json_encode($pagination_options).',
columnDefs: [
{ className: "no-class", targets: "_all" },
{ bSortable: false, targets: '.$no_sortable_columns.' }
],
ordering: '.$ordering.',
initComplete: function(settings, json) {
// Move elements to table_action_buttons bar.
$(".action_buttons_right_content").html("<div class=\"pagination-child-div\"></div>");
$(".action_buttons_right_content").html("<div class=\"pagination-child-div\"></div>");
$(".action_buttons_right_content").html("<div class=\"pagination-child-div\"></div>");
$(".action_buttons_right_content").html("<div class=\"pagination-child-div\"></div>");
$(".pagination-child-div").append($("#'.$table_id.'_wrapper > .dataTables_paginate.paging_simple_numbers"));
$(".pagination-child-div").append($("#'.$table_id.'_wrapper > .dataTables_length"));
$(".pagination-child-div").append($("#'.$table_id.'_wrapper > .dt-buttons"));
$(".pagination-child-div").append($("#'.$table_id.'_wrapper > .dataTables_filter"));
$("div.spinner-fixed").hide();
},
columns: [';
foreach ($parameters['datacolumns'] as $data) {
if (is_array($data)) {
$js .= '{data : "'.$data['text'].'",className: "'.$data['class'].'"},';
} else {
$js .= '{data : "'.$data.'",className: "no-class"},';
} }
} }
$type_data .= 'page: "'.$parameters['ajax_url'].'" $js .= '
}); ],
order: [[ '.$order.' ]],';
$js .= $type_data;
$js .= '
};
return data; dt_'.$table_id.' = $("#'.$table_id.'").DataTable(settings_datatable);
}
},';
} else {
$type_data = 'data: '.json_encode($parameters['data_element']).',';
}
$serverside = 'true'; $("#button-'.$form_id.'_search_bt").click(function (){
if (isset($parameters['data_element'])) { dt_'.$table_id.'.draw().page(0)
$serverside = 'false'; });
} ';
// Javascript controller. if (isset($parameters['caption']) === true
$js = '<script type="text/javascript"> && empty($parameters['caption']) === false
$(document).ready(function(){ ) {
$.fn.dataTable.ext.errMode = "none"; $js .= '$("#'.$table_id.'").append("<caption>'.$parameters['caption'].'</caption>");';
$.fn.dataTable.ext.classes.sPageButton = "'.$pagination_class.'"; $js .= '$(".datatables_thead_tr").css("height", 0);';
}
var settings_datatable = { if (isset($parameters['csv']) === true) {
drawCallback: function(settings) {'; $js."'$('#".$table_id."').on( 'buttons-processing', function ( e, indicator ) {
if ( indicator ) {
console.log('a');
}
else {
console.log('b');
}";
}
if (!isset($parameters['data_element'])) { $js .= '$("table#'.$table_id.'").removeClass("invisible");
$js .= 'if (dt_'.$table_id.'.page.info().pages > 1) { });';
$("#'.$table_id.'_wrapper > .dataTables_paginate.paging_simple_numbers").show() $js .= '
} else { $(function() {
$("#'.$table_id.'_wrapper > .dataTables_paginate.paging_simple_numbers").hide() $(document).on("preInit.dt", function (ev, settings) {
}';
}
$js .= 'if ($("#'.$table_id.' tr td").length == 1) {
$(".datatable-msg-info-'.$table_id.'").show();
$(".datatable-msg-info-'.$table_id.'").removeClass(\'invisible_important\');
$("table#'.$table_id.'").hide();
$("div.dataTables_paginate").hide();
$("div.dataTables_info").hide();
$("div.dataTables_length").hide(); $("div.dataTables_length").hide();
$("div.dt-buttons").hide(); $("div.dt-buttons").hide();
});
if (dt_'.$table_id.'.page.info().pages > 1) {
$(".dataTables_paginate.paging_simple_numbers").show()
}
} else {
$(".datatable-msg-info-'.$table_id.'").hide();
$("table#'.$table_id.'").show();
$("div.dataTables_paginate").show();
$("div.dataTables_info").show();
$("div.dataTables_length").show();
$("div.dt-buttons").show();
if (dt_'.$table_id.'.page.info().pages == 1) {
$(".dataTables_paginate.paging_simple_numbers").hide()
}
}';
if (isset($parameters['drawCallback'])) {
$js .= $parameters['drawCallback'];
}
$dom_elements = '"plfrtiB"';
if (isset($parameters['dom_elements'])) {
$dom_elements = '"'.$parameters['dom_elements'].'"';
}
$searching = 'false';
if (isset($parameters['searching']) && $parameters['searching'] === true) {
$searching = 'true';
}
$ordering = 'true';
if (isset($parameters['ordering']) && $parameters['ordering'] === false) {
$ordering = 'false';
}
$js .= '},';
$languaje = substr(get_user_language(), 0, 2);
$js .= '
processing: true,
serverSide: '.$serverside.',
paging: '.$parameters['paging'].',
pageLength: '.$parameters['default_pagination'].',
searching: '.$searching.',
responsive: true,
dom: '.$dom_elements.',
language: {
url: "/pandora_console/include/javascript/i18n/dataTables.'.$languaje.'.json",
processing:"'.$processing.'",
zeroRecords:"'.$zeroRecords.'",
emptyTable:"'.$emptyTable.'",
},
buttons: '.$parameters['csv'].'== 1 ? [
{
extend: "csv",
text : "'.__('Export current page to CSV').'",
titleAttr: "'.__('Export current page to CSV').'",
title: "export_'.$parameters['id'].'_current_page_'.date('Y-m-d').'",
fieldSeparator: "'.$config['csv_divider'].'",
action: function ( e, dt, node, config ) {
blockResubmit(node);
// Call the default csvHtml5 action method to create the CSV file
$.fn.dataTable.ext.buttons.csvHtml5.action.call(this, e, dt, node, config);
},
exportOptions : {
modifier : {
// DataTables core
order : "current",
page : "All",
search : "applied"
}'.$export_columns.'
},
}
] : [],
lengthMenu: '.json_encode($pagination_options).',
columnDefs: [
{ className: "no-class", targets: "_all" },
{ bSortable: false, targets: '.$no_sortable_columns.' }
],
ordering: '.$ordering.',
initComplete: function(settings, json) {
// Move elements to table_action_buttons bar.
$(".action_buttons_right_content").html("<div class=\"pagination-child-div\"></div>");
$(".action_buttons_right_content").html("<div class=\"pagination-child-div\"></div>");
$(".action_buttons_right_content").html("<div class=\"pagination-child-div\"></div>");
$(".action_buttons_right_content").html("<div class=\"pagination-child-div\"></div>");
$(".pagination-child-div").append($("#'.$table_id.'_wrapper > .dataTables_paginate.paging_simple_numbers"));
$(".pagination-child-div").append($("#'.$table_id.'_wrapper > .dataTables_length"));
$(".pagination-child-div").append($("#'.$table_id.'_wrapper > .dt-buttons"));
$(".pagination-child-div").append($("#'.$table_id.'_wrapper > .dataTables_filter"));
$("div.spinner-fixed").hide();
},
columns: [';
foreach ($parameters['datacolumns'] as $data) {
if (is_array($data)) {
$js .= '{data : "'.$data['text'].'",className: "'.$data['class'].'"},';
} else {
$js .= '{data : "'.$data.'",className: "no-class"},';
}
}
$js .= '
],
order: [[ '.$order.' ]],';
$js .= $type_data;
$js .= '
};
dt_'.$table_id.' = $("#'.$table_id.'").DataTable(settings_datatable);
$("#button-'.$form_id.'_search_bt").click(function (){
dt_'.$table_id.'.draw().page(0)
}); });
'; ';
if (isset($parameters['caption']) === true $js .= '</script>';
&& empty($parameters['caption']) === false
) {
$js .= '$("#'.$table_id.'").append("<caption>'.$parameters['caption'].'</caption>");';
$js .= '$(".datatables_thead_tr").css("height", 0);';
} }
if (isset($parameters['csv']) === true) {
$js."'$('#".$table_id."').on( 'buttons-processing', function ( e, indicator ) {
if ( indicator ) {
console.log('a');
}
else {
console.log('b');
}";
}
$js .= '$("table#'.$table_id.'").removeClass("invisible");
});';
$js .= '
$(function() {
$(document).on("preInit.dt", function (ev, settings) {
$("div.dataTables_length").hide();
$("div.dt-buttons").hide();
});
});
';
$js .= '</script>';
// Order. // Order.
$info_msg_arr = []; $info_msg_arr = [];
$info_msg_arr['message'] = $emptyTable; $info_msg_arr['message'] = $emptyTable;

View File

@ -453,6 +453,7 @@ class ModulesByStatus extends Widget
1000, 1000,
], ],
], ],
'dom_elements' => 'frtilp',
] ]
); );
} catch (\Exception $e) { } catch (\Exception $e) {

View File

@ -816,10 +816,6 @@ div[id^="auto-os-"] > img {
height: 20px; height: 20px;
} }
.dataTables_paginate {
margin-right: 10px;
}
.w22px { .w22px {
width: 22px; width: 22px;
} }
@ -838,3 +834,13 @@ td.FF-thresholds-pdd {
padding: 0px !important; padding: 0px !important;
padding-left: 13px !important; padding-left: 13px !important;
} }
div.grid-stack-item-content a.pandora_pagination,
a.mini-pandora-pagination {
padding: 7px;
font-size: 9pt;
}
input.mini-search-input {
height: 30px;
}

View File

@ -434,35 +434,39 @@ if ($agent_view_page === true) {
); );
} }
if (((bool) check_acl($config['id_user'], $id_group, 'AW') === true || (bool) check_acl($config['id_user'], $id_group, 'LM') === true)) { if (is_metaconsole() === false) {
if ($agent_view_page === true) { if (((bool) check_acl($config['id_user'], $id_group, 'AW') === true || (bool) check_acl($config['id_user'], $id_group, 'LM') === true)) {
html_print_div( if ($agent_view_page === true) {
[ html_print_div(
'class' => 'action-buttons pdd_b_10px pdd_r_5px w100p', [
'content' => html_print_submit_button( 'class' => 'action-buttons pdd_b_10px pdd_r_5px w100p',
'content' => html_print_submit_button(
__('Validate'),
'alert_validate',
false,
[
'icon' => 'wand',
'mode' => 'secondary mini',
],
true
),
]
);
} else {
html_print_action_buttons(
html_print_submit_button(
__('Validate'), __('Validate'),
'alert_validate', 'alert_validate',
false, false,
[ [ 'icon' => 'wand' ],
'icon' => 'wand',
'mode' => 'secondary mini',
],
true true
), ),
] ['type' => 'form_action']
); );
} else { }
html_print_action_buttons(
html_print_submit_button(
__('Validate'),
'alert_validate',
false,
[ 'icon' => 'wand' ],
true
),
['type' => 'form_action']
);
} }
} else {
html_print_action_buttons('');
} }
$html_content = ob_get_clean(); $html_content = ob_get_clean();