From 638606c87a6baab4f1141f01fe6417b3698ddb62 Mon Sep 17 00:00:00 2001 From: Fred Tempez Date: Tue, 7 Apr 2020 19:08:24 +0200 Subject: [PATCH] Tri des images WIP --- core/module/install/ressource/defaultdata.php | 10 ++ module/gallery/gallery.php | 114 ++++++++++++------ module/gallery/view/edit/edit.js.php | 21 +++- module/gallery/view/edit/edit.php | 23 +++- 4 files changed, 127 insertions(+), 41 deletions(-) diff --git a/core/module/install/ressource/defaultdata.php b/core/module/install/ressource/defaultdata.php index f0ea4c07..9b85e8de 100644 --- a/core/module/install/ressource/defaultdata.php +++ b/core/module/install/ressource/defaultdata.php @@ -546,6 +546,11 @@ class init extends common { 'desertjpg' => 'Un désert', 'icebergjpg' => 'Un iceberg', 'meadowjpg' => 'Une prairie' + ], + 'postion' => [ + 'desertjpg' => 3, + 'icebergjpg' => 1, + 'meadowjpg' => 2 ] ], 'espace' => [ @@ -560,6 +565,11 @@ class init extends common { 'earthjpg' => 'La Terre et la Lune', 'cosmosjpg' => 'Le cosmos', 'nebulajpg' => 'Une nébuleuse' + ], + 'postion' => [ + 'earthjpg' => 1, + 'cosmosjpg' => 3, + 'nebulajpg' => 2 ] ] ], diff --git a/module/gallery/gallery.php b/module/gallery/gallery.php index 98677caf..6ca4eeed 100644 --- a/module/gallery/gallery.php +++ b/module/gallery/gallery.php @@ -19,7 +19,6 @@ class gallery extends common { 'delete' => self::GROUP_MODERATOR, 'dirs' => self::GROUP_MODERATOR, 'edit' => self::GROUP_MODERATOR, - 'filter' => self::GROUP_MODERATOR, 'index' => self::GROUP_VISITOR ]; @@ -39,12 +38,16 @@ class gallery extends common { public static $pictures = []; + public static $picturesId = []; + 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 $data = explode('&',($this->getInput('galleryConfigFilterResponse'))); $data = str_replace('galleryTable%5B%5D=','',$data); @@ -66,6 +69,30 @@ 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;$isetData(['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 */ @@ -114,7 +141,7 @@ class gallery extends common { if($this->isPost()) { if ($this->getInput('galleryConfigFilterResponse')) { - self::filter(); + self::sortGallery(); } else { $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 @@ -230,39 +257,43 @@ class gallery extends common { else { // Soumission du formulaire if($this->isPost()) { - // Si l'id a changée - $galleryId = $this->getInput('galleryEditName', helper::FILTER_ID, true); - if($galleryId !== $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)]); + if ($this->getInput('galleryEditFilterResponse')) { + self::sortPicture(); + } else { + // Si l'id a changée + $galleryId = $this->getInput('galleryEditName', helper::FILTER_ID, true); + if($galleryId !== $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 $directory = $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'config', 'directory']); @@ -277,6 +308,7 @@ class gallery extends common { self::THUMBS_WIDTH); } self::$pictures[$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, @@ -288,8 +320,11 @@ class gallery extends common { ]), '' ]; + // Tableau des id des galleries pour le drag and drop + self::$picturesId[] = $fileInfos->getFilename(); } } + // Tri des images par ordre alphabétique switch ($this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'config', 'sort'])) { case 'none': @@ -306,7 +341,10 @@ class gallery extends common { // Valeurs en sortie $this->addOutput([ 'title' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'config', 'name']), - 'view' => 'edit' + 'view' => 'edit', + 'vendor' => [ + 'tablednd' + ] ]); } } diff --git a/module/gallery/view/edit/edit.js.php b/module/gallery/view/edit/edit.js.php index 63252061..4b6d6f35 100644 --- a/module/gallery/view/edit/edit.js.php +++ b/module/gallery/view/edit/edit.js.php @@ -53,4 +53,23 @@ directoryDOM.on("change", function() { $('.homePicture').click(function(){ $('.homePicture').prop('checked', false); $(this).prop('checked', true); -}); \ No newline at end of file +}); + +/** + * 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); + } +}); diff --git a/module/gallery/view/edit/edit.php b/module/gallery/view/edit/edit.php index 36752866..ce8b484e 100644 --- a/module/gallery/view/edit/edit.php +++ b/module/gallery/view/edit/edit.php @@ -44,7 +44,26 @@ + + - + 'galleryTable'], $module::$picturesId ); ?> + + false + ]); ?> + + - \ No newline at end of file +
+
+ 'Trier', + 'disabled' => true + ]); ?> +
+
+ +
Version n° + +