From 932b78650ae05ac78d0f97e13bad4b62105a7937 Mon Sep 17 00:00:00 2001 From: Fred Tempez Date: Tue, 24 Mar 2020 17:48:54 +0100 Subject: [PATCH 01/20] =?UTF-8?q?manque=20r=C3=A9cup=C3=A9ration=20donn?= =?UTF-8?q?=C3=A9es=20ajax?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/core.php | 10 +++--- module/form/vendor/html-sortable/lisezmoi.txt | 1 + module/gallery/gallery.php | 25 +++++++++++---- module/gallery/vendor/tablednd/inc.json | 3 ++ module/gallery/vendor/tablednd/lisez-moi.txt | 1 + .../gallery/vendor/tablednd/tablednd.min.js | 2 ++ module/gallery/view/config/config.js.php | 32 ++++++++++++------- 7 files changed, 51 insertions(+), 23 deletions(-) create mode 100644 module/form/vendor/html-sortable/lisezmoi.txt create mode 100644 module/gallery/vendor/tablednd/inc.json create mode 100644 module/gallery/vendor/tablednd/lisez-moi.txt create mode 100644 module/gallery/vendor/tablednd/tablednd.min.js diff --git a/core/core.php b/core/core.php index e8093bd8..006f566d 100644 --- a/core/core.php +++ b/core/core.php @@ -3327,7 +3327,7 @@ class template { if($head) { // Début des entêtes $html .= ''; - $html .= ''; + $html .= ''; $i = 0; foreach($head as $th) { $html .= '' . $th . ''; @@ -3337,12 +3337,12 @@ class template { $html .= ''; } // Début contenu - $html .= ''; - foreach($body as $tr) { - $html .= ''; + $j = 1; + foreach($body as $tr) { + $html .= ''; $i = 0; foreach($tr as $td) { - $html .= '' . $td . ''; + $html .= '' . $td . ''; } $html .= ''; } diff --git a/module/form/vendor/html-sortable/lisezmoi.txt b/module/form/vendor/html-sortable/lisezmoi.txt new file mode 100644 index 00000000..83c36b44 --- /dev/null +++ b/module/form/vendor/html-sortable/lisezmoi.txt @@ -0,0 +1 @@ +https://github.com/lukasoppermann/html5sortable \ No newline at end of file diff --git a/module/gallery/gallery.php b/module/gallery/gallery.php index b1c3b30a..73f5b913 100644 --- a/module/gallery/gallery.php +++ b/module/gallery/gallery.php @@ -16,9 +16,10 @@ class gallery extends common { public static $actions = [ 'config' => self::GROUP_MODERATOR, + 'filter' =>self::GROUP_MODERATOR, 'delete' => self::GROUP_MODERATOR, 'dirs' => self::GROUP_MODERATOR, - 'edit' => self::GROUP_MODERATOR, + 'edit' => self::GROUP_MODERATOR, 'index' => self::GROUP_VISITOR ]; @@ -44,8 +45,6 @@ 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) { foreach($galleries as $galleryId => $gallery) { // Erreur dossier vide @@ -58,9 +57,6 @@ 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'], @@ -99,10 +95,25 @@ class gallery extends common { // Valeurs en sortie $this->addOutput([ 'title' => 'Configuration du module', - 'view' => 'config' + 'view' => 'config', + 'vendor' => [ + 'tablednd' + ] ]); } + /** + * Fonction AJAX tri des galeries + */ + public function filter() { + + $data = $_POST['data']; + var_dump(json_decode($data)); + var_dump($_POST); + die(); + + } + /** * Suppression */ diff --git a/module/gallery/vendor/tablednd/inc.json b/module/gallery/vendor/tablednd/inc.json new file mode 100644 index 00000000..aea2b720 --- /dev/null +++ b/module/gallery/vendor/tablednd/inc.json @@ -0,0 +1,3 @@ +[ + "tablednd.min.js" +] \ No newline at end of file diff --git a/module/gallery/vendor/tablednd/lisez-moi.txt b/module/gallery/vendor/tablednd/lisez-moi.txt new file mode 100644 index 00000000..dfa8616a --- /dev/null +++ b/module/gallery/vendor/tablednd/lisez-moi.txt @@ -0,0 +1 @@ +https://github.com/isocra/TableDnD \ No newline at end of file diff --git a/module/gallery/vendor/tablednd/tablednd.min.js b/module/gallery/vendor/tablednd/tablednd.min.js new file mode 100644 index 00000000..225739f4 --- /dev/null +++ b/module/gallery/vendor/tablednd/tablednd.min.js @@ -0,0 +1,2 @@ +/*! jquery.tablednd.js 30-12-2017 */ +!function(a,b,c,d){var e="touchstart mousedown",f="touchmove mousemove",g="touchend mouseup";a(c).ready(function(){function b(a){for(var b={},c=a.match(/([^;:]+)/g)||[];c.length;)b[c.shift()]=c.shift().trim();return b}a("table").each(function(){"dnd"===a(this).data("table")&&a(this).tableDnD({onDragStyle:a(this).data("ondragstyle")&&b(a(this).data("ondragstyle"))||null,onDropStyle:a(this).data("ondropstyle")&&b(a(this).data("ondropstyle"))||null,onDragClass:a(this).data("ondragclass")===d&&"tDnD_whileDrag"||a(this).data("ondragclass"),onDrop:a(this).data("ondrop")&&new Function("table","row",a(this).data("ondrop")),onDragStart:a(this).data("ondragstart")&&new Function("table","row",a(this).data("ondragstart")),onDragStop:a(this).data("ondragstop")&&new Function("table","row",a(this).data("ondragstop")),scrollAmount:a(this).data("scrollamount")||5,sensitivity:a(this).data("sensitivity")||10,hierarchyLevel:a(this).data("hierarchylevel")||0,indentArtifact:a(this).data("indentartifact")||'
 
',autoWidthAdjust:a(this).data("autowidthadjust")||!0,autoCleanRelations:a(this).data("autocleanrelations")||!0,jsonPretifySeparator:a(this).data("jsonpretifyseparator")||"\t",serializeRegexp:a(this).data("serializeregexp")&&new RegExp(a(this).data("serializeregexp"))||/[^\-]*$/,serializeParamName:a(this).data("serializeparamname")||!1,dragHandle:a(this).data("draghandle")||null})})}),jQuery.tableDnD={currentTable:null,dragObject:null,mouseOffset:null,oldX:0,oldY:0,build:function(b){return this.each(function(){this.tableDnDConfig=a.extend({onDragStyle:null,onDropStyle:null,onDragClass:"tDnD_whileDrag",onDrop:null,onDragStart:null,onDragStop:null,scrollAmount:5,sensitivity:10,hierarchyLevel:0,indentArtifact:'
 
',autoWidthAdjust:!0,autoCleanRelations:!0,jsonPretifySeparator:"\t",serializeRegexp:/[^\-]*$/,serializeParamName:!1,dragHandle:null},b||{}),a.tableDnD.makeDraggable(this),this.tableDnDConfig.hierarchyLevel&&a.tableDnD.makeIndented(this)}),this},makeIndented:function(b){var c,d,e=b.tableDnDConfig,f=b.rows,g=a(f).first().find("td:first")[0],h=0,i=0;if(a(b).hasClass("indtd"))return null;d=a(b).addClass("indtd").attr("style"),a(b).css({whiteSpace:"nowrap"});for(var j=0;ja.vertical&&this.dragObject.parentNode.insertBefore(this.dragObject,b.nextSibling)||00&&a(c).find("td:first").children(":first").remove()&&a(c).data("level",--d),0>b.horizontal&&d=d&&a(c).children(":first").prepend(e.indentArtifact)&&a(c).data("level",++d)},mousemove:function(b){var c,d,e,f,g,h=a(a.tableDnD.dragObject),i=a.tableDnD.currentTable.tableDnDConfig;return b&&b.preventDefault(),!!a.tableDnD.dragObject&&("touchmove"===b.type&&event.preventDefault(),i.onDragClass&&h.addClass(i.onDragClass)||h.css(i.onDragStyle),d=a.tableDnD.mouseCoords(b),f=d.x-a.tableDnD.mouseOffset.x,g=d.y-a.tableDnD.mouseOffset.y,a.tableDnD.autoScroll(d),c=a.tableDnD.findDropTargetRow(h,g),e=a.tableDnD.findDragDirection(f,g),a.tableDnD.moveVerticle(e,c),a.tableDnD.moveHorizontal(e,c),!1)},findDragDirection:function(a,b){var c=this.currentTable.tableDnDConfig.sensitivity,d=this.oldX,e=this.oldY,f=d-c,g=d+c,h=e-c,i=e+c,j={horizontal:a>=f&&a<=g?0:a>d?-1:1,vertical:b>=h&&b<=i?0:b>e?-1:1};return 0!==j.horizontal&&(this.oldX=a),0!==j.vertical&&(this.oldY=b),j},findDropTargetRow:function(b,c){for(var d=0,e=this.currentTable.rows,f=this.currentTable.tableDnDConfig,g=0,h=null,i=0;ig-d&&c1&&a(this.currentTable.rows).each(function(){if((h=a(this).data("level"))>1)for(e=a(this).prev().data("level");h>e+1;)a(this).find("td:first").children(":first").remove(),a(this).data("level",--h)}),b.onDragClass&&a(d).removeClass(b.onDragClass)||a(d).css(b.onDropStyle),this.dragObject=null,b.onDrop&&this.originalOrder!==this.currentOrder()&&a(d).hide().fadeIn("fast")&&b.onDrop(this.currentTable,d),b.onDragStop&&b.onDragStop(this.currentTable,d),this.currentTable=null},mouseup:function(b){return b&&b.preventDefault(),a.tableDnD.processMouseup(),!1},jsonize:function(a){var b=this.currentTable;return a?JSON.stringify(this.tableData(b),null,b.tableDnDConfig.jsonPretifySeparator):JSON.stringify(this.tableData(b))},serialize:function(){return a.param(this.tableData(this.currentTable))},serializeTable:function(a){for(var b="",c=a.tableDnDConfig.serializeParamName||a.id,d=a.rows,e=0;e0&&(b+="&");var f=d[e].id;f&&a.tableDnDConfig&&a.tableDnDConfig.serializeRegexp&&(f=f.match(a.tableDnDConfig.serializeRegexp)[0],b+=c+"[]="+f)}return b},serializeTables:function(){var b=[];return a("table").each(function(){this.id&&b.push(a.param(a.tableDnD.tableData(this)))}),b.join("&")},tableData:function(b){var c,d,e,f,g=b.tableDnDConfig,h=[],i=0,j=0,k=null,l={};if(b||(b=this.currentTable),!b||!b.rows||!b.rows.length)return{error:{code:500,message:"Not a valid table."}};if(!b.id&&!g.serializeParamName)return{error:{code:500,message:"No serializable unique id provided."}};f=g.autoCleanRelations&&b.rows||a.makeArray(b.rows),d=g.serializeParamName||b.id,e=d,c=function(a){return a&&g&&g.serializeRegexp?a.match(g.serializeRegexp)[0]:a},l[e]=[],!g.autoCleanRelations&&a(f[0]).data("level")&&f.unshift({id:"undefined"});for(var m=0;mi)h.push([e,i]),e=c(f[m-1].id);else if(j=i&&(h[n][1]=0);i=j,a.isArray(l[e])||(l[e]=[]),k=c(f[m].id),k&&l[e].push(k)}else(k=c(f[m].id))&&l[e].push(k);return l}},jQuery.fn.extend({tableDnD:a.tableDnD.build,tableDnDUpdate:a.tableDnD.updateTables,tableDnDSerialize:a.proxy(a.tableDnD.serialize,a.tableDnD),tableDnDSerializeAll:a.tableDnD.serializeTables,tableDnDData:a.proxy(a.tableDnD.tableData,a.tableDnD)})}(jQuery,window,window.document); \ No newline at end of file diff --git a/module/gallery/view/config/config.js.php b/module/gallery/view/config/config.js.php index 80bef565..a2983968 100644 --- a/module/gallery/view/config/config.js.php +++ b/module/gallery/view/config/config.js.php @@ -67,15 +67,25 @@ directoryDOM.on("change", function() { * 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); + $("#galleryTable").tableDnD({ + onDrop: function(table, row) { + console.log($.tableDnD.serialize()); + var url= getUrl(0) . '/filter'); ?>; + /*url = "http://localhost/ZwiiCMS/?galeries/filter"; */ + $.ajax({ + url: url, + data: $.tableDnD.serialize(), + type: "POST", + success: function (data) { + // Je charge les données dans box + alert("ok"); + }, + // La fonction à appeler si la requête n'a pas abouti + error: function() { + // J'affiche un message d'erreur + alert("Désolé, aucun résultat trouvé."); + } + }); + } + }); }); \ No newline at end of file From e3da2f3dba8fdfa7c59c5d59966469c558b24481 Mon Sep 17 00:00:00 2001 From: Fred Tempez Date: Fri, 27 Mar 2020 15:06:35 +0100 Subject: [PATCH 02/20] Gallery v2 init --- core/core.php | 10 +- module/gallery/gallery.php | 119 ++++++++++++++++------- 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 | 64 +----------- module/gallery/view/config/config.php | 77 ++++++--------- 7 files changed, 246 insertions(+), 146 deletions(-) create mode 100644 module/gallery/view/add/add.css create mode 100644 module/gallery/view/add/add.js.php create mode 100644 module/gallery/view/add/add.php 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 = $("