Tri des images WIP

This commit is contained in:
Fred Tempez 2020-04-08 17:46:29 +02:00
parent 638606c87a
commit 179f27270c
5 changed files with 83 additions and 100 deletions

View File

@ -547,7 +547,7 @@ class init extends common {
'icebergjpg' => 'Un iceberg',
'meadowjpg' => 'Une prairie'
],
'postion' => [
'position' => [
'desertjpg' => 3,
'icebergjpg' => 1,
'meadowjpg' => 2
@ -566,7 +566,7 @@ class init extends common {
'cosmosjpg' => 'Le cosmos',
'nebulajpg' => 'Une nébuleuse'
],
'postion' => [
'position' => [
'earthjpg' => 1,
'cosmosjpg' => 3,
'nebulajpg' => 2

View File

@ -25,7 +25,7 @@ class gallery extends common {
public static $sort = [
'SORT_ASC' => 'Alphabétique ',
'SORT_DSC' => 'Alphabétique inversé',
'none' => 'Aucun tri',
'SORT_HAND' => 'Tri manuel',
];
public static $directories = [];
@ -58,7 +58,7 @@ class gallery extends common {
'directory' => $this->getData(['module',$this->getUrl(0),$data[$i],'config','directory']),
'homePicture' => $this->getData(['module',$this->getUrl(0),$data[$i],'config','homePicture']),
'sort' => $this->getData(['module',$this->getUrl(0),$data[$i],'config','sort']),
'position' => $i + 1
'position' => $i
],
'legend' => $this->getData(['module',$this->getUrl(0),$data[$i],'legend'])
]]);
@ -69,29 +69,6 @@ class gallery extends common {
header('Refresh: 0;url='. helper::baseUrl() . $this->getUrl() );
}
private function sortPicture() {
// Traitement du tri
$data = explode('&',($this->getInput('galleryEditFilterResponse')));
$data = str_replace('galleryTable%5B%5D=','',$data);
for($i=0;$i<count($data);$i++) {
$this->setData(['module', $this->getUrl(0), $data[$i], [
'config' => [
'position' => $this->getData(['module',$this->getUrl(0),$data[$i],'config'])
],
'legend' => $this->getData(['module',$this->getUrl(0),$data[$i],'legend']),
'position' => [
],
]]);
}
$this->saveData();
// Valeurs en sortie
// Recharge la page
header('Refresh: 0;url='. helper::baseUrl() . $this->getUrl() );
}
/**
* Configuration
@ -257,9 +234,14 @@ class gallery extends common {
else {
// Soumission du formulaire
if($this->isPost()) {
if ($this->getInput('galleryEditFilterResponse')) {
self::sortPicture();
if ($this->getInput('galleryEditFormResponse')) {
// Tri des images
$picturesPosition = explode('&',($this->getInput('galleryEditFormResponse')));
$picturesPosition = str_replace('galleryTable%5B%5D=','',$picturesPosition);
$picturesPosition = array_flip($picturesPosition);
} else {
$picturesPosition = $this->getData(['module',$this->getUrl(0),'position']);
}
// Si l'id a changée
$galleryId = $this->getInput('galleryEditName', helper::FILTER_ID, true);
if($galleryId !== $this->getUrl(2)) {
@ -283,22 +265,25 @@ class gallery extends common {
'directory' => $this->getInput('galleryEditDirectory', helper::FILTER_STRING_SHORT, true),
'homePicture' => $homePicture[0],
'sort' => $this->getInput('galleryEditSort'),
'position' => count($this->getData(['module',$this->getUrl(0)])) + 1
'position' => count($this->getData(['module',$this->getUrl(0)]))
],
'legend' => $legends
'legend' => $legends,
'position' => empty($picturesPosition) ? $this->getData(['module', $this->getUrl(0), $this->getUrl(2),'position']) : $picturesPosition
]]);
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config',
//'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config',
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/edit/' . $this->getUrl(2) . '/' . $_SESSION['csrf'],
'notification' => 'Modifications enregistrées',
'state' => true
]);
}
}
// Met en forme le tableau
$directory = $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'config', 'directory']);
if(is_dir($directory)) {
$iterator = new DirectoryIterator($directory);
foreach($iterator as $fileInfos) {
if($fileInfos->isDot() === false AND $fileInfos->isFile() AND @getimagesize($fileInfos->getPathname())) {
// Créer la miniature si manquante
@ -307,35 +292,44 @@ class gallery extends common {
str_replace('source','thumb',$fileInfos->getPath()) . '/' . self::THUMBS_SEPARATOR . strtolower($fileInfos->getFilename()),
self::THUMBS_WIDTH);
}
self::$pictures[$fileInfos->getFilename()] = [
self::$pictures[str_replace('.','',$fileInfos->getFilename())] = [
template::ico('sort'),
$fileInfos->getFilename(),
template::checkbox( 'homePicture[' . $fileInfos->getFilename() . ']', true, '', [
'checked' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2),'config', 'homePicture']) === $fileInfos->getFilename() ? true : false,
'class' => 'homePicture'
]),
template::text('legend[' . $fileInfos->getFilename() . ']', [
'value' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'legend', str_replace('.','',$fileInfos->getFilename())])
]),
'<a href="'. str_replace('source','thumb',$directory) . '/mini_' . $fileInfos->getFilename() .'" rel="data-lity" data-lity=""><img src="'. str_replace('source','thumb',$directory) . '/' . $fileInfos->getFilename() . '"></a>'
];
// Tableau des id des galleries pour le drag and drop
self::$picturesId[] = $fileInfos->getFilename();
self::$picturesId [] = str_replace('.','',$fileInfos->getFilename());
}
}
// Tri des images par ordre alphabétique
switch ($this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'config', 'sort'])) {
case 'none':
case 'SORT_HAND':
$positions = $this->getdata(['module',$this->getUrl(0), $this->getUrl(2),'position']);
if ($positions) {
foreach ($positions as $position => $name) {
$tempPictures [] = self::$pictures[$position];
$tempPicturesId [] = $position;
}
self::$pictures = $tempPictures;
self::$picturesId = $tempPicturesId;
}
break;
case 'SORT_ASC':
ksort(self::$pictures,SORT_NATURAL);
sort(self::$picturesId,SORT_NATURAL);
break;
case 'SORT_DSC':
krsort(self::$pictures,SORT_NATURAL);
rsort(self::$picturesId,SORT_NATURAL);
break;
case 'SORT_ASC':
default:
ksort(self::$pictures,SORT_NATURAL);
break;
}
}
// Valeurs en sortie
@ -371,6 +365,7 @@ class gallery extends common {
foreach($iterator as $fileInfos) {
if($fileInfos->isDot() === false AND $fileInfos->isFile() AND @getimagesize($fileInfos->getPathname())) {
self::$pictures[$directory . '/' . $fileInfos->getFilename()] = $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'legend', str_replace('.','',$fileInfos->getFilename())]);
$picturesSort[$directory . '/' . $fileInfos->getFilename()] = $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'position', str_replace('.','',$fileInfos->getFilename())]);
// Créer la miniature si manquante
if (!file_exists( str_replace('source','thumb',$fileInfos->getPathname()) . '/' . self::THUMBS_SEPARATOR . strtolower($fileInfos->getFilename()))) {
$this->makeThumb($fileInfos->getPathname(),
@ -385,8 +380,15 @@ class gallery extends common {
}
// Tri des images par ordre alphabétique
switch ($this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'config', 'sort'])) {
case 'none':
case 'SORT_HAND':
asort($picturesSort);
if ($picturesSort) {
foreach ($picturesSort as $name => $position) {
$temp[$name] = self::$pictures[$name];
}
self::$pictures = $temp;
break;
}
case 'SORT_DSC':
krsort(self::$pictures,SORT_NATURAL);
break;
@ -402,10 +404,6 @@ class gallery extends common {
$this->addOutput([
'showBarEditButton' => true,
'title' => $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'config', 'name']),
/* Désactivé car SLB est actif pour tout le site
'vendor' => [
'simplelightbox'
],*/
'view' => 'gallery'
]);
}

View File

@ -26,7 +26,7 @@ $( document ).ready(function() {
// Activer le bouton de tri uniquement après un tri
$("#galleryTable").click(function() {
if ($("#galleryConfigFilterResponse").val() != "") {
if ($("#galleryEditFilterResponse").val() != "") {
$(":input[type='submit']").prop('disabled', false);
}
});

View File

@ -61,15 +61,8 @@ $('.homePicture').click(function(){
$( document ).ready(function() {
$("#galleryTable").tableDnD({
onDrop: function(table, row) {
$("#galleryEditFilterResponse").val($.tableDnD.serialize());
$("#galleryEditFormResponse").val($.tableDnD.serialize());
},
serializeRegexp: "[^\_]*$"
});
});
// Activer le bouton de tri uniquement après un tri
$("#galleryTable").click(function() {
if ($("#galleryEditResponse").val() != "") {
$(":input[type='submit']").prop('disabled', false);
}
});

View File

@ -44,24 +44,16 @@
</div>
</div>
</div>
<?php echo template::formClose(); ?>
<?php echo template::formOpen('galleryEditFilterForm'); ?>
<?php if($module::$pictures): ?>
<?php echo template::table([1, 4, 1, 5, 1], $module::$pictures, ['','Image', 'Couverture','Légende',''],['id' => 'galleryTable'], $module::$picturesId ); ?>
<?php echo template::hidden('galleryEditFilterResponse'); ?>
<?php echo template::hidden('galleryEditFilterSubmit',[
<?php echo template::hidden('galleryEditFormResponse'); ?>
<?php echo template::hidden('galleryEditSubmit',[
'value' => false
]); ?>
<?php else: ?>
<?php echo template::speech('Aucune galerie.'); ?>
<?php endif; ?>
<div class="row">
<div class="col2 offset10">
<?php echo template::submit('galleryEditFilterSubmit', [
'value' => 'Trier',
'disabled' => true
]); ?>
</div>
</div>
<?php echo template::formClose(); ?>
<div class="moduleVersion">Version