From a93b63980f2c7a8a6c7b551362e06fb4482c36f8 Mon Sep 17 00:00:00 2001
From: pabois <pierreandre.boissinot@noesya.coop>
Date: Thu, 21 Oct 2021 17:03:43 +0200
Subject: [PATCH] sortable

---
 app/assets/javascripts/admin/treeview.js      |  3 ++-
 .../website/pages/children.js.erb             | 25 +------------------
 2 files changed, 3 insertions(+), 25 deletions(-)

diff --git a/app/assets/javascripts/admin/treeview.js b/app/assets/javascripts/admin/treeview.js
index 5ef95956f..92273c52f 100644
--- a/app/assets/javascripts/admin/treeview.js
+++ b/app/assets/javascripts/admin/treeview.js
@@ -52,7 +52,8 @@ window.osuny.treeView = {
     invoke: function () {
         'use strict';
         return {
-            init: this.init.bind(this)
+            init: this.init.bind(this),
+            initSortable: this.initSortable.bind(this)
         };
     }
 }.invoke();
diff --git a/app/views/admin/communication/website/pages/children.js.erb b/app/views/admin/communication/website/pages/children.js.erb
index 900cd91c5..113897cf0 100644
--- a/app/views/admin/communication/website/pages/children.js.erb
+++ b/app/views/admin/communication/website/pages/children.js.erb
@@ -3,27 +3,4 @@ $('.js-treeview-children', $branch).html("<%= escape_javascript(render 'treebran
 $branch.addClass('treeview__branch--loaded');
 
 
-var nestedSortables,
-    i;
-
-nestedSortables = [].slice.call(document.querySelectorAll('.js-treeview-sortable'));
-for (i = 0; i < nestedSortables.length; i += 1) {
-    new Sortable(nestedSortables[i], {
-        group: 'nested',
-        animation: 150,
-        fallbackOnBody: true,
-        swapThreshold: 0.65,
-        onEnd: function (/**Event*/evt) {
-            console.log(evt);
-            var itemEl = evt.item;  // dragged HTMLElement
-            evt.to;    // target list
-            evt.from;  // previous list
-            evt.oldIndex;  // element's old index within old parent
-            evt.newIndex;  // element's new index within new parent
-            evt.oldDraggableIndex; // element's old index within old parent, only counting draggable elements
-            evt.newDraggableIndex; // element's new index within new parent, only counting draggable elements
-            evt.clone // the clone element
-            evt.pullMode;  // when item is in another sortable: `"clone"` if cloning, `true` if moving
-        },
-    });
-}
+window.osuny.treeView.initSortable();
-- 
GitLab