Merge branch 'dev10_gallery_stock_v2' into dev10

This commit is contained in:
Fred Tempez 2020-04-04 16:22:07 +02:00
commit 3b1bf1c777
13 changed files with 190 additions and 116 deletions

View File

@ -602,10 +602,11 @@ class template {
* @param array $cols Cols des colonnes (format: [col colonne1, col colonne2, etc]) * @param array $cols Cols des colonnes (format: [col colonne1, col colonne2, etc])
* @param array $body Contenu (format: [[contenu1, contenu2, etc], [contenu1, contenu2, etc]]) * @param array $body Contenu (format: [[contenu1, contenu2, etc], [contenu1, contenu2, etc]])
* @param array $head Entêtes (format : [[titre colonne1, titre colonne2, etc]) * @param array $head Entêtes (format : [[titre colonne1, titre colonne2, etc])
* @param array $rowsId Id pour la numérotation des rows (format : [id colonne1, id colonne2, etc])
* @param array $attributes Attributs ($key => $value) * @param array $attributes Attributs ($key => $value)
* @return string * @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 // Attributs par défaut
$attributes = array_merge([ $attributes = array_merge([
'class' => '', 'class' => '',
@ -620,7 +621,7 @@ class template {
if($head) { if($head) {
// Début des entêtes // Début des entêtes
$html .= '<thead>'; $html .= '<thead>';
$html .= '<tr>'; $html .= '<tr class="nodrag">';
$i = 0; $i = 0;
foreach($head as $th) { foreach($head as $th) {
$html .= '<th class="col' . $cols[$i++] . '">' . $th . '</th>'; $html .= '<th class="col' . $cols[$i++] . '">' . $th . '</th>';
@ -628,11 +629,16 @@ class template {
// Fin des entêtes // Fin des entêtes
$html .= '</tr>'; $html .= '</tr>';
$html .= '</thead>'; $html .= '</thead>';
}
// Pas de tableau d'Id transmis, générer une numérotation
if (empty($rowsId)) {
$rowsId = range(0,count($body));
} }
// Début contenu // Début contenu
$html .= '<tbody>'; $j = 0;
foreach($body as $tr) { foreach($body as $tr) {
$html .= '<tr>'; // Id de ligne pour les tableaux drag and drop
$html .= '<tr id="' . $rowsId[$j++] . '">';
$i = 0; $i = 0;
foreach($tr as $td) { foreach($tr as $td) {
$html .= '<td class="col' . $cols[$i++] . '">' . $td . '</td>'; $html .= '<td class="col' . $cols[$i++] . '">' . $td . '</td>';

View File

@ -1143,6 +1143,7 @@ class common {
} }
$this->setData(['core', 'dataVersion', 10000]); $this->setData(['core', 'dataVersion', 10000]);
} }
} }
} }

View File

@ -537,7 +537,9 @@ class init extends common {
'beaux-paysages' => [ 'beaux-paysages' => [
'config' => [ 'config' => [
'name' => 'Beaux paysages', 'name' => 'Beaux paysages',
'directory' => self::FILE_DIR.'source/galerie/landscape' 'directory' => self::FILE_DIR.'source/galerie/landscape',
'sort' => 'SORT_ASC',
'position' => 1
], ],
'legend' => [ 'legend' => [
'desertjpg' => 'Un désert', 'desertjpg' => 'Un désert',
@ -548,7 +550,9 @@ class init extends common {
'espace' => [ 'espace' => [
'config' => [ 'config' => [
'name' => 'Espace', 'name' => 'Espace',
'directory' => self::FILE_DIR.'source/galerie/space' 'directory' => self::FILE_DIR.'source/galerie/space',
'sort' => 'SORT_ASC',
'position' => 2
], ],
'legend' => [ 'legend' => [
'earthjpg' => 'La Terre et la Lune', 'earthjpg' => 'La Terre et la Lune',

View File

@ -0,0 +1 @@
https://github.com/lukasoppermann/html5sortable

View File

@ -19,12 +19,13 @@ 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
]; ];
public static $sort = [ public static $sort = [
'SORT_ASC' => 'Alphabétique naturel', 'SORT_ASC' => 'Alphabétique ',
'SORT_DSC' => 'Alphabétique naturel inverse', 'SORT_DSC' => 'Alphabétique inversé',
'none' => 'Aucun tri', 'none' => 'Aucun tri',
]; ];
@ -34,16 +35,49 @@ class gallery extends common {
public static $galleries = []; public static $galleries = [];
public static $galleriesId = [];
public static $pictures = []; public static $pictures = [];
const GALLERY_VERSION = '1.3'; 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;$i<count($data);$i++) {
$this->setData(['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 * Configuration
*/ */
public function config() { public function config() {
// Liste des galeries // Tri des galeries
$galleries = $this->getData(['module', $this->getUrl(0)]); $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) { if($galleries) {
foreach($galleries as $galleryId => $gallery) { foreach($galleries as $galleryId => $gallery) {
// Erreur dossier vide // Erreur dossier vide
@ -58,15 +92,9 @@ class gallery extends common {
} }
// Met en forme le tableau // Met en forme le tableau
self::$galleries[] = [ self::$galleries[] = [
template::ico('sort'),
$gallery['config']['name'], $gallery['config']['name'],
$gallery['config']['directory'], $gallery['config']['directory'],
//$gallery['config']['order'],
/*
template::select('galleryConfigOrder', $galeryOrder , [
'selected' => $gallery['config']['order'],
'class' => 'configOrder'
]),*/
template::button('galleryConfigEdit' . $galleryId , [ template::button('galleryConfigEdit' . $galleryId , [
'href' => helper::baseUrl() . $this->getUrl(0) . '/edit/' . $galleryId . '/' . $_SESSION['csrf'], 'href' => helper::baseUrl() . $this->getUrl(0) . '/edit/' . $galleryId . '/' . $_SESSION['csrf'],
'value' => template::ico('pencil') 'value' => template::ico('pencil')
@ -77,17 +105,24 @@ class gallery extends common {
'value' => template::ico('cancel') 'value' => template::ico('cancel')
]) ])
]; ];
// Tableau des id des galleries pour le drag and drop
self::$galleriesId[] = $galleryId;
} }
} }
// Soumission du formulaire // Soumission du formulaire
if($this->isPost()) { 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)])); $galleryId = helper::increment($this->getInput('galleryConfigName', helper::FILTER_ID, true), (array) $this->getData(['module', $this->getUrl(0)]));
$this->setData(['module', $this->getUrl(0), $galleryId, [ $this->setData(['module', $this->getUrl(0), $galleryId, [
'config' => [ 'config' => [
'name' => $this->getInput('galleryConfigName'), 'name' => $this->getInput('galleryConfigName'),
'directory' => $this->getInput('galleryConfigDirectory', helper::FILTER_STRING_SHORT, true), 'directory' => $this->getInput('galleryConfigDirectory', helper::FILTER_STRING_SHORT, true),
'homePicture' => '',
'sort' => $this->getInput('galleryConfigSort'), 'sort' => $this->getInput('galleryConfigSort'),
'order' => count($this->getData(['module',$this->getUrl(0)])) + 1 'position' => count($this->getData(['module',$this->getUrl(0)])) + 1
], ],
'legend' => [] 'legend' => []
]]); ]]);
@ -98,10 +133,14 @@ class gallery extends common {
'state' => true 'state' => true
]); ]);
} }
}
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'title' => 'Configuration du module', 'title' => 'Configuration du module',
'view' => 'config' 'view' => 'config',
'vendor' => [
'tablednd'
]
]); ]);
} }
@ -196,7 +235,8 @@ class gallery extends common {
'name' => $this->getInput('galleryEditName', helper::FILTER_STRING_SHORT, true), 'name' => $this->getInput('galleryEditName', helper::FILTER_STRING_SHORT, true),
'directory' => $this->getInput('galleryEditDirectory', helper::FILTER_STRING_SHORT, true), 'directory' => $this->getInput('galleryEditDirectory', helper::FILTER_STRING_SHORT, true),
'homePicture' => $homePictures[$file], 'homePicture' => $homePictures[$file],
'sort' => $this->getInput('galleryEditSort') 'sort' => $this->getInput('galleryEditSort'),
'position' => count($this->getData(['module',$this->getUrl(0)])) + 1
], ],
'legend' => $legends 'legend' => $legends
]]); ]]);
@ -309,7 +349,15 @@ class gallery extends common {
} }
// Liste des galeries // Liste des galeries
else { else {
foreach((array) $this->getData(['module', $this->getUrl(0)]) as $galleryId => $gallery) { // 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'])) { if(is_dir($gallery['config']['directory'])) {
$iterator = new DirectoryIterator($gallery['config']['directory']); $iterator = new DirectoryIterator($gallery['config']['directory']);
foreach($iterator as $fileInfos) { foreach($iterator as $fileInfos) {

View File

@ -0,0 +1,3 @@
[
"tablednd.min.js"
]

View File

@ -0,0 +1 @@
https://github.com/isocra/TableDnD

File diff suppressed because one or more lines are too long

View File

@ -12,6 +12,24 @@
* @link http://zwiicms.com/ * @link http://zwiicms.com/
*/ */
/**
* Tri dynamique de la galerie
*/
$( document ).ready(function() {
$("#galleryTable").tableDnD({
onDrop: function(table, row) {
$("#galleryConfigFilterResponse").val($.tableDnD.serialize());
},
serializeRegexp: "[^\_]*$"
});
});
// Activer le bouton de tri uniquement après un tri
$("#galleryTable").mouseup(function(e) {
e.preventDefault();
$(":input[type='submit']").prop('disabled', false);
});
/** /**
* Confirmation de suppression * Confirmation de suppression
*/ */
@ -22,6 +40,8 @@ $(".galleryConfigDelete").on("click", function() {
}); });
}); });
/** /**
* Liste des dossiers * Liste des dossiers
*/ */
@ -62,4 +82,3 @@ directoryDOM.on("change", function() {
directoryOldDOM.val($(this).val()); directoryOldDOM.val($(this).val());
}); });

View File

@ -44,11 +44,25 @@
</div> </div>
</div> </div>
</div> </div>
<?php echo template::formClose(); ?>
<?php echo template::formOpen('galleryConfigFilterForm'); ?>
<?php if($module::$galleries): ?> <?php if($module::$galleries): ?>
<?php echo template::table([4, 6, 1, 1], $module::$galleries, ['Nom', 'Dossier cible', '', ''], ['id' => 'galleryTable']); ?> <?php echo template::table([1, 4, 5, 1, 1], $module::$galleries, ['','Nom', 'Dossier cible', '', ''], ['id' => 'galleryTable'],$module::$galleriesId); ?>
<?php echo template::hidden('galleryConfigFilterResponse'); ?>
<?php echo template::hidden('galleryConfigFilterSubmit',[
'value' => false
]); ?>
<?php else: ?> <?php else: ?>
<?php echo template::speech('Aucune galerie.'); ?> <?php echo template::speech('Aucune galerie.'); ?>
<?php endif; ?> <?php endif; ?>
<div class="row">
<div class="col2 offset10">
<?php echo template::submit('galleryConfigFilterSubmit', [
'value' => 'Trier',
'disabled' => true
]); ?>
</div>
</div>
<?php echo template::formClose(); ?> <?php echo template::formClose(); ?>
<div class="moduleVersion">Version <div class="moduleVersion">Version
<?php echo $module::GALLERY_VERSION; ?> <?php echo $module::GALLERY_VERSION; ?>

View File

@ -45,6 +45,6 @@
</div> </div>
</div> </div>
<?php if($module::$pictures): ?> <?php if($module::$pictures): ?>
<?php echo template::table([4, 1, 7], $module::$pictures, ['Image', 'Album','Légende']); ?> <?php echo template::table([4, 1, 7], $module::$pictures, ['Image', 'Couverture','Légende']); ?>
<?php endif; ?> <?php endif; ?>
<?php echo template::formClose(); ?> <?php echo template::formClose(); ?>

View File

@ -1,25 +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 <remi.jean@outlook.com>
* @copyright Copyright (C) 2008-2018, Rémi Jean
* @authorFrédéric Tempez <frederic.tempez@outlook.com>
* @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);
*/
});

View File

@ -5,7 +5,7 @@
<?php if($i % 2 === 1): ?> <?php if($i % 2 === 1): ?>
<div class="row"> <div class="row">
<?php endif; ?> <?php endif; ?>
<div class="col6" div="pos<?php echo $gallery['config']['order']; ?>" > <div class="col6" div="pos<?php echo $gallery['config']['position']; ?>" >
<a <a
href="<?php echo helper::baseUrl() . $this->getUrl(0); ?>/<?php echo $galleryId; ?>" href="<?php echo helper::baseUrl() . $this->getUrl(0); ?>/<?php echo $galleryId; ?>"
class="galleryPicture" class="galleryPicture"