This commit is contained in:
Fred Tempez 2020-03-08 14:56:10 +01:00
parent eabac93f1f
commit b6839bc0ac
4 changed files with 46 additions and 10 deletions

View File

@ -3332,7 +3332,7 @@ class template {
$html .= '<tr>'; $html .= '<tr>';
$i = 0; $i = 0;
foreach($tr as $td) { foreach($tr as $td) {
$html .= '<td class="col' . $cols[$i++] . '">' . $td . '</td>'; $html .= '<td id="pos' . ($i+1) . '" class="col' . $cols[$i++] . '">' . $td . '</td>';
} }
$html .= '</tr>'; $html .= '</tr>';
} }

View File

@ -23,8 +23,8 @@ class gallery extends common {
]; ];
public static $sort = [ public static $sort = [
'asc' => 'Alphabétique naturel', 'SORT_ASC' => 'Alphabétique naturel',
'dsc' => 'Alphabétique naturel inverse', 'SORT_DSC' => 'Alphabétique naturel inverse',
'none' => 'Aucun tri', 'none' => 'Aucun tri',
]; ];
@ -44,8 +44,24 @@ class gallery extends common {
public function config() { public function config() {
// Liste des galeries // Liste des galeries
$galleries = $this->getData(['module', $this->getUrl(0)]); $galleries = $this->getData(['module', $this->getUrl(0)]);
$countGalleries = count($this->getData(['module',$this->getUrl(0)]));
// Tri des éléments de la galerie
/*
echo "<pre>";
if($galleries) {
foreach($galleries as $galleryId => $gallery) {
echo $galleryId;
echo "|";
echo $gallery['config']['order'] ;
echo '<p>';
}
}
echo "</pre>";
*/
if($galleries) { if($galleries) {
ksort($galleries,SORT_NATURAL);
foreach($galleries as $galleryId => $gallery) { foreach($galleries as $galleryId => $gallery) {
// Erreur dossier vide // Erreur dossier vide
if(is_dir($gallery['config']['directory'])) { if(is_dir($gallery['config']['directory'])) {
@ -57,10 +73,18 @@ class gallery extends common {
else { else {
$gallery['config']['directory'] = '<span class="galleryConfigError">' . $gallery['config']['directory'] . ' (dossier introuvable)</span>'; $gallery['config']['directory'] = '<span class="galleryConfigError">' . $gallery['config']['directory'] . ' (dossier introuvable)</span>';
} }
// Ordre des galeries
// Element 0 chaine vide
$galeryOrder = range(1,count($this->getData(['module',$this->getUrl(0)])));
// Met en forme le tableau // Met en forme le tableau
self::$galleries[] = [ self::$galleries[] = [
$gallery['config']['name'], $gallery['config']['name'],
$gallery['config']['directory'], $gallery['config']['directory'],
template::select('galleryConfigOrder', $galeryOrder , [
'selected' => $gallery['config']['order'],
'class' => 'configOrder'
]),
template::button('galleryConfigEdit' . $galleryId , [ template::button('galleryConfigEdit' . $galleryId , [
'href' => helper::baseUrl() . $this->getUrl(0) . '/edit/' . $galleryId . '/' . $_SESSION['csrf'], 'href' => helper::baseUrl() . $this->getUrl(0) . '/edit/' . $galleryId . '/' . $_SESSION['csrf'],
'value' => template::ico('pencil') 'value' => template::ico('pencil')
@ -80,7 +104,8 @@ class gallery extends common {
'config' => [ 'config' => [
'name' => $this->getInput('galleryConfigName'), 'name' => $this->getInput('galleryConfigName'),
'directory' => $this->getInput('galleryConfigDirectory', helper::FILTER_STRING_SHORT, true), 'directory' => $this->getInput('galleryConfigDirectory', helper::FILTER_STRING_SHORT, true),
'sort' => $this->getInput('galleryConfigSort') 'sort' => $this->getInput('galleryConfigSort'),
'order' => count($this->getData(['module',$this->getUrl(0)])) + 1
], ],
'legend' => [] 'legend' => []
]]); ]]);
@ -223,10 +248,10 @@ class gallery extends common {
switch ($this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'config', 'sort'])) { switch ($this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'config', 'sort'])) {
case 'none': case 'none':
break; break;
case 'dsc': case 'SORT_DSC':
krsort(self::$pictures,SORT_NATURAL); krsort(self::$pictures,SORT_NATURAL);
break; break;
case 'asc': case 'SORT_ASC':
default: default:
ksort(self::$pictures,SORT_NATURAL); ksort(self::$pictures,SORT_NATURAL);
break; break;
@ -268,10 +293,10 @@ class gallery extends common {
switch ($this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'config', 'sort'])) { switch ($this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'config', 'sort'])) {
case 'none': case 'none':
break; break;
case 'dsc': case 'SORT_DSC':
krsort(self::$pictures,SORT_NATURAL); krsort(self::$pictures,SORT_NATURAL);
break; break;
case 'asc': case 'SORT_ASC':
default: default:
ksort(self::$pictures,SORT_NATURAL); ksort(self::$pictures,SORT_NATURAL);
break; break;

View File

@ -59,3 +59,14 @@ setInterval(function() {
directoryDOM.on("change", function() { directoryDOM.on("change", function() {
directoryOldDOM.val($(this).val()); directoryOldDOM.val($(this).val());
}); });
/**
* Tri de la galerie
*/
$( document ).ready(function() {
$('tbody > tr').sort(function (a, b) {
return +$('td#pos3', b).text() > +$('td#pos3', a).text();
}).appendTo('tbody');
});

View File

@ -45,7 +45,7 @@
</div> </div>
</div> </div>
<?php if($module::$galleries): ?> <?php if($module::$galleries): ?>
<?php echo template::table([4, 6, 1, 1], $module::$galleries, ['Nom', 'Dossier cible', '', '']); ?> <?php echo template::table([4, 6,1, 1, 1], $module::$galleries, ['Nom', 'Dossier cible', 'Ordre', '', '']); ?>
<?php else: ?> <?php else: ?>
<?php echo template::speech('Aucune galerie.'); ?> <?php echo template::speech('Aucune galerie.'); ?>
<?php endif; ?> <?php endif; ?>