Skip to content
Snippets Groups Projects
Commit 5aea6753 authored by pabois's avatar pabois
Browse files

wip treeview

parent 5d3e7c1c
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,7 @@ window.osuny.treeView = { ...@@ -4,7 +4,7 @@ window.osuny.treeView = {
init: function () { init: function () {
'use strict'; 'use strict';
$('.js-treeview').on('click', '.js-treeview-element', this.branchClicked.bind(this)); $('.js-treeview').on('click', '.js-treeview-openzone', this.branchClicked.bind(this));
this.initSortable(); this.initSortable();
}, },
...@@ -20,18 +20,18 @@ window.osuny.treeView = { ...@@ -20,18 +20,18 @@ window.osuny.treeView = {
animation: 150, animation: 150,
fallbackOnBody: true, fallbackOnBody: true,
swapThreshold: 0.65, swapThreshold: 0.65,
onEnd: function (/**Event*/evt) { onEnd: function (evt) {
console.log(evt); var from = evt.from,
var itemEl = evt.item; // dragged HTMLElement to = evt.to,
evt.to; // target list ids = [],
evt.from; // previous list parentId;
evt.oldIndex; // element's old index within old parent $('> .js-treeview-element', to).each(function () {
evt.newIndex; // element's new index within new parent ids.push($(this).attr('data-id'));
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 parentId = to.dataset.id;
evt.clone // the clone element console.log(parentId, ids, from === to);
evt.pullMode; // when item is in another sortable: `"clone"` if cloning, `true` if moving // TODO
}, }
}); });
} }
}, },
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
&__branch, &__leaf &__branch, &__leaf
& > .treeview__label & > .treeview__label
& > .move_btn & > .move_btn
transition: opacity 0.1s
opacity: 0 opacity: 0
transition: opacity 0.1s
&:hover &:hover
& > .treeview__label & > .treeview__label
& > .move_btn & > .move_btn
......
<% pages.each do |page| %> <% pages.each do |page| %>
<li class="<%= page.has_children? ? 'treeview__branch js-treeview-branch' : 'treeview__leaf' %>" data-id="<%= page.id %>"> <li class="js-treeview-element <%= page.has_children? ? 'treeview__branch js-treeview-branch' : 'treeview__leaf' %>" data-id="<%= page.id %>" data-parent="<%= page.parent_id %>">
<div class="d-flex align-items-center treeview__label border-bottom p-1"> <div class="d-flex align-items-center treeview__label border-bottom p-1">
<% if page.has_children? %> <% if page.has_children? %>
<%= link_to children_admin_communication_website_page_path(website_id: page.website.id, id: page.id), <%= link_to children_admin_communication_website_page_path(website_id: page.website.id, id: page.id),
class: 'js-treeview-element d-inline-block p-2 ps-0', style: 'width: 22px', remote: true do %> class: 'js-treeview-openzone d-inline-block p-2 ps-0', style: 'width: 22px', remote: true do %>
<span class="open_btn"><i class="fas fa-folder"></i></span> <span class="open_btn"><i class="fas fa-folder"></i></span>
<span class="close_btn"><i class="fas fa-folder-open"></i></span> <span class="close_btn"><i class="fas fa-folder-open"></i></span>
<% end %> <% end %>
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<span class="move_btn py-2 ps-2"><i class="fas fa-sort"></i></span> <span class="move_btn py-2 ps-2"><i class="fas fa-sort"></i></span>
</div> </div>
<% if page.has_children? %> <% if page.has_children? %>
<ul class="list-unstyled treeview__children js-treeview-children js-treeview-sortable ms-4"> <ul class="list-unstyled treeview__children js-treeview-children js-treeview-sortable ms-4" data-id="<%= page.id %>">
<li>loading...</li> <li>loading...</li>
</ul> </ul>
<% end %> <% end %>
......
<% content_for :title, Communication::Website::Page.model_name.human(count: 2) %> <% content_for :title, Communication::Website::Page.model_name.human(count: 2) %>
<ul class="list-unstyled treeview js-treeview js-treeview-sortable"> <ul class="list-unstyled treeview js-treeview js-treeview-sortable" data-id="">
<%= render 'treebranch', pages: @pages %> <%= render 'treebranch', pages: @pages %>
</ul> </ul>
<%#= render 'admin/communication/website/pages/list', pages: @pages %>
<%#= paginate @pages, theme: 'bootstrap-5' %>
<% content_for :action_bar_right do %> <% content_for :action_bar_right do %>
<%= create_link Communication::Website::Page %> <%= create_link Communication::Website::Page %>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment