diff --git a/main/lp/learnpath.class.php b/main/lp/learnpath.class.php index 14ecd220ef..7960ccb4e6 100755 --- a/main/lp/learnpath.class.php +++ b/main/lp/learnpath.class.php @@ -6535,7 +6535,7 @@ class learnpath $sub_list = ''; if (isset($item['type']) && $item['type'] == 'dir') { // 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'])) { $sub_list = Display::tag('ul', $sub_list, ['id' => 'UL_'.$key, 'class' => 'record li_container']); diff --git a/main/lp/lp_controller.php b/main/lp/lp_controller.php index 8589843d4a..dd9af80223 100755 --- a/main/lp/lp_controller.php +++ b/main/lp/lp_controller.php @@ -102,36 +102,131 @@ $htmlHeadXtra[] = ' var jItems = $("#lp_item_list li.li_container"); var jItem = $("#"+ itemId); 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) { case "up": 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) { 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; 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"); - if (subItems.length >= 0) { + if (subItems.length > 0) { 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"); - if (subItems.length >= 0) { - index = index + 1; + console.log("next subItems.length: "+subItems.length); + // 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) { + console.log(index + 1); + console.log("changed"); jItem.detach().insertAfter(jItems[index + 1]); } } break; } + console.log("rebuild"); buildLPtree($("#lp_item_list"), 0); var order = "new_order="+ newOrderData + "&a=update_lp_item_order";