Fix_Empty_Drag_and_Drop_Issue : RV

This commit is contained in:
VENKATESHWARAN 2024-01-23 17:32:20 +05:30
parent 072126a2f2
commit 40aa6fe055
3 changed files with 100 additions and 69 deletions

View File

@ -1478,7 +1478,6 @@ return false;
} }
let innerDivElement = document.getElementById('Max_Marks'); let innerDivElement = document.getElementById('Max_Marks');
console.log(innerDivElement)
innerDivElement.addEventListener("keyup", function(event) { innerDivElement.addEventListener("keyup", function(event) {
json2nav(); json2nav();
@ -1921,7 +1920,6 @@ var questionIncrement = 1;
$(document).ready(function(){ $(document).ready(function(){
array_of_Id.push('Max_Marks') array_of_Id.push('Max_Marks')
console.log(array_of_Id);
const arrayString = JSON.stringify(array_of_Id); const arrayString = JSON.stringify(array_of_Id);
collect_Empty_Question_Id(arrayString, 'Max_Marks'); collect_Empty_Question_Id(arrayString, 'Max_Marks');
}) })
@ -4220,14 +4218,12 @@ const titleElements = textQuestiontitleId.previousElementSibling;
if (mathEnabled === 'Math') if (mathEnabled === 'Math')
{ {
console.log('mathEnabled === true');
ChoiceMathSwitchId.checked = true; ChoiceMathSwitchId.checked = true;
$(Elements).hide(); $(Elements).hide();
$(textQuestionSubtitle_mathId).show(); $(textQuestionSubtitle_mathId).show();
} }
else else
{ {
console.log('mathEnabled === false');
ChoiceMathSwitchId.checked = false; ChoiceMathSwitchId.checked = false;
$(Elements).show(); $(Elements).show();
$(textQuestionSubtitle_mathId).hide(); $(textQuestionSubtitle_mathId).hide();

View File

@ -73,6 +73,7 @@ var draggedItem = null;
//Nav Pane full Element //Nav Pane full Element
const container = document.getElementById('questionPaper'); const container = document.getElementById('questionPaper');
const dropTarget = e.target; const dropTarget = e.target;
// console.log('dropTarget : ', dropTarget)
if (container.contains(dropTarget)) { if (container.contains(dropTarget)) {
//Before Insert OF the HTML Node //Before Insert OF the HTML Node
if (e.clientY < dropTarget.getBoundingClientRect().top + dropTarget.clientHeight / 2) { if (e.clientY < dropTarget.getBoundingClientRect().top + dropTarget.clientHeight / 2) {
@ -182,83 +183,117 @@ var draggedItem = null;
//THis function is Replicate the Nav Pane Change //THis function is Replicate the Nav Pane Change
function insertElement(dragStartElement, dragDropElement, position){ function insertElement(dragStartElement, dragDropElement, position){
var mainpaneSection = document.getElementById('addNewSection') var mainpaneSection = document.getElementById('addNewSection')
//Check All is true this for var matches = dragDropElement.id.match(/([a-zA-Z_]+)([0-9]+)/);
if (dragStartElement && dragDropElement && position) {
//Check IS before var Section = document.getElementById('question_area_'+matches[2]);
if (position == "before") { var innerElementCount = ''
//Check DragFirst Element have id if(Section){
if (!dragStartElement.id) { innerElementCount = Section.childElementCount;
var dragStartElementChild = dragStartElement.dragStartElementChild }
var maindragStartElement = mainpaneSection.querySelector(`#${dragStartElementChild.id.replace(/^nav_/, '')}`); else{
var maindragDropElement = mainpaneSection.querySelector(`#${dragDropElement.id.replace(/^nav_/, '')}`); innerElementCount = 1;
if (maindragStartElement && maindragDropElement && maindragStartElement !== maindragDropElement) { }
maindragDropElement.parentNode.insertBefore( maindragStartElement, maindragDropElement);
if(innerElementCount === 0){
var QuestionStartElement = mainpaneSection.querySelector(`#${dragStartElement.id.replace(/^nav_/, '')}`);
var QuestionDropElement = mainpaneSection.querySelector(`#${dragDropElement.id.replace(/^nav_/, '')}`);
//Check First Element is Group
if (QuestionStartElement.id.replace(/\d+/g, '') == "draggedGroup_") {
if (QuestionStartElement && Section && QuestionStartElement !== Section) {
Section.appendChild(QuestionStartElement)
} }
} else { } else {
var maindragStartElement = mainpaneSection.querySelector(`#${dragStartElement.id.replace(/^nav_/, '')}`); if (QuestionStartElement && Section && QuestionStartElement !== Section) {
var maindragDropElement = mainpaneSection.querySelector(`#${dragDropElement.id.replace(/^nav_/, '')}`); Section.appendChild(QuestionStartElement)
if (maindragStartElement && maindragDropElement && maindragStartElement !== maindragDropElement) {
maindragDropElement.parentNode.insertBefore( maindragStartElement, maindragDropElement);
} }
} }
}
// After element Node Added
else {
var maindragStartElement = mainpaneSection.querySelector(`#${dragStartElement.id.replace(/^nav_/, '')}`);
var maindragDropElement = mainpaneSection.querySelector(`#${dragDropElement.id.replace(/^nav_/, '')}`);
// End Element is Section }else{
if (maindragDropElement.id.replace(/\d+/g, '') == "section_title_") {
//Check First Element is Group //Check All is true this for
if (maindragStartElement.id.replace(/\d+/g, '') == "draggedGroup_") { if (dragStartElement && dragDropElement && position) {
var groupQuestionAddSection = maindragDropElement.nextElementSibling.querySelector('.section-question-area')
//Check IS before
if (position == "before") {
//Check DragFirst Element have id
if (!dragStartElement.id) {
var dragStartElementChild = dragStartElement.dragStartElementChild
var maindragStartElement = mainpaneSection.querySelector(`#${dragStartElementChild.id.replace(/^nav_/, '')}`);
var maindragDropElement = mainpaneSection.querySelector(`#${dragDropElement.id.replace(/^nav_/, '')}`);
if (maindragStartElement && maindragDropElement && maindragStartElement !== maindragDropElement) { if (maindragStartElement && maindragDropElement && maindragStartElement !== maindragDropElement) {
groupQuestionAddSection.appendChild(maindragStartElement) maindragDropElement.parentNode.insertBefore( maindragStartElement, maindragDropElement);
// test.parentNode.insertBefore(maindragStartElement, test)
} }
} else { } else {
var textAndChoiceAddSection = maindragDropElement.nextElementSibling.querySelector('.section-question-area'); var maindragStartElement = mainpaneSection.querySelector(`#${dragStartElement.id.replace(/^nav_/, '')}`);
var maindragDropElement = mainpaneSection.querySelector(`#${dragDropElement.id.replace(/^nav_/, '')}`);
if (maindragStartElement && maindragDropElement && maindragStartElement !== maindragDropElement) { if (maindragStartElement && maindragDropElement && maindragStartElement !== maindragDropElement) {
textAndChoiceAddSection.parentNode.insertBefore(maindragStartElement, textAndChoiceAddSection) maindragDropElement.parentNode.insertBefore( maindragStartElement, maindragDropElement);
} }
} }
} }
//Check the Second Element is Group Question // After element Node Added
else if(maindragDropElement.id.replace(/\d+/g, '') == "draggedGroup_"){ else {
//Check First Element is Group Question var maindragStartElement = mainpaneSection.querySelector(`#${dragStartElement.id.replace(/^nav_/, '')}`);
if (maindragStartElement.id.replace(/\d+/g, '') == "draggedGroup_") { var maindragDropElement = mainpaneSection.querySelector(`#${dragDropElement.id.replace(/^nav_/, '')}`);
var groupQuestionAddGroupQuestion = maindragDropElement.querySelector('.nested-sortable');
if (maindragStartElement && maindragDropElement && maindragStartElement !== maindragDropElement) { // End Element is Section
groupQuestionAddGroupQuestion.appendChild(maindragStartElement) if (maindragDropElement.id.replace(/\d+/g, '') == "section_title_") {
} //Check First Element is Group
} if (maindragStartElement.id.replace(/\d+/g, '') == "draggedGroup_") {
//This allows Text and Choice var groupQuestionAddSection = maindragDropElement.nextElementSibling.querySelector('.section-question-area')
else { if (maindragStartElement && maindragDropElement && maindragStartElement !== maindragDropElement) {
var groupQuestionAddTextChoice= maindragDropElement.querySelector('.nested-sortable').dragStartElementChild; groupQuestionAddSection.appendChild(maindragStartElement)
if (groupQuestionAddTextChoice) { // test.parentNode.insertBefore(maindragStartElement, test)
groupQuestionAddTextChoice.parentNode.insertBefore(maindragStartElement , groupQuestionAddTextChoice) }
} else { } else {
var groupQuestionAdd = maindragDropElement.querySelector('.nested-sortable') var textAndChoiceAddSection = maindragDropElement.nextElementSibling.querySelector('.section-question-area');
console.log(groupQuestionAdd); if (maindragStartElement && maindragDropElement && maindragStartElement !== maindragDropElement) {
groupQuestionAdd.appendChild(maindragStartElement) textAndChoiceAddSection.parentNode.insertBefore(maindragStartElement, textAndChoiceAddSection)
console.log(groupQuestionAdd); }
alert("111")
// test.parentNode.insertBefore(maindragStartElement , test)
} }
} }
}else{ //Check the Second Element is Group Question
maindragDropElement.parentNode.insertBefore(maindragStartElement , maindragDropElement) else if(maindragDropElement.id.replace(/\d+/g, '') == "draggedGroup_"){
//Check First Element is Group Question
if (maindragStartElement.id.replace(/\d+/g, '') == "draggedGroup_") {
var groupQuestionAddGroupQuestion = maindragDropElement.querySelector('.nested-sortable');
if (maindragStartElement && maindragDropElement && maindragStartElement !== maindragDropElement) {
groupQuestionAddGroupQuestion.appendChild(maindragStartElement)
}
}
//This allows Text and Choice
else {
var groupQuestionAddTextChoice= maindragDropElement.querySelector('.nested-sortable').dragStartElementChild;
if (groupQuestionAddTextChoice) {
groupQuestionAddTextChoice.parentNode.insertBefore(maindragStartElement , groupQuestionAddTextChoice)
} else {
var groupQuestionAdd = maindragDropElement.querySelector('.nested-sortable')
console.log(groupQuestionAdd);
groupQuestionAdd.appendChild(maindragStartElement)
console.log(groupQuestionAdd);
// alert("111")
// test.parentNode.insertBefore(maindragStartElement , test)
}
}
}else{
maindragDropElement.parentNode.insertBefore(maindragStartElement , maindragDropElement)
}
} }
} }
} //no need
//no need else {
else {
var maindragStartElement = mainpaneSection.querySelector(`#${dragStartElement.id.replace(/^nav_/, '')}`); console.log('ELSE');
var maindragDropElement = mainpaneSection.querySelector(`#${dragDropElement.id.replace(/^nav_/, '')}`); var maindragStartElement = mainpaneSection.querySelector(`#${dragStartElement.id.replace(/^nav_/, '')}`);
if (maindragStartElement && maindragDropElement && maindragStartElement !== maindragDropElement) { var maindragDropElement = mainpaneSection.querySelector(`#${dragDropElement.id.replace(/^nav_/, '')}`);
maindragDropElement.parentNode.insertBefore( maindragStartElement, maindragDropElement.nextElementSibling); if (maindragStartElement && maindragDropElement && maindragStartElement !== maindragDropElement) {
maindragDropElement.parentNode.insertBefore( maindragStartElement, maindragDropElement.nextElementSibling);
}
} }
} }
} }

View File

@ -5,17 +5,17 @@ function rtc_hide_and_show(rtcid) {
// console.log('hideid : ', hideid); // console.log('hideid : ', hideid);
// console.log('hide id :' + id) // console.log('hide id :' + id)
$(hideid).hide(); $(hideid).hide();
console.log('hide id :' + id); // console.log('hide id :' + id);
var showid = document.getElementById(rtcid); var showid = document.getElementById(rtcid);
$(showid).show(); $(showid).show();
console.log('Show id :' + rtcid) // console.log('Show id :' + rtcid)
localStorage.setItem('rtc',rtcid); localStorage.setItem('rtc',rtcid);
}; };
function add_button_hide_and_show(BtnID){ function add_button_hide_and_show(BtnID){
console.log('show id :'+BtnID) // console.log('show id :'+BtnID)
var id = localStorage.getItem('btn'); var id = localStorage.getItem('btn');
var hideid = document.getElementById(id); var hideid = document.getElementById(id);
// console.log('hide id :' + id); // console.log('hide id :' + id);