From f42f0745eae2114f2e3a2325800586edb2c46150 Mon Sep 17 00:00:00 2001 From: Fred Tempez Date: Mon, 23 Mar 2020 17:53:43 +0100 Subject: [PATCH] gallery master --- module/gallery/gallery.php | 28 +++++++++++++++++------- module/gallery/view/config/config.js.php | 20 +++++++++++++++++ module/gallery/view/config/config.php | 2 +- module/gallery/view/edit/edit.php | 6 ++--- module/gallery/view/index/index.js.php | 25 +++++++++++++++++++++ module/gallery/view/index/index.php | 2 +- 6 files changed, 70 insertions(+), 13 deletions(-) create mode 100644 module/gallery/view/index/index.js.php diff --git a/module/gallery/gallery.php b/module/gallery/gallery.php index f463f634..bc2844fa 100644 --- a/module/gallery/gallery.php +++ b/module/gallery/gallery.php @@ -23,8 +23,8 @@ class gallery extends common { ]; public static $sort = [ - 'asc' => 'Alphabétique naturel', - 'dsc' => 'Alphabétique naturel inverse', + 'SORT_ASC' => 'Alphabétique naturel', + 'SORT_DSC' => 'Alphabétique naturel inverse', 'none' => 'Aucun tri', ]; @@ -44,8 +44,9 @@ class gallery extends common { public function config() { // Liste des galeries $galleries = $this->getData(['module', $this->getUrl(0)]); + $countGalleries = count($this->getData(['module',$this->getUrl(0)])); + if($galleries) { - ksort($galleries,SORT_NATURAL); foreach($galleries as $galleryId => $gallery) { // Erreur dossier vide if(is_dir($gallery['config']['directory'])) { @@ -57,10 +58,20 @@ class gallery extends common { else { $gallery['config']['directory'] = '' . $gallery['config']['directory'] . ' (dossier introuvable)'; } + // Ordre des galeries + // Element 0 chaine vide + $galeryOrder = range(1,count($this->getData(['module',$this->getUrl(0)]))); // Met en forme le tableau self::$galleries[] = [ $gallery['config']['name'], $gallery['config']['directory'], + $gallery['config']['order'], + /* + template::select('galleryConfigOrder', $galeryOrder , [ + 'selected' => $gallery['config']['order'], + 'class' => 'configOrder' + + ]),*/ template::button('galleryConfigEdit' . $galleryId , [ 'href' => helper::baseUrl() . $this->getUrl(0) . '/edit/' . $galleryId . '/' . $_SESSION['csrf'], 'value' => template::ico('pencil') @@ -80,7 +91,8 @@ class gallery extends common { 'config' => [ 'name' => $this->getInput('galleryConfigName'), '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' => [] ]]); @@ -223,10 +235,10 @@ class gallery extends common { switch ($this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'config', 'sort'])) { case 'none': break; - case 'dsc': + case 'SORT_DSC': krsort(self::$pictures,SORT_NATURAL); break; - case 'asc': + case 'SORT_ASC': default: ksort(self::$pictures,SORT_NATURAL); break; @@ -268,10 +280,10 @@ class gallery extends common { switch ($this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'config', 'sort'])) { case 'none': break; - case 'dsc': + case 'SORT_DSC': krsort(self::$pictures,SORT_NATURAL); break; - case 'asc': + case 'SORT_ASC': default: ksort(self::$pictures,SORT_NATURAL); break; diff --git a/module/gallery/view/config/config.js.php b/module/gallery/view/config/config.js.php index 39e47491..80bef565 100644 --- a/module/gallery/view/config/config.js.php +++ b/module/gallery/view/config/config.js.php @@ -6,6 +6,8 @@ * * @author Rémi Jean * @copyright Copyright (C) 2008-2018, Rémi Jean + * @author Frédéric Tempez + * @copyright Copyright (C) 2018-2020, Frédéric Tempez * @license GNU General Public License, version 3 * @link http://zwiicms.com/ */ @@ -58,4 +60,22 @@ setInterval(function() { */ directoryDOM.on("change", function() { directoryOldDOM.val($(this).val()); +}); + + +/** + * Tri dynamique de la galerie + */ +$( document ).ready(function() { + var $tbody = $('#galleryTable tbody'); + $tbody.find('tr').sort(function (a, b) { + var tda = $(a).find('td.pos3:eq(0)').text(); + var tdb = $(b).find('td.pos3:eq(0)').text(); + // if a < b return 1 + return tda > tdb ? 1 + // else if a > b return -1 + : tda < tdb ? -1 + // else they are equal - return 0 + : 0; + }).appendTo($tbody); }); \ No newline at end of file diff --git a/module/gallery/view/config/config.php b/module/gallery/view/config/config.php index 508b07a0..4f00d51c 100644 --- a/module/gallery/view/config/config.php +++ b/module/gallery/view/config/config.php @@ -45,7 +45,7 @@ - + 'galleryTable']); ?> diff --git a/module/gallery/view/edit/edit.php b/module/gallery/view/edit/edit.php index c088032d..60f7dff4 100644 --- a/module/gallery/view/edit/edit.php +++ b/module/gallery/view/edit/edit.php @@ -17,7 +17,7 @@

Informations générales

-
+
'Nom', 'value' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'config', 'name']) @@ -33,13 +33,13 @@ 'noDirty' => true // Désactivé à cause des modifications en ajax ]); ?>
-
+
$this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'config', 'sort']), 'label' => 'Tri des images', 'help' => 'Les images sont triées par nom de fichier grâce à la méthode naturelle qui donne de meilleurs résultats lorsque les images sont numérotées.' ]); ?> -
+
diff --git a/module/gallery/view/index/index.js.php b/module/gallery/view/index/index.js.php new file mode 100644 index 00000000..17927eda --- /dev/null +++ b/module/gallery/view/index/index.js.php @@ -0,0 +1,25 @@ +/** + * This file is part of Zwii. + * + * For full copyright and license information, please see the LICENSE + * file that was distributed with this source code. + * + * @author Rémi Jean + * @copyright Copyright (C) 2008-2018, Rémi Jean + * @authorFrédéric Tempez + * @copyright Copyright (C) 2018-2020, Frédéric Tempez + * @license GNU General Public License, version 3 + * @link http://zwiicms.com/ + */ + +$( document ).ready(function() { +/* + asc=false; + var sorted=$('.pictureBox').sort(function(a,b){ + return (asc == + ($(a).data('sort') < $(b).data('sort'))) ? 1 : -1; + }); + asc = asc ? false : true; + $('body').html(sorted); + */ +}); \ No newline at end of file diff --git a/module/gallery/view/index/index.php b/module/gallery/view/index/index.php index b2040e8b..a9269e6f 100644 --- a/module/gallery/view/index/index.php +++ b/module/gallery/view/index/index.php @@ -5,7 +5,7 @@
-
+