Tri des images WIP

This commit is contained in:
Fred Tempez 2020-04-07 19:08:24 +02:00
parent 1106c74c9f
commit 638606c87a
4 changed files with 127 additions and 41 deletions

View File

@ -546,6 +546,11 @@ class init extends common {
'desertjpg' => 'Un désert', 'desertjpg' => 'Un désert',
'icebergjpg' => 'Un iceberg', 'icebergjpg' => 'Un iceberg',
'meadowjpg' => 'Une prairie' 'meadowjpg' => 'Une prairie'
],
'postion' => [
'desertjpg' => 3,
'icebergjpg' => 1,
'meadowjpg' => 2
] ]
], ],
'espace' => [ 'espace' => [
@ -560,6 +565,11 @@ class init extends common {
'earthjpg' => 'La Terre et la Lune', 'earthjpg' => 'La Terre et la Lune',
'cosmosjpg' => 'Le cosmos', 'cosmosjpg' => 'Le cosmos',
'nebulajpg' => 'Une nébuleuse' 'nebulajpg' => 'Une nébuleuse'
],
'postion' => [
'earthjpg' => 1,
'cosmosjpg' => 3,
'nebulajpg' => 2
] ]
] ]
], ],

View File

@ -19,7 +19,6 @@ class gallery extends common {
'delete' => self::GROUP_MODERATOR, 'delete' => self::GROUP_MODERATOR,
'dirs' => self::GROUP_MODERATOR, 'dirs' => self::GROUP_MODERATOR,
'edit' => self::GROUP_MODERATOR, 'edit' => self::GROUP_MODERATOR,
'filter' => self::GROUP_MODERATOR,
'index' => self::GROUP_VISITOR 'index' => self::GROUP_VISITOR
]; ];
@ -39,12 +38,16 @@ class gallery extends common {
public static $pictures = []; public static $pictures = [];
public static $picturesId = [];
public static $thumbs = []; public static $thumbs = [];
const GALLERY_VERSION = '2.0'; const GALLERY_VERSION = '2.1';
/**
public function filter() { * Tri des galeries
*/
private function sortGallery() {
// Traitement du tri // Traitement du tri
$data = explode('&',($this->getInput('galleryConfigFilterResponse'))); $data = explode('&',($this->getInput('galleryConfigFilterResponse')));
$data = str_replace('galleryTable%5B%5D=','',$data); $data = str_replace('galleryTable%5B%5D=','',$data);
@ -66,6 +69,30 @@ class gallery extends common {
header('Refresh: 0;url='. helper::baseUrl() . $this->getUrl() ); 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 * Configuration
*/ */
@ -114,7 +141,7 @@ class gallery extends common {
if($this->isPost()) { if($this->isPost()) {
if ($this->getInput('galleryConfigFilterResponse')) { if ($this->getInput('galleryConfigFilterResponse')) {
self::filter(); self::sortGallery();
} else { } else {
$galleryId = helper::increment($this->getInput('galleryConfigName', helper::FILTER_ID, true), (array) $this->getData(['module', $this->getUrl(0)])); $galleryId = helper::increment($this->getInput('galleryConfigName', helper::FILTER_ID, true), (array) $this->getData(['module', $this->getUrl(0)]));
// La première image est celle de la couverture de l'album // La première image est celle de la couverture de l'album
@ -230,39 +257,43 @@ class gallery extends common {
else { else {
// Soumission du formulaire // Soumission du formulaire
if($this->isPost()) { if($this->isPost()) {
// Si l'id a changée if ($this->getInput('galleryEditFilterResponse')) {
$galleryId = $this->getInput('galleryEditName', helper::FILTER_ID, true); self::sortPicture();
if($galleryId !== $this->getUrl(2)) { } else {
// Incrémente le nouvel id de la galerie // Si l'id a changée
$galleryId = helper::increment($galleryId, $this->getData(['module', $this->getUrl(0)])); $galleryId = $this->getInput('galleryEditName', helper::FILTER_ID, true);
// Supprime l'ancienne galerie if($galleryId !== $this->getUrl(2)) {
$this->deleteData(['module', $this->getUrl(0), $this->getUrl(2)]); // Incrémente le nouvel id de la galerie
$galleryId = helper::increment($galleryId, $this->getData(['module', $this->getUrl(0)]));
// Supprime l'ancienne galerie
$this->deleteData(['module', $this->getUrl(0), $this->getUrl(2)]);
}
// légendes
$legends = [];
foreach((array) $this->getInput('legend', null) as $file => $legend) {
$file = str_replace('.','',$file);
$legends[$file] = helper::filter($legend, helper::FILTER_STRING_SHORT);
}
// Photo de la page de garde de l'album
$homePicture = array_keys($this->getInput('homePicture', null));
// Sauvegarder
$this->setData(['module', $this->getUrl(0), $galleryId, [
'config' => [
'name' => $this->getInput('galleryEditName', helper::FILTER_STRING_SHORT, true),
'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
],
'legend' => $legends
]]);
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config',
'notification' => 'Modifications enregistrées',
'state' => true
]);
} }
// légendes
$legends = [];
foreach((array) $this->getInput('legend', null) as $file => $legend) {
$file = str_replace('.','',$file);
$legends[$file] = helper::filter($legend, helper::FILTER_STRING_SHORT);
}
// Photo de la page de garde de l'album
$homePicture = array_keys($this->getInput('homePicture', null));
// Sauvegarder
$this->setData(['module', $this->getUrl(0), $galleryId, [
'config' => [
'name' => $this->getInput('galleryEditName', helper::FILTER_STRING_SHORT, true),
'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
],
'legend' => $legends
]]);
// Valeurs en sortie
$this->addOutput([
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config',
'notification' => 'Modifications enregistrées',
'state' => true
]);
} }
// Met en forme le tableau // Met en forme le tableau
$directory = $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'config', 'directory']); $directory = $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'config', 'directory']);
@ -277,6 +308,7 @@ class gallery extends common {
self::THUMBS_WIDTH); self::THUMBS_WIDTH);
} }
self::$pictures[$fileInfos->getFilename()] = [ self::$pictures[$fileInfos->getFilename()] = [
template::ico('sort'),
$fileInfos->getFilename(), $fileInfos->getFilename(),
template::checkbox( 'homePicture[' . $fileInfos->getFilename() . ']', true, '', [ template::checkbox( 'homePicture[' . $fileInfos->getFilename() . ']', true, '', [
'checked' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2),'config', 'homePicture']) === $fileInfos->getFilename() ? true : false, 'checked' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2),'config', 'homePicture']) === $fileInfos->getFilename() ? true : false,
@ -288,8 +320,11 @@ class gallery extends common {
]), ]),
'<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>' '<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();
} }
} }
// Tri des images par ordre alphabétique // Tri des images par ordre alphabétique
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':
@ -306,7 +341,10 @@ class gallery extends common {
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'title' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'config', 'name']), 'title' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'config', 'name']),
'view' => 'edit' 'view' => 'edit',
'vendor' => [
'tablednd'
]
]); ]);
} }
} }

View File

@ -53,4 +53,23 @@ directoryDOM.on("change", function() {
$('.homePicture').click(function(){ $('.homePicture').click(function(){
$('.homePicture').prop('checked', false); $('.homePicture').prop('checked', false);
$(this).prop('checked', true); $(this).prop('checked', true);
}); });
/**
* Tri dynamique de la galerie
*/
$( document ).ready(function() {
$("#galleryTable").tableDnD({
onDrop: function(table, row) {
$("#galleryEditFilterResponse").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,7 +44,26 @@
</div> </div>
</div> </div>
</div> </div>
<?php echo template::formClose(); ?>
<?php echo template::formOpen('galleryEditFilterForm'); ?>
<?php if($module::$pictures): ?> <?php if($module::$pictures): ?>
<?php echo template::table([4, 1, 6, 1], $module::$pictures, ['Image', 'Couverture','Légende','']); ?> <?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',[
'value' => false
]); ?>
<?php else: ?>
<?php echo template::speech('Aucune galerie.'); ?>
<?php endif; ?> <?php endif; ?>
<?php echo template::formClose(); ?> <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
<?php echo $module::GALLERY_VERSION; ?>
</div>