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

@ -598,56 +598,62 @@ class template {
} }
/** /**
* Crée un tableau * Crée un tableau
* @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 $attributes Attributs ($key => $value) * @param array $rowsId Id pour la numérotation des rows (format : [id colonne1, id colonne2, etc])
* @return string * @param array $attributes Attributs ($key => $value)
*/ * @return string
public static function table(array $cols = [], array $body = [], array $head = [], array $attributes = []) { */
// Attributs par défaut public static function table(array $cols = [], array $body = [], array $head = [], array $attributes = [], array $rowsId = []) {
$attributes = array_merge([ // Attributs par défaut
'class' => '', $attributes = array_merge([
'classWrapper' => '', 'class' => '',
'id' => '' 'classWrapper' => '',
], $attributes); 'id' => ''
// Début du wrapper ], $attributes);
$html = '<div id="' . $attributes['id'] . 'Wrapper" class="tableWrapper ' . $attributes['classWrapper']. '">'; // Début du wrapper
// Début tableau $html = '<div id="' . $attributes['id'] . 'Wrapper" class="tableWrapper ' . $attributes['classWrapper']. '">';
$html .= '<table id="' . $attributes['id'] . '" class="table ' . $attributes['class']. '">'; // Début tableau
// Entêtes $html .= '<table id="' . $attributes['id'] . '" class="table ' . $attributes['class']. '">';
if($head) { // Entêtes
// Début des entêtes if($head) {
$html .= '<thead>'; // Début des entêtes
$html .= '<tr>'; $html .= '<thead>';
$i = 0; $html .= '<tr class="nodrag">';
foreach($head as $th) { $i = 0;
$html .= '<th class="col' . $cols[$i++] . '">' . $th . '</th>'; foreach($head as $th) {
} $html .= '<th class="col' . $cols[$i++] . '">' . $th . '</th>';
// Fin des entêtes }
$html .= '</tr>'; // Fin des entêtes
$html .= '</thead>'; $html .= '</tr>';
$html .= '</thead>';
} }
// Début contenu // Pas de tableau d'Id transmis, générer une numérotation
$html .= '<tbody>'; if (empty($rowsId)) {
foreach($body as $tr) { $rowsId = range(0,count($body));
$html .= '<tr>';
$i = 0;
foreach($tr as $td) {
$html .= '<td class="col' . $cols[$i++] . '">' . $td . '</td>';
}
$html .= '</tr>';
} }
// Fin contenu // Début contenu
$html .= '</tbody>'; $j = 0;
// Fin tableau foreach($body as $tr) {
$html .= '</table>'; // Id de ligne pour les tableaux drag and drop
// Fin container $html .= '<tr id="' . $rowsId[$j++] . '">';
$html .= '</div>'; $i = 0;
// Retourne le html foreach($tr as $td) {
return $html; $html .= '<td class="col' . $cols[$i++] . '">' . $td . '</td>';
} }
$html .= '</tr>';
}
// Fin contenu
$html .= '</tbody>';
// Fin tableau
$html .= '</table>';
// Fin container
$html .= '</div>';
// Retourne le html
return $html;
}
/** /**
* Crée un champ texte court * Crée un champ texte court

View File

@ -475,7 +475,7 @@ class common {
// La clef est une chaine // La clef est une chaine
else { else {
foreach($this->input as $type => $values) { foreach($this->input as $type => $values) {
// Champ obligatoire // Champ obligatoire
if($required) { if($required) {
$this->addRequiredInputNotices($key); $this->addRequiredInputNotices($key);
} }
@ -1110,7 +1110,7 @@ class common {
// Forcer la régénération du thème // Forcer la régénération du thème
if (file_exists(self::DATA_DIR.'theme.css')) { if (file_exists(self::DATA_DIR.'theme.css')) {
unlink (self::DATA_DIR.'theme.css'); unlink (self::DATA_DIR.'theme.css');
} }
$this->setData(['core', 'dataVersion', 9227]); $this->setData(['core', 'dataVersion', 9227]);
} }
// Version 10.0.00 // Version 10.0.00
@ -1143,6 +1143,7 @@ class common {
} }
$this->setData(['core', 'dataVersion', 10000]); $this->setData(['core', 'dataVersion', 10000]);
} }
} }
} }
@ -2400,4 +2401,4 @@ class layout extends common {
} }
} }
} }

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,
'index' => self::GROUP_VISITOR 'filter' => self::GROUP_MODERATOR,
'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
@ -57,16 +91,10 @@ class gallery extends common {
$gallery['config']['directory'] = '<span class="galleryConfigError">' . $gallery['config']['directory'] . ' (dossier introuvable)</span>'; $gallery['config']['directory'] = '<span class="galleryConfigError">' . $gallery['config']['directory'] . ' (dossier introuvable)</span>';
} }
// 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,31 +105,42 @@ 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()) {
$galleryId = helper::increment($this->getInput('galleryConfigName', helper::FILTER_ID, true), (array) $this->getData(['module', $this->getUrl(0)])); if ($this->getInput('galleryConfigFilterResponse')) {
$this->setData(['module', $this->getUrl(0), $galleryId, [ self::filter();
'config' => [ } else {
'name' => $this->getInput('galleryConfigName'), $galleryId = helper::increment($this->getInput('galleryConfigName', helper::FILTER_ID, true), (array) $this->getData(['module', $this->getUrl(0)]));
'directory' => $this->getInput('galleryConfigDirectory', helper::FILTER_STRING_SHORT, true), $this->setData(['module', $this->getUrl(0), $galleryId, [
'sort' => $this->getInput('galleryConfigSort'), 'config' => [
'order' => count($this->getData(['module',$this->getUrl(0)])) + 1 'name' => $this->getInput('galleryConfigName'),
], 'directory' => $this->getInput('galleryConfigDirectory', helper::FILTER_STRING_SHORT, true),
'legend' => [] 'homePicture' => '',
]]); 'sort' => $this->getInput('galleryConfigSort'),
// Valeurs en sortie 'position' => count($this->getData(['module',$this->getUrl(0)])) + 1
$this->addOutput([ ],
'redirect' => helper::baseUrl() . $this->getUrl(), 'legend' => []
'notification' => 'Modifications enregistrées', ]]);
'state' => true // Valeurs en sortie
]); $this->addOutput([
'redirect' => helper::baseUrl() . $this->getUrl(),
'notification' => 'Modifications enregistrées',
'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
]]); ]]);
@ -308,8 +348,16 @@ 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"