Skip to content

Commit

Permalink
Restore print buttons (#183)
Browse files Browse the repository at this point in the history
* Start using the new layout option of datatables

* Manage specific -1 value in datatables_page_length_choices

* Use datatables_page_length_default option

* Add missing datatables buttons scripts

* Add auto_print

* Typo

* Add options to display print buttons
  • Loading branch information
coudot authored Nov 19, 2024
1 parent 5d38e70 commit 8dfcbc3
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 30 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
"cp vendor/datatables.net/datatables.net-bs5/css/dataTables.bootstrap5.min.css htdocs/vendor/datatables/",
"cp vendor/datatables.net/datatables.net-bs5/js/dataTables.bootstrap5.min.js htdocs/vendor/datatables/",
"cp vendor/datatables.net/datatables.net-buttons/js/dataTables.buttons.min.js htdocs/vendor/datatables/",
"cp vendor/datatables.net/datatables.net-buttons/js/buttons.colVis.min.js htdocs/vendor/datatables/",
"cp vendor/datatables.net/datatables.net-buttons/js/buttons.html5.min.js htdocs/vendor/datatables/",
"cp vendor/datatables.net/datatables.net-buttons/js/buttons.print.min.js htdocs/vendor/datatables/",
"cp vendor/datatables.net/datatables.net-buttons-bs5/css/buttons.bootstrap5.min.css htdocs/vendor/datatables/",
"cp vendor/datatables.net/datatables.net-buttons-bs5/js/buttons.bootstrap5.min.js htdocs/vendor/datatables/",
"rm -rf vendor/datatables.net",
Expand Down
2 changes: 2 additions & 0 deletions conf/config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@

$datatables_page_length_choices = array(10, 25, 50, 100, -1);
$datatables_page_length_default = 10;
$datatables_print_all = true;
$datatables_print_page = true;
$datatables_auto_print = true;

$display_items = array('identifier', 'firstname', 'lastname', 'title', 'businesscategory', 'employeenumber', 'employeetype', 'mail', 'mailquota', 'phone', 'mobile', 'fax', 'postaladdress', 'street', 'postalcode', 'l', 'state', 'organizationalunit', 'organization', 'manager', 'secretary' );
Expand Down
20 changes: 18 additions & 2 deletions docs/search-parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Configure items shown when displaying results:
Datatables
----------

Pagination
~~~~~~~~~~

Define pagination values in dropdown:

.. code-block:: php
Expand All @@ -40,9 +43,22 @@ Set default pagination for results (can also be used to force the length without
$datatables_page_length_default = 10;
Enable or disable autoPrint feature:
Print
~~~~~
Show "print all" button:

.. code-block:: php
$datatables_auto_print = true;
$datatables_print_all = true;
Show "print page" button:

.. code-block:: php
$datatables_print_page = true;
Enable autoPrint feature (will launch print dialog directly when cliking on print buttons):

.. code-block:: php
$datatables_auto_print = true;
9 changes: 8 additions & 1 deletion htdocs/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,16 @@ function sha256($string)
$smarty->assign('custom_css',$custom_css);
$smarty->assign('attributes_map',$attributes_map);
$smarty->assign('date_specifiers',$date_specifiers);
if (is_array($datatables_page_length_choices)) $datatables_page_length_choices = implode(', ', $datatables_page_length_choices);
if (is_array($datatables_page_length_choices)) {
if ( $all = array_search('-1', $datatables_page_length_choices)) {
$datatables_page_length_choices[$all] = '{"value":"-1","label":"'.$messages["pager_all"].'"}';
}
$datatables_page_length_choices = implode(', ', $datatables_page_length_choices);
}
$smarty->assign('datatables_page_length_choices', $datatables_page_length_choices);
$smarty->assign('datatables_page_length_default', $datatables_page_length_default);
$smarty->assign('datatables_print_all', $datatables_print_all);
$smarty->assign('datatables_print_page', $datatables_print_page);
$smarty->assign('datatables_auto_print', $datatables_auto_print);
$smarty->assign('version',$version);
$smarty->assign('display_footer',$display_footer);
Expand Down
50 changes: 23 additions & 27 deletions templates/footer.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<script src="vendor/datatables/dataTables.min.js"></script>
<script src="vendor/datatables/dataTables.bootstrap5.min.js"></script>
<script src="vendor/datatables/dataTables.buttons.min.js"></script>
<script src="vendor/datatables/buttons.colVis.min.js"></script>
<script src="vendor/datatables/buttons.html5.min.js"></script>
<script src="vendor/datatables/buttons.print.min.js"></script>
<script src="vendor/datatables/buttons.bootstrap5.min.js"></script>
<script src="js/service-desk.js"></script>
<script src="js/ppolicy.js"></script>
Expand All @@ -21,39 +24,32 @@
{/literal}
{literal}
var itemlist = $('table.dataTable').DataTable({
"stateSave": true,
"searching": true,
"paging": true,
"info": true,
"processing": true,
layout: {
topStart: {
{/literal}
{if $datatables_page_length_choices}
"lengthMenu": [
[ {$datatables_page_length_choices} ],
[ {$datatables_page_length_choices|replace:'-1':($msg_pager_all|string_format:'"%s"') nofilter} ]
],
pageLength: {
menu: [ {$datatables_page_length_choices nofilter} ]
}
{/if}
},
bottom2Start: {
buttons: [
{if $datatables_print_all}
{ extend: 'print', text: '{$msg_print_all}', autoPrint: {if $datatables_auto_print}true{else}false{/if} },
{/if}
{if $datatables_print_page}
{ extend: 'print', text: '{$msg_print_page}', exportOptions: { modifier: { page: 'current' } }, autoPrint: {if $datatables_auto_print}true{else}false{/if} },
{/if}
]
}
},
{if $datatables_page_length_default}
"pageLength": {$datatables_page_length_default},
pageLength: {$datatables_page_length_default},
{/if}
{literal}
"dom":
"<'row ft-head'<'col-sm-3'{/literal}{if $datatables_page_length_choices}l{/if}{literal}><'col-sm-3'f><'col-sm-6'p>>" +
"<'row dt-main'<'col-sm-12'tr>>" +
"<'row dt-foot'<'col-sm-6'i><'col-sm-6'p>>" +
"<'row dt-foot'<'col-sm-12'B>>",
/* "buttons": [
{ extend: 'print', autoPrint: {/literal}{if $datatables_auto_print}true{else}false{/if}{literal}, text: "{/literal}<i class=\"fa fa-print\"></i> {$msg_print_all}{literal}", className: "btn-info" },
{ extend: 'print', autoPrint: {/literal}{if $datatables_auto_print}true{else}false{/if}{literal}, exportOptions: {modifier:{page: 'current'}}, text: "{/literal}<i class=\"fa fa-print\"></i> {$msg_print_page}{literal}", className: "btn-info" },
],*/
"order": [
[ {/literal}{if is_int($listing_sortby)}{$listing_sortby}{else}1{/if}{literal}, "asc" ]
],
"aoColumnDefs": [
{ "bSortable": false, "aTargets": ['nosort'] },
],
"language": {
"url": "vendor/datatables/i18n/{/literal}{$lang|default:'en'}{literal}.json"
language: {
url: "vendor/datatables/i18n/{/literal}{$lang|default:'en'}{literal}.json"
}
});
{/literal}
Expand Down

0 comments on commit 8dfcbc3

Please sign in to comment.