WIP - Fix ordering see BT#15967

pull/2981/head
Julio Montoya 6 years ago
parent 472c9c0337
commit d8593ad72b
  1. 2
      main/lp/learnpath.class.php
  2. 113
      main/lp/lp_controller.php

@ -6535,7 +6535,7 @@ class learnpath
$sub_list = ''; $sub_list = '';
if (isset($item['type']) && $item['type'] == 'dir') { if (isset($item['type']) && $item['type'] == 'dir') {
// empty value // empty value
$sub_list = Display::tag('li', '', ['class' => 'sub_item empty record li_container']); $sub_list = Display::tag('li', '', ['class' => 'sub_item empty']);
} }
if (empty($item['children'])) { if (empty($item['children'])) {
$sub_list = Display::tag('ul', $sub_list, ['id' => 'UL_'.$key, 'class' => 'record li_container']); $sub_list = Display::tag('ul', $sub_list, ['id' => 'UL_'.$key, 'class' => 'record li_container']);

@ -102,36 +102,131 @@ $htmlHeadXtra[] = '
var jItems = $("#lp_item_list li.li_container"); var jItems = $("#lp_item_list li.li_container");
var jItem = $("#"+ itemId); var jItem = $("#"+ itemId);
var index = jItems.index(jItem); var index = jItems.index(jItem);
var total = jItems.length; var total = jItems.length;
//console.log(jItems);
console.log("total " + total);
console.log("current " + index);
switch (dir) { switch (dir) {
case "up": case "up":
if (index != 0 && jItems[index - 1]) { if (index != 0 && jItems[index - 1]) {
var subItems = $(jItems[index - 1]).find("li.sub_item"); /*var subItems = $(jItems[index - 1]).find("li.sub_item");
if (subItems.length >= 0) { if (subItems.length >= 0) {
index = index - 1; index = index - 1;
}*/
var subItems = $(jItems[index - 1]).find("li.sub_item");
var parentClass = $(jItems[index - 1]).parent().parent().attr("class");
var parentId = $(jItems[index]).parent().parent().attr("id");
var myParentId = $(jItems[index - 1]).parent().parent().attr("id");
console.log(parentId + " - " + myParentId);
// We are brothers!
if (parentId == myParentId) {
console.log("Brothers");
console.log(subItems.length);
if (subItems.length > 0) {
var lastItem = $(jItems[index - 1]).find("li.sub_item");
parentIndex = jItems.index(lastItem);
console.log(parentIndex);
jItem.detach().insertAfter(lastItem);
console.log("not classic");
} else {
console.log("classic");
jItem.detach().insertBefore(jItems[index - 1]);
}
break;
} }
jItem.detach().insertBefore(jItems[index - 1]);
console.log(parentClass);
if (parentClass == "record li_container") {
// previous is a chapter
var lastItem = $(jItems[index - 1]).parent().parent().find("li.li_container").last();
parentIndex = jItems.index(lastItem);
console.log(parentIndex);
jItem.detach().insertAfter(jItems[parentIndex]);
} else {
jItem.detach().insertBefore(jItems[index - 1]);
}
} }
break; break;
case "down": case "down":
if (index != jItems.length - 1) { if (index != total - 1) {
const originIndex = index;
// The element is a chapter with items
var subItems = jItem.find("li.li_container"); var subItems = jItem.find("li.li_container");
if (subItems.length >= 0) { if (subItems.length > 0) {
index = subItems.length + index; index = subItems.length + index;
} console.log("element is a chapter with items");
console.log("new index = " + index);
}
// is a chapter?
var subItems = $(jItems[index + 1]).find("li.sub_item"); var subItems = $(jItems[index + 1]).find("li.sub_item");
if (subItems.length >= 0) { console.log("next subItems.length: "+subItems.length);
index = index + 1; // This is an element entering in a chapter
if (subItems.length > 0) {
// Check if im a child
var parentClass = jItem.parent().parent().attr("class");
console.log(parentClass);
if (parentClass == "record li_container") {
// Parent position
var parentIndex = jItems.index(jItem.parent().parent());
console.log(jItem.parent().parent().attr("id"));
console.log(parentIndex);
jItem.detach().insertAfter(jItems[parentIndex]);
} else {
jItem.detach().insertAfter(subItems);
}
break;
}
var currentSubItems = $(jItems[index]).parent().find("li.sub_item");
console.log("currentSubItems"+currentSubItems.length);
var parentId = $(jItems[originIndex]).parent().parent().attr("id");
var myParentId = $(jItems[index + 1]).parent().parent().attr("id");
console.log("parent ids: "+ parentId + " - " + myParentId);
// We are brothers!
if (parentId == myParentId) {
if ((index + 1) < total) {
console.log(index + 1);
console.log("We are brothers");
jItem.detach().insertAfter(jItems[index + 1]);
}
break;
}
if (currentSubItems.length > 0) {
var parentIndex = jItems.index(jItem.parent().parent());
console.log("has currentSubItems");
console.log(jItem.parent().parent().attr("id"));
console.log(parentIndex);
if (parentIndex > 0) {
jItem.detach().insertAfter(jItems[parentIndex]);
break;
}
//jItem.detach().insertAfter($(jItems[index]).parent().parent());
}
//var lastItem = $(jItems[index + 1]).parent().parent().find("li.li_container").last();
if (subItems.length > 0) {
index = originIndex;
} }
if ((index + 1) < total) { if ((index + 1) < total) {
console.log(index + 1);
console.log("changed");
jItem.detach().insertAfter(jItems[index + 1]); jItem.detach().insertAfter(jItems[index + 1]);
} }
} }
break; break;
} }
console.log("rebuild");
buildLPtree($("#lp_item_list"), 0); buildLPtree($("#lp_item_list"), 0);
var order = "new_order="+ newOrderData + "&a=update_lp_item_order"; var order = "new_order="+ newOrderData + "&a=update_lp_item_order";

Loading…
Cancel
Save