From 2c0f96ee05f7495abf336a7d42200a914467f3da Mon Sep 17 00:00:00 2001 From: Fred Tempez Date: Wed, 1 Apr 2020 13:43:15 +0200 Subject: [PATCH] =?UTF-8?q?Gallery=202.0=20:=20formulaire=20non=20s=C3=A9p?= =?UTF-8?q?ar=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/gallery/gallery.php | 131 ++++++++++------------- module/gallery/view/add/add.css | 21 ---- module/gallery/view/add/add.js.php | 53 --------- module/gallery/view/add/add.php | 48 --------- module/gallery/view/config/config.js.php | 65 +++++++++-- module/gallery/view/config/config.php | 91 +++++++++++----- 6 files changed, 174 insertions(+), 235 deletions(-) delete mode 100644 module/gallery/view/add/add.css delete mode 100644 module/gallery/view/add/add.js.php delete mode 100644 module/gallery/view/add/add.php diff --git a/module/gallery/gallery.php b/module/gallery/gallery.php index 20396f69..7f4e10ab 100644 --- a/module/gallery/gallery.php +++ b/module/gallery/gallery.php @@ -16,11 +16,11 @@ class gallery extends common { public static $actions = [ 'config' => self::GROUP_MODERATOR, - 'add' => self::GROUP_MODERATOR, 'delete' => self::GROUP_MODERATOR, 'dirs' => self::GROUP_MODERATOR, - 'edit' => self::GROUP_MODERATOR, - 'index' => self::GROUP_VISITOR + 'edit' => self::GROUP_MODERATOR, + 'filter' => self::GROUP_MODERATOR, + 'index' => self::GROUP_VISITOR ]; public static $sort = [ @@ -41,30 +41,34 @@ class gallery extends common { const GALLERY_VERSION = '2.0'; + + + public function filter() { + // Traitement du tri + $data = explode('&',($this->getInput('galleryConfigFilterResponse'))); + $data = str_replace('galleryTable%5B%5D=','',$data); + for($i=0;$isetData(['module', $this->getUrl(0), $data[$i], [ + 'config' => [ + 'name' => $this->getData(['module',$this->getUrl(0),$data[$i],'config','name']), + '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 + ], + 'legend' => $this->getData(['module',$this->getUrl(0),$data[$i],'legend']) + ]]); + } + $this->saveData(); + // Valeurs en sortie + // Recharge la page + header('Refresh: 0;url='. helper::baseUrl() . $this->getUrl() ); + } + /** * Configuration */ public function config() { - // Traiement du tri - // Soumission du formulaire - if( $this->isPost() && - $this->getInput('galleryConfigResponse') !== NULL ) { - $data = explode('&',($this->getInput('galleryConfigResponse'))); - $data = str_replace('galleryTable%5B%5D=','',$data); - for($i=0;$isetData(['module', $this->getUrl(0), $data[$i], [ - 'config' => [ - 'name' => $this->getData(['module',$this->getUrl(0),$data[$i],'config','name']), - '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 - ], - 'legend' => $this->getData(['module',$this->getUrl(0),$data[$i],'legend']) - ]]); - } - $this->saveData(); - } // Tri des galeries $g = $this->getData(['module', $this->getUrl(0)]); $p = helper::arrayCollumn(helper::arrayCollumn($g,'config'),'position'); @@ -87,11 +91,8 @@ class gallery extends common { $gallery['config']['directory'] = '' . $gallery['config']['directory'] . ' (dossier introuvable)'; } // Met en forme le tableau - self::$galleries[] = [ - template::button($galleryId, [ - 'value' => template::ico('sort'), - 'class' => 'disabled' - ]), + self::$galleries[] = [ + template::ico('sort'), $gallery['config']['name'], $gallery['config']['directory'], template::button('galleryConfigEdit' . $galleryId , [ @@ -107,7 +108,31 @@ class gallery extends common { // Tableau des id des galleries pour le drag and drop self::$galleriesId[] = $galleryId; } - } + } + // Soumission du formulaire + + if($this->isPost()) { + if ($this->getInput('galleryConfigFilterResponse')) { + self::filter(); + } else { + $galleryId = helper::increment($this->getInput('galleryConfigName', helper::FILTER_ID, true), (array) $this->getData(['module', $this->getUrl(0)])); + $this->setData(['module', $this->getUrl(0), $galleryId, [ + 'config' => [ + 'name' => $this->getInput('galleryConfigName'), + 'directory' => $this->getInput('galleryConfigDirectory', helper::FILTER_STRING_SHORT, true), + 'sort' => $this->getInput('galleryConfigSort'), + 'order' => count($this->getData(['module',$this->getUrl(0)])) + 1 + ], + 'legend' => [] + ]]); + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(), + 'notification' => 'Modifications enregistrées', + 'state' => true + ]); + } + } // Valeurs en sortie $this->addOutput([ 'title' => 'Configuration du module', @@ -118,42 +143,6 @@ class gallery extends common { ]); } - /** - * Ajouter une galerie - * - */ - public function add() { - // Soumission du formulaire - if($this->isPost()) { - $success = false; - if (!empty($this->getInput('galleryAddName')) ) { - $galleryId = helper::increment($this->getInput('galleryAddName', helper::FILTER_ID, true), (array) $this->getData(['module', $this->getUrl(0)])); - $this->setData(['module', $this->getUrl(0), $galleryId, [ - 'config' => [ - 'name' => $this->getInput('galleryAddName',helper::FILTER_STRING_SHORT, true), - 'directory' => $this->getInput('galleryAddDirectory', helper::FILTER_STRING_SHORT, true), - 'sort' => $this->getInput('galleryAddSort'), - 'order' => count($this->getData(['module',$this->getUrl(0)])) + 1 - ], - 'legend' => [] - ]]); - $success = true; - } - // Valeurs en sortie - $this->addOutput([ - 'redirect' => $success ? helper::baseUrl() . $this->getUrl(0) . '/config' : helper::baseUrl() . $this->getUrl(0) . '/add', - 'notification' => $success ? 'Modifications enregistrées' : 'Le nom de la galerie est obligatoire', - 'state' => $success - ]); - } else { - // valeurs en sortie - $this->addOutput([ - 'title' => 'Ajouter une galerie', - 'view' => 'add' - ]); - } - } - /** * Suppression */ @@ -357,16 +346,8 @@ class gallery extends common { } // Liste des galeries - else { - // Tri des galeries - $g = $this->getData(['module', $this->getUrl(0)]); - $p = helper::arrayCollumn(helper::arrayCollumn($g,'config'),'position'); - asort($p,SORT_NUMERIC); - $galleries = []; - foreach ($p as $positionId => $item) { - $galleries [$positionId] = $g[$positionId]; - } - foreach((array) $galleries as $galleryId => $gallery) { + else { + foreach((array) $this->getData(['module', $this->getUrl(0)]) as $galleryId => $gallery) { if(is_dir($gallery['config']['directory'])) { $iterator = new DirectoryIterator($gallery['config']['directory']); foreach($iterator as $fileInfos) { diff --git a/module/gallery/view/add/add.css b/module/gallery/view/add/add.css deleted file mode 100644 index b8d5a798..00000000 --- a/module/gallery/view/add/add.css +++ /dev/null @@ -1,21 +0,0 @@ -/** - * 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 - * @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/ - */ - - -@import url("core/layout/admin.css"); - -.galleryConfigError { - color: #F3674A; - font-weight: bold; -} \ No newline at end of file diff --git a/module/gallery/view/add/add.js.php b/module/gallery/view/add/add.js.php deleted file mode 100644 index 1f0d8235..00000000 --- a/module/gallery/view/add/add.js.php +++ /dev/null @@ -1,53 +0,0 @@ -/** - * 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 - * @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/ - */ - -/** - * Liste des dossiers - */ -var oldResult = []; -var directoryDOM = $("#galleryAddDirectory"); -var directoryOldDOM = $("#galleryAddDirectoryOld"); -function dirs() { - $.ajax({ - type: "POST", - url: "getUrl(0); ?>/dirs", - success: function(result) { - if($(result).not(oldResult).length !== 0 || $(oldResult).not(result).length !== 0) { - directoryDOM.empty(); - for(var i = 0; i < result.length; i++) { - directoryDOM.append(function(i) { - var option = $("