diff --git a/core/core.php b/core/core.php index 006f566d..0c443de4 100644 --- a/core/core.php +++ b/core/core.php @@ -3312,7 +3312,7 @@ class template { * @param array $attributes Attributs ($key => $value) * @return string */ - public static function table(array $cols = [], array $body = [], array $head = [], array $attributes = []) { + public static function table(array $cols = [], array $body = [], array $head = [], array $attributes = [], array $rowsId = []) { // Attributs par défaut $attributes = array_merge([ 'class' => '', @@ -3337,9 +3337,11 @@ class template { $html .= ''; } // Début contenu - $j = 1; - foreach($body as $tr) { - $html .= ''; + $j = 0; + foreach($body as $tr) { + // Id de ligne pour les tableaux drag and drop + $html .= ''; + $j++; $i = 0; foreach($tr as $td) { $html .= '' . $td . ''; diff --git a/module/gallery/gallery.php b/module/gallery/gallery.php index 73f5b913..699166c7 100644 --- a/module/gallery/gallery.php +++ b/module/gallery/gallery.php @@ -16,7 +16,7 @@ class gallery extends common { public static $actions = [ 'config' => self::GROUP_MODERATOR, - 'filter' =>self::GROUP_MODERATOR, + 'add' => self::GROUP_MODERATOR, 'delete' => self::GROUP_MODERATOR, 'dirs' => self::GROUP_MODERATOR, 'edit' => self::GROUP_MODERATOR, @@ -35,16 +35,45 @@ class gallery extends common { public static $galleries = []; + public static $galleriesId = []; + public static $pictures = []; - const GALLERY_VERSION = '1.3'; + const GALLERY_VERSION = '2.0'; /** * Configuration */ public function config() { - // Liste des galeries - $galleries = $this->getData(['module', $this->getUrl(0)]); + // 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'); + asort($p,SORT_NUMERIC); + $galleries = []; + foreach ($p as $positionId => $item) { + $galleries [$positionId] = $g[$positionId]; + } + // Traitement de l'affichage if($galleries) { foreach($galleries as $galleryId => $gallery) { // Erreur dossier vide @@ -58,7 +87,11 @@ class gallery extends common { $gallery['config']['directory'] = '' . $gallery['config']['directory'] . ' (dossier introuvable)'; } // Met en forme le tableau - self::$galleries[] = [ + self::$galleries[] = [ + template::button($galleryId, [ + 'value' => template::ico('sort'), + 'class' => 'disabled' + ]), $gallery['config']['name'], $gallery['config']['directory'], template::button('galleryConfigEdit' . $galleryId , [ @@ -71,27 +104,10 @@ class gallery extends common { 'value' => template::ico('cancel') ]) ]; + // Tableau des id des galleries pour le drag and drop + self::$galleriesId[] = $galleryId; } - } - // Soumission du formulaire - if($this->isPost()) { - $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', @@ -103,15 +119,40 @@ class gallery extends common { } /** - * Fonction AJAX tri des galeries + * Ajouter une galerie + * */ - public function filter() { - - $data = $_POST['data']; - var_dump(json_decode($data)); - var_dump($_POST); - die(); - + public function add() { + // Soumission du formulaire + if($this->isPost()) { + 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; + } else { + $success = false; + } + // Valeurs en sortie + $this->addOutput([ + 'redirect' => $success === true ? helper::baseUrl() . $this->getUrl() . '/config' : helper::baseUrl() . $this->getUrl() . '/add', + 'notification' => $success === true ? 'Modifications enregistrées' : 'Le nom de la galerie est obligatoire', + 'state' => $success + ]); + } else { + // valeurs en sortie + $this->addOutput([ + 'title' => 'Ajouter une galerie', + 'view' => 'add' + ]); + } } /** @@ -317,8 +358,16 @@ class gallery extends common { } // Liste des galeries - else { - foreach((array) $this->getData(['module', $this->getUrl(0)]) as $galleryId => $gallery) { + 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) { 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 new file mode 100644 index 00000000..b8d5a798 --- /dev/null +++ b/module/gallery/view/add/add.css @@ -0,0 +1,21 @@ +/** + * 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 new file mode 100644 index 00000000..1f0d8235 --- /dev/null +++ b/module/gallery/view/add/add.js.php @@ -0,0 +1,53 @@ +/** + * 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 = $("