From bf1a3affe4a04b0341a47ee6b2b2c75500bad9d0 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Thu, 1 Feb 2024 14:25:59 +0100 Subject: [PATCH] Add selection boxes feature on objects list page (for LSsearch customActions) --- doc/src/conf/LSobject/LSsearch.md | 11 +++++- src/css/default/base.css | 9 +++++ .../LSaddons.exportSearchResultAsCSV.php | 3 ++ src/includes/js/LSview.js | 21 +++++++++-- src/includes/routes.php | 5 ++- src/templates/default/viewSearch.tpl | 37 +++++++++++++------ 6 files changed, 70 insertions(+), 16 deletions(-) diff --git a/doc/src/conf/LSobject/LSsearch.md b/doc/src/conf/LSobject/LSsearch.md index 14ea3c8b..f82a7ca4 100644 --- a/doc/src/conf/LSobject/LSsearch.md +++ b/doc/src/conf/LSobject/LSsearch.md @@ -70,7 +70,8 @@ $GLOBALS['LSobjects']['[nom du type d'LSobject]']['LSsearch'] = array ( ), 'customActions' => array ( // Configuration des customActions pour les recherches de ce type d'objet - ) + ), + 'showSelectionBoxes' => [boolean], ); ``` @@ -295,6 +296,14 @@ $GLOBALS['LSobjects']['[nom du type d'LSobject]']['LSsearch'] = array ( Tableau associatif contenant les paramètres de configuration des [customActions](#customactions). [Voir la section concernée](#customactions). +- `showSelectionBoxes` + + Booléen permettant de définir si les cases à cocher de sélections des objets doivent être + affichées. Lorsqu'elles sont affichées, l'utilisateur pourra sélectionner un ou plusieurs objets + dans la liste avant de déclencher une [customAction](#customsactions). Dans ce cas, les DNs de ces + objets seront passés à la page d'exécution de la [customAction](#customsactions) via le paramètre + `selected`. + ## Les actions personnalisées (customActions) Cette section décrit la manière de configurer les actions personnalisées exécutables sur les diff --git a/src/css/default/base.css b/src/css/default/base.css index 5665f50d..1f9e6f10 100644 --- a/src/css/default/base.css +++ b/src/css/default/base.css @@ -242,6 +242,15 @@ td.LSobject-list-names { cursor: pointer; } +/* Selection */ +td.LSobject-list-selection, th.LSobject-list-selection { + width: 1em; +} + +.LSobject-list-selection input[type=checkbox] { + border: 1px solid #ccc; +} + /* * Liste des pages */ diff --git a/src/includes/addons/LSaddons.exportSearchResultAsCSV.php b/src/includes/addons/LSaddons.exportSearchResultAsCSV.php index a4145af0..0a543bda 100644 --- a/src/includes/addons/LSaddons.exportSearchResultAsCSV.php +++ b/src/includes/addons/LSaddons.exportSearchResultAsCSV.php @@ -111,8 +111,11 @@ function exportSearchResultAsCSV($LSsearch) { return false; } + $selected = isset($_REQUEST['selected'])?ensureIsArray($_REQUEST['selected']):[]; foreach ($LSsearch -> getSearchEntries() as $e) { + if ($selected && !in_array($e -> dn, $selected)) + continue; $row = array( $e -> displayName, $e -> dn diff --git a/src/includes/js/LSview.js b/src/includes/js/LSview.js index c038780e..b26bf234 100644 --- a/src/includes/js/LSview.js +++ b/src/includes/js/LSview.js @@ -50,6 +50,10 @@ var LSview = new Class({ }, this); this.onWindowResized(); window.addEvent('resize', this.onWindowResized.bind(this)); + + this.listSelectAll = $('LSobject-list-select-all'); + if (this.listSelectAll) + this.listSelectAll.addEvent('click', this.toogleListSelectAll.bind(this)); }, onWindowResized: function() { @@ -127,10 +131,10 @@ var LSview = new Class({ }, onCustomActionBtnClick: function(event,a) { - if (a.hasClass('LScustomActions_noConfirmation')) { - return true; - } Event(event).stop(); + if (a.hasClass('LScustomActions_noConfirmation')) { + return this.executeCustomActionFromA(a); + } if (!this._confirmBoxOpen) { this._confirmBoxOpen = 1; var getName = new RegExp('customAction/([^/]*)'); @@ -157,6 +161,11 @@ var LSview = new Class({ executeCustomActionFromA: function(a) { var validatedURL = new URL(a.href); validatedURL.searchParams.set('valid', '1'); + $$('td.LSobject-list-selection input') + .filter(function(x) {return x.checked}) + .each(function(el, idx) { + validatedURL.searchParams.set(`selected[${idx}]`, el.value); + }) document.location = validatedURL.href; }, @@ -164,6 +173,12 @@ var LSview = new Class({ if (ul.hasClass('LSview-actions-dropdown')) { ul.toggleClass('LSview-actions-dropdown-opened'); } + }, + + toogleListSelectAll: function() { + $$('td.LSobject-list-selection input').each(function(el){ + el.checked = !el.checked; + }, this); } }); diff --git a/src/includes/routes.php b/src/includes/routes.php index 35be006b..169a7382 100644 --- a/src/includes/routes.php +++ b/src/includes/routes.php @@ -529,7 +529,10 @@ function handle_LSobject_search($request) { 'hiddenFields' => $LSsearch -> getHiddenFieldForm(), 'predefinedFilter' => $LSsearch -> getParam('predefinedFilter') )); - + LStemplate :: assign( + 'showSelectionBoxes', + LSconfig :: get("LSobjects.$LSobject.LSsearch.showSelectionBoxes", false, "bool") + ); if (LSsession :: loadLSclass('LSform')) { LSform :: loadDependenciesDisplayView($object, true); diff --git a/src/templates/default/viewSearch.tpl b/src/templates/default/viewSearch.tpl index 1f6c00bc..66118bab 100644 --- a/src/templates/default/viewSearch.tpl +++ b/src/templates/default/viewSearch.tpl @@ -33,6 +33,11 @@ + {if $showSelectionBoxes} + {foreach from=$page.list item=object} - - {if $LSsearch->displaySubDn}{/if} - {if $LSsearch->extraDisplayedColumns} - {foreach from=$LSsearch->visibleExtraDisplayedColumns item=conf key=cid} - - {/foreach} - {/if} - + {/if} + + {if $LSsearch->displaySubDn}{/if} + {if $LSsearch->extraDisplayedColumns} + {foreach from=$LSsearch->visibleExtraDisplayedColumns item=conf key=cid} + {/foreach} - + {/if} + {foreachelse}
+ + + {/if} {if $LSsearch->sort} @@ -85,18 +90,28 @@
{$object->displayName|escape:"htmlall"} {$object->subDn|escape:"htmlall"}{if !isset($conf.escape) || $conf.escape}{$object->$cid|escape:"htmlall"}{else}{$object->$cid}{/if} - {foreach from=$object->actions item=item} - {$item.label|escape:"htmlall"} + {if $showSelectionBoxes} + + + + + {$object->displayName|escape:"htmlall"} + + {$object->subDn|escape:"htmlall"}{if !isset($conf.escape) || $conf.escape}{$object->$cid|escape:"htmlall"}{else}{$object->$cid}{/if} + {foreach from=$object->actions item=item} + {$item.label|escape:"htmlall"} + {/foreach} +