Add selection boxes feature on objects list page (for LSsearch customActions)

This commit is contained in:
Benjamin Renard 2024-02-01 14:25:59 +01:00
parent 2104187b14
commit bf1a3affe4
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC
6 changed files with 70 additions and 16 deletions

View file

@ -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

View file

@ -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
*/

View file

@ -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

View file

@ -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);
}
});

View file

@ -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);

View file

@ -33,6 +33,11 @@
<table class='LSobject-list'>
<tr class='LSobject-list'>
{if $showSelectionBoxes}
<th class='LSobject-list LSobject-list-selection'>
<input type="checkbox" class="LSobject-list-selection" id="LSobject-list-select-all"/>
</td>
{/if}
<th class='LSobject-list'>
{if $LSsearch->sort}
<a href='object/{$LSsearch->LSobject|escape:"url"}?sortBy=displayName&amp;nocache={$smarty.now}'>
@ -85,18 +90,28 @@
</tr>
{foreach from=$page.list item=object}
<tr class='{cycle values="LSobject-list,LSobject-list LSobject-list-bis"}'>
<td class='LSobject-list LSobject-list-names'><a href='object/{$LSsearch->LSobject|escape:"url"}/{$object->dn|escape:'url'}' class='LSobject-list'>{$object->displayName|escape:"htmlall"}</a> </td>
{if $LSsearch->displaySubDn}<td class='LSobject-list'>{$object->subDn|escape:"htmlall"}</td>{/if}
{if $LSsearch->extraDisplayedColumns}
{foreach from=$LSsearch->visibleExtraDisplayedColumns item=conf key=cid}
<td class='LSobject-list'{if isset($conf.cssStyle) && $conf.cssStyle} style='{$conf.cssStyle|escape:"htmlall"}'{/if}>{if !isset($conf.escape) || $conf.escape}{$object->$cid|escape:"htmlall"}{else}{$object->$cid}{/if}</td>
{/foreach}
{/if}
<td class='LSobject-list LSobject-list-actions'>
{foreach from=$object->actions item=item}
<a href='{$item.url}' class='LSobject-list-actions'><img src='{img name=$item.action}' alt='{$item.label|escape:"htmlall"}' title='{$item.label|escape:"htmlall"}'/></a>
{if $showSelectionBoxes}
<td class='LSobject-list LSobject-list-selection'>
<input type="checkbox" name="selected" value="{$object->dn|escape:'quotes'}"/>
</td>
{/if}
<td class='LSobject-list LSobject-list-names'>
<a href='object/{$LSsearch->LSobject|escape:"url"}/{$object->dn|escape:'url'}'
class='LSobject-list'>
{$object->displayName|escape:"htmlall"}
</a>
</td>
{if $LSsearch->displaySubDn}<td class='LSobject-list'>{$object->subDn|escape:"htmlall"}</td>{/if}
{if $LSsearch->extraDisplayedColumns}
{foreach from=$LSsearch->visibleExtraDisplayedColumns item=conf key=cid}
<td class='LSobject-list'{if isset($conf.cssStyle) && $conf.cssStyle} style='{$conf.cssStyle|escape:"htmlall"}'{/if}>{if !isset($conf.escape) || $conf.escape}{$object->$cid|escape:"htmlall"}{else}{$object->$cid}{/if}</td>
{/foreach}
</td>
{/if}
<td class='LSobject-list LSobject-list-actions'>
{foreach from=$object->actions item=item}
<a href='{$item.url}' class='LSobject-list-actions'><img src='{img name=$item.action}' alt='{$item.label|escape:"htmlall"}' title='{$item.label|escape:"htmlall"}'/></a>
{/foreach}
</td>
</tr>
{foreachelse}
<tr class='LSobject-list'>