Skip to content

Extension de la syntaxe des boucles avec une partie avant/apres non conditionnelle

cerdic a demandé de fusionner gh-3abd0771/57/unknown/refs/pull/57/head vers master

Pour la nouvelle syntaxe voir le commentaire de commit de 03b9e260

L'interet majeur est quand on fait des squelettes de vue tableau, avec des filtres dans la partie en-tete, qui permettent d'afficher plus ou moins de resultat.

Si on coche un filtre qui amene a n'avoir aucun resultat, on veut quand meme que cet entete s'affiche pour que l'utilisateur puisse decocher des filtres.

Actuellement il faut dupliquer tout le code de la partie conditionnelle avant dans la partie alternative, ce qui n'est pas tres pratique.

Exemple de cas pratique : En spip 3.2 :

[(#SET{defaut_tri,#ARRAY{
	date_modif,-1,
	titre,1,
	statut,1,
	id_document,1,
	points,-1
}})]
<B_liste_documents>
	[(#ENV{big_title}|oui)
	<div class="row">
		<div class="col-lg-5">
			[<h1 class="caption">(#ENV*{titre,#GRAND_TOTAL|singulier_ou_pluriel{document:info_1_document,document:info_nb_documents}|sinon{<:document:info_aucun_document:>}})</h1>]
		</div>
		<div class="col-lg-7">
			[<div class="pagination">(#PAGINATION{page_precedent_suivant})</div>]
		</div>
	</div>]
<div class="liste-objets documents">
<table class="spip liste">
	[(#ENV{big_title}|non)
	[<caption>
	[<div class="pagination pull-right">(#PAGINATION{page_precedent_suivant})</div>]
	<strong class="h2 caption">(#ENV*{titre,#GRAND_TOTAL|singulier_ou_pluriel{document:info_1_document,document:info_nb_documents}|sinon{<:document:info_aucun_document:>}})</strong></caption>]
	]
	<thead>
		<tr class="first_row">
			<th class="picto" scope="col"></th>
			<th class="statut" scope="col">[(#TRI{statut,<:info_statut:>,ajax})]</th>
			<th class="titre" scope="col">[(#TRI{titre,<:document:champ_titre_label:>,ajax})]</th>
			<th class="descriptif" scope="col">[(#TRI{descriptif,<:document:champ_descriptif_label:>,ajax})]</th>
			<th class="date" scope="col">[(#TRI{date,<:info_date:>,ajax})]</th>
			<th class="id" scope="col">[(#TRI{id_document,<:info_numero_abbreviation:>,ajax})]</th>
		</tr>
		<tr class="filter_row bg-secondary">
			<td class="picto"></td>
			<td class="statut">#FORM_FILTER_LIST{statut,#ARRAY{prepa,#VAL{prepa}|statut_titre{document},publie,#VAL{publie}|statut_titre{document},poubelle,#VAL{poubelle}|statut_titre{document}}}</td>
			<td class="titre">#FORM_FILTER_LIST{titre}</td>
			<td class="descriptif">#FORM_FILTER_LIST{descriptif}</td>
			<td class="date">#FORM_FILTER_LIST{date}</td>
			<td class="id"></td>
		</tr>
	</thead>
	<tbody>
	<BOUCLE_liste_documents(DOCUMENTS)
		{id_?}
		{statut?}
	  {where?}
		{form_filter_list}
		{tri #ENV{par,num titre},#GET{defaut_tri}}{!par date}{pagination #ENV{nb,50}}>
		<tr class="[(#COMPTEUR_BOUCLE|alterner{row_odd,row_even})][ statut-(#STATUT)]">
			<td class="picto">#FA_ICON{file-alt,icon-primary}</td>
			<td class="statut">[(#STATUT|statut_titre{document})]</td>
			<td class="titre principale"><a href="[(#ID_DOCUMENT|generer_url_objet{document})]" title="<:info_numero_abbreviation|attribut_html:> #ID_DOCUMENT">[(#RANG). ]#TITRE</a></td>
			<td class="descriptif">[(#DESCRIPTIF)]</td>
			<td class="date">[(#DATE|intval|?{#DATE|affdate{d/m/Y}})]</td>
			<td class="id">[(#AUTORISER{modifier,document,#ID_DOCUMENT}|?{
				<a href="[(#ID_DOCUMENT|generer_url_objet{document,edit})]">[(#FA_ICON{edit,icon-primary,<:document:icone_modifier_document:>})]</a>,
				<tt>#ID_DOCUMENT</tt>
			})]</td>
		</tr>
	</BOUCLE_liste_documents>
	</tbody>
</table>
	[<div class="pagination">(#PAGINATION{page_precedent_suivant})</div>]
</div>
</B_liste_documents>
[(#ENV{big_title}|oui)
<div class="row">
	<div class="col-lg-5">
		[<h1 class="caption">(#ENV*{titre,#GRAND_TOTAL|singulier_ou_pluriel{document:info_1_document,document:info_nb_documents}|sinon{<:document:info_aucun_document:>}})</h1>]
	</div>
	<div class="col-lg-7">
		[<div class="pagination">(#PAGINATION{page_precedent_suivant})</div>]
	</div>
</div>]
<div class="liste-objets documents">
<table class="spip liste">
	[(#ENV{big_title}|non)
	[<caption>
	[<div class="pagination pull-right">(#PAGINATION{page_precedent_suivant})</div>]
	<strong class="h2 caption">(#ENV*{titre,#GRAND_TOTAL|singulier_ou_pluriel{document:info_1_document,document:info_nb_documents}|sinon{<:document:info_aucun_document:>}})</strong></caption>]
	]
	<thead>
		<tr class="first_row">
			<th class="picto" scope="col"></th>
			<th class="statut" scope="col">[(#TRI{statut,<:info_statut:>,ajax})]</th>
			<th class="titre" scope="col">[(#TRI{titre,<:document:champ_titre_label:>,ajax})]</th>
			<th class="descriptif" scope="col">[(#TRI{descriptif,<:document:champ_descriptif_label:>,ajax})]</th>
			<th class="date" scope="col">[(#TRI{date,<:info_date:>,ajax})]</th>
			<th class="id" scope="col">[(#TRI{id_document,<:info_numero_abbreviation:>,ajax})]</th>
		</tr>
		<tr class="filter_row bg-secondary">
			<td class="picto"></td>
			<td class="statut">#FORM_FILTER_LIST{statut,#ARRAY{prepa,#VAL{prepa}|statut_titre{document},publie,#VAL{publie}|statut_titre{document},poubelle,#VAL{poubelle}|statut_titre{document}}}</td>
			<td class="titre">#FORM_FILTER_LIST{titre}</td>
			<td class="descriptif">#FORM_FILTER_LIST{descriptif}</td>
			<td class="date">#FORM_FILTER_LIST{date}</td>
			<td class="id"></td>
		</tr>
	</thead>
	<tfoot>
		<tr>
			<td colspan="6" class="p-0"><div class="alert alert-warning center">[<strong>(#ENV*{sinon,<:document:info_aucun_document:>})</strong>]</div></td>
		</tr>
	</tfoot>
</table>
</div>
<//B_liste_documents>

Avec la nouvelle syntaxe (j'utilise uniquement la partie header ici) :

[(#SET{defaut_tri,#ARRAY{
	date_modif,-1,
	titre,1,
	statut,1,
	id_document,1,
	points,-1
}})]
<BB_liste_documents>
	[(#ENV{big_title}|oui)
	<div class="row">
		<div class="col-lg-5">
			[<h1 class="caption">(#ENV*{titre,#GRAND_TOTAL|singulier_ou_pluriel{document:info_1_document,document:info_nb_documents}|sinon{<:document:info_aucun_document:>}})</h1>]
		</div>
		<div class="col-lg-7">
			[<div class="pagination">(#PAGINATION{page_precedent_suivant})</div>]
		</div>
	</div>]
<div class="liste-objets documents">
<table class="spip liste">
	[(#ENV{big_title}|non)
	[<caption>
	[<div class="pagination pull-right">(#PAGINATION{page_precedent_suivant})</div>]
	<strong class="h2 caption">(#ENV*{titre,#GRAND_TOTAL|singulier_ou_pluriel{document:info_1_document,document:info_nb_documents}|sinon{<:document:info_aucun_document:>}})</strong></caption>]
	]
	<thead>
		<tr class="first_row">
			<th class="picto" scope="col"></th>
			<th class="statut" scope="col">[(#TRI{statut,<:info_statut:>,ajax})]</th>
			<th class="titre" scope="col">[(#TRI{titre,<:document:champ_titre_label:>,ajax})]</th>
			<th class="descriptif" scope="col">[(#TRI{descriptif,<:document:champ_descriptif_label:>,ajax})]</th>
			<th class="date" scope="col">[(#TRI{date,<:info_date:>,ajax})]</th>
			<th class="id" scope="col">[(#TRI{id_document,<:info_numero_abbreviation:>,ajax})]</th>
		</tr>
		<tr class="filter_row bg-secondary">
			<td class="picto"></td>
			<td class="statut">#FORM_FILTER_LIST{statut,#ARRAY{prepa,#VAL{prepa}|statut_titre{document},publie,#VAL{publie}|statut_titre{document},poubelle,#VAL{poubelle}|statut_titre{document}}}</td>
			<td class="titre">#FORM_FILTER_LIST{titre}</td>
			<td class="descriptif">#FORM_FILTER_LIST{descriptif}</td>
			<td class="date">#FORM_FILTER_LIST{date}</td>
			<td class="id"></td>
		</tr>
	</thead>
	<tbody>
	<BOUCLE_liste_documents(DOCUMENTS)
		{id_?}
		{statut?}
	  {where?}
		{form_filter_list}
		{tri #ENV{par,num titre},#GET{defaut_tri}}{!par date}{pagination #ENV{nb,50}}>
		<tr class="[(#COMPTEUR_BOUCLE|alterner{row_odd,row_even})][ statut-(#STATUT)]">
			<td class="picto">#FA_ICON{file-alt,icon-primary}</td>
			<td class="statut">[(#STATUT|statut_titre{document})]</td>
			<td class="titre principale"><a href="[(#ID_DOCUMENT|generer_url_objet{document})]" title="<:info_numero_abbreviation|attribut_html:> #ID_DOCUMENT">[(#RANG). ]#TITRE</a></td>
			<td class="descriptif">[(#DESCRIPTIF)]</td>
			<td class="date">[(#DATE|intval|?{#DATE|affdate{d/m/Y}})]</td>
			<td class="id">[(#AUTORISER{modifier,document,#ID_DOCUMENT}|?{
				<a href="[(#ID_DOCUMENT|generer_url_objet{document,edit})]">[(#FA_ICON{edit,icon-primary,<:document:icone_modifier_document:>})]</a>,
				<tt>#ID_DOCUMENT</tt>
			})]</td>
		</tr>
	</BOUCLE_liste_documents>
	</tbody>
</table>
	[<div class="pagination">(#PAGINATION{page_precedent_suivant})</div>]
</div>
</B_liste_documents>
	</tbody>
	<tfoot>
		<tr>
			<td colspan="6" class="p-0"><div class="alert alert-warning center">[<strong>(#ENV*{sinon,<:document:info_aucun_document:>})</strong>]</div></td>
		</tr>
	</tfoot>
</table>
</div>
<//B_liste_documents>

Modification effectuée par JamesRezo

Rapports de requête de fusion