diff --git a/QuestionPreview.html b/QuestionPreview.html index b97b616..79355cf 100644 --- a/QuestionPreview.html +++ b/QuestionPreview.html @@ -615,6 +615,7 @@ function loadXML(xmlFileName) { if(filelist !== false) { //JSON File Read Function + console.log(encodedJsonFilePath); fs.readFile(encodedJsonFilePath, 'utf8', (error, data) => { if (error) { console.error('Error reading file:', error); diff --git a/addform.html b/addform.html index a2c266d..dfa3b65 100644 --- a/addform.html +++ b/addform.html @@ -1017,10 +1017,6 @@ async function sendMessage() { var workarea = document.getElementById('workarea').innerHTML; var mathField = document.getElementById('workarea_math'); - // console.log("workarea",workarea); - // console.log("mathField",mathField); - // console.log("messagesContainer",messagesContainer); - var content = ''; // Check if the checkbox is checked @@ -1035,7 +1031,6 @@ async function sendMessage() { } - // console.log("Message Content: ", content); if (content !== '') { @@ -2572,7 +2567,7 @@ function addQuestionGroup(idObj) array_of_Id.push('Questions_Group_id_' + QuestionGroup_ID); - array_of_Id.push('subSectionDescriptionWorkarea_' + QuestionGroup_ID); + array_of_Id.push('subSection_description_text_' + QuestionGroup_ID); array_of_Id.push('subSection_title_text_' + QuestionGroup_ID); @@ -2787,11 +2782,15 @@ function addQuestionGroup(idObj) addListenersToButtons(question_groupid); }, 1000); - var question_group_description = 'subSectionDescriptionWorkarea_'+ QuestionGroup_ID; - var inputElemen = document.getElementById(question_group_description); - attrId = document.getElementById('subSectionDescriptionWorkarea_'+ QuestionGroup_ID).innerHTML; + var question_group_description= 'subSection_description_text_'+ QuestionGroup_ID; + var inputElements = document.getElementById(question_group_description); + + var previousElements = inputElements.previousElementSibling; + var innerDivElements = previousElements.querySelector('.jodit-workplace').querySelector('.jodit-wysiwyg'); - inputElemen.addEventListener("keyup", function(event) { + attrId = document.getElementById('subSection_description_text_'+ QuestionGroup_ID).innerHTML; + + innerDivElements.addEventListener("keyup", function(event) { json2nav(); clearSidebarWrapper(); @@ -2799,12 +2798,32 @@ function addQuestionGroup(idObj) check_Remove_Empty_Question(question_group_description); // SetQuestionGroupTitle(QuestionGroup_ID, QuestionGroup_ID) - }); + const targetIds = 'subSection_description_text_' + QuestionGroup_ID; + localStorage.setItem('savePreventDefault', targetIds); + }); setInterval(function() { addListenersToButtons(question_group_description); }, 1000); + // var question_group_description = 'subSectionDescriptionWorkarea_'+ QuestionGroup_ID; + // var inputElemen = document.getElementById(question_group_description); + // attrId = document.getElementById('subSectionDescriptionWorkarea_'+ QuestionGroup_ID).innerHTML; + + // inputElemen.addEventListener("keyup", function(event) { + + // json2nav(); + // clearSidebarWrapper(); + // navpane(); + // check_Remove_Empty_Question(question_group_description); + // // SetQuestionGroupTitle(QuestionGroup_ID, QuestionGroup_ID) + + // }); + + // setInterval(function() { + // addListenersToButtons(question_group_description); + // }, 1000); + var question_groupi = 'Questions_Group_id_'+ QuestionGroup_ID; var inputElemen = document.getElementById(question_groupi); attrId = document.getElementById('Questions_Group_id_'+ QuestionGroup_ID).innerHTML; @@ -2896,7 +2915,6 @@ function addQuestionGroup(idObj) } const arrayString = JSON.stringify(array_of_Id); - // console.log("2"); collect_Empty_Question_Id(arrayString, question_groupid); // SetQuestionGroupTitle(QuestionGroup_ID, QuestionGroup_ID) @@ -4268,15 +4286,6 @@ fileInput2.addEventListener("change", () => { const titleRTCID = 'textTitleRtc_'+idParts rtc_hide_and_show(titleRTCID); }); - - // console.log("AAdhavj"); - // const textSerialNumber = document.getElementById(`QuestionTextIdSet_${addTextQuestionId}`); - // if (textSerialNumber) { - // console.log(textSerialNumber); - // textSerialNumber.focus(); - - - // } @@ -4641,7 +4650,6 @@ function collect_Empty_Question_Id(arrayString, ID) { // console.log('attrId : ', attrId); var value = localStorage.getItem('EditNavExpend'); // console.log(value); - if (!value && attrId === '' || attrId === '


') { // console.log('JSON_FOR_EMPTY_QUESTION localstorage set'); @@ -4660,7 +4668,6 @@ function check_Empty_Question() // console.log("Check Empty Enter"); var title_id = localStorage.getItem('JSON_FOR_EMPTY_QUESTION'); - // console.log('check_Empty_Question JSON_FOR_EMPTY_QUESTION', title_id); var attrId = ''; var questionpapertitleid = 'Question_title'; if (title_id) { @@ -4672,7 +4679,6 @@ function check_Empty_Question() if (index === array.length - 1) { var idclass= document.getElementById(Id); - console.log(idclass); // console.log(idclass == "QuestionTextIdSet SerialNo"); if (idclass == '' || idclass == null) { @@ -4693,13 +4699,11 @@ function check_Empty_Question() }else{ - console.log("else"); const previousElement = elementid.previousElementSibling; + if (previousElement == null) { - console.log("inner if"); attrId =elementid; } else { - console.log("inner else"); var value = '' if(getMathFiled == 'textQuestiontitleMath_' || Id == "Max_Marks"){ value = elementid.value; @@ -4710,13 +4714,10 @@ function check_Empty_Question() } } } - console.log(attrId); if(attrId === '


' || attrId === '



') { - // console.log("Check empty if"); if(Id === 'Question_title'){ var elementID = document.getElementById('Question_title_workarea') - console.log(elementID); // var elementID = document.querySelector('.jodit-workplace').querySelector('.jodit-wysiwyg'); elementID.scrollIntoView({ behavior: "smooth", block: "center" }); elementID.focus(); @@ -4758,8 +4759,8 @@ function check_Empty_Question() //if the Question has not empty then remove the id from the array if empty than again push id to array function check_Remove_Empty_Question(IdToRemove , DeleteElement=0) { - console.log('IdToRemove : ', IdToRemove); + var attrId; var title_id = localStorage.getItem('JSON_FOR_EMPTY_QUESTION'); var attrId= ''; @@ -4787,14 +4788,9 @@ function check_Remove_Empty_Question(IdToRemove , DeleteElement=0) { if(newVariableWithoutNumbers == 'QuestionTextIdSet_' || newVariableWithoutNumbers == 'QuestionChoiceId_' || newVariableWithoutNumbers == 'Questions_Group_id_' || newVariableWithoutNumbers == 'textQuestiontitleMath_' || IdToRemove == "Max_Marks"){ attrId = input_text_value.value; } - else if(newVariableWithoutNumbers == "subSectionDescriptionWorkarea_"){ + else if(newVariableWithoutNumbers == "subSection_description_text_"){ var subSectionDescription = document.getElementById(IdToRemove).querySelector('p').innerHTML; - attrId= subSectionDescription - // console.log(subSectionDescription == '
'); - // if(subSectionDescription !== '
' ){ - // attrId= subSectionDescription; - // // attrId =''; - // } + attrId =subSectionDescription; } else{ const previousElement = input_text_value.previousElementSibling; @@ -4804,98 +4800,77 @@ function check_Remove_Empty_Question(IdToRemove , DeleteElement=0) { } var parsedArray = []; - if (count !== 0) { - - - - parsedArray = JSON.parse(title_id); - console.log('attrId 2 : ', attrId); - - if(attrId === '' || attrId === '



' || attrId === '


' || attrId === '
') { - - // alert('1'); + parsedArray = JSON.parse(title_id); + if(attrId === '' || attrId === '



' || attrId === '


' || attrId === '
') { + if (!parsedArray.includes(IdToRemove)) { + var newArray = parsedArray.push(IdToRemove); + } + const newArrayString = JSON.stringify(parsedArray); + collect_Empty_Question_Id(newArrayString); + } else{ + for (let i = 0; i < parsedArray.length; i++) { + const Id = parsedArray[i]; + const element = document.getElementById(Id); + if (element) { + if (DeleteElement != 1) { + const attrId = element.innerHTML; + } + if (Id === IdToRemove && DeleteElement ==0) { + if (attrId !== '


' && attrId !== "" ) { + parsedArray.splice(i, 1); + i--; + } + } + else if (DeleteElement) + { + if (Id === IdToRemove ) { + parsedArray.splice(i, 1); + i--; + } + } + else if(Id === IdToRemove) + { + parsedArray.splice(i, 1); + i--; + } + else + { + if (!parsedArray.includes(IdToRemove)) { + var newArray = parsedArray.push(IdToRemove); + } + const newArrayString = JSON.stringify(newArray); + collect_Empty_Question_Id(newArrayString); + } + } + } + const newArrayString = JSON.stringify(parsedArray); + collect_Empty_Question_Id(newArrayString); + } + } + else if(attrId === '' || attrId == '


' || attrId === '



' || attrId === '
') + { if (!parsedArray.includes(IdToRemove)) { var newArray = parsedArray.push(IdToRemove); } const newArrayString = JSON.stringify(parsedArray); collect_Empty_Question_Id(newArrayString); - - } else{ - - // alert('2'); - for (let i = 0; i < parsedArray.length; i++) { - const Id = parsedArray[i]; - const element = document.getElementById(Id); - if (element) { - - if (DeleteElement != 1) { - const attrId = element.innerHTML; - } - - if (Id === IdToRemove && DeleteElement ==0) { - // console.log("Id === IdToRemove && DeleteElement ==0"); - if (attrId !== '


' && attrId !== "" ) { - // console.log("Id === IdToRemove && DeleteElement ==0 in if conditions"); - parsedArray.splice(i, 1); - i--; - } - - }else if (DeleteElement) { - if (Id === IdToRemove ) { - parsedArray.splice(i, 1); - i--; - } - }else if(Id === IdToRemove){ - // console.log('Id === IdToRemove'); - parsedArray.splice(i, 1); - i--; - } - else{ - // console.log("last part"); - if (!parsedArray.includes(IdToRemove)) { - var newArray = parsedArray.push(IdToRemove); - } - const newArrayString = JSON.stringify(newArray); - collect_Empty_Question_Id(newArrayString); - } - } - } - const newArrayString = JSON.stringify(parsedArray); - collect_Empty_Question_Id(newArrayString); } - } - else if(attrId === '' || attrId == '


' || attrId === '



' || attrId === '
') { - - // alert('3') - // console.log('check empty question : ', attrId); - if (!parsedArray.includes(IdToRemove)) { - var newArray = parsedArray.push(IdToRemove); - } - const newArrayString = JSON.stringify(parsedArray); - // console.log(newArrayString); - collect_Empty_Question_Id(newArrayString); - } - var title_i = localStorage.getItem('JSON_FOR_EMPTY_QUESTION'); + var title_i = localStorage.getItem('JSON_FOR_EMPTY_QUESTION'); var parsedArra = JSON.parse(title_i); - var againpushlist =[]; - if (parsedArra) { - parsedArra.forEach(function (para) { - - againpushlist.push(para) - array_of_Id=againpushlist; - // console.log(array_of_Id); - }) - } - - var myArray = localStorage.getItem('JSON_FOR_EMPTY_QUESTION'); + var againpushlist =[]; + if (parsedArra) { + parsedArra.forEach(function (para) { + againpushlist.push(para) + array_of_Id=againpushlist; + }) + } + var myArray = localStorage.getItem('JSON_FOR_EMPTY_QUESTION'); if(myArray !== null && myArray !== undefined){ var idOfArray = removeNonExistentIds(myArray) - // console.log(idOfArray); localStorage.setItem('JSON_FOR_EMPTY_QUESTION', JSON.stringify(idOfArray)); } - } //set the current position to localstorage @@ -4916,10 +4891,7 @@ window.addEventListener('scroll', saveScrollPosition); function ReArrangeQuestions(e){ var currentID= e.target.parentElement.parentElement.parentElement.id; - // console.log(currentID) var currentItemID = document.getElementById(currentID); - // console.log('currentItemID'); - // console.log(currentItemID); if (e.target.classList.contains('up-icon')) { @@ -5016,16 +4988,12 @@ function scrollToElementWithoutLink(elementId) { // console.log(modifiedA); const element = document.getElementById(elementId); if (element) { - // console.log('true'); - if (modifiedA == 'section_title_text_' || modifiedA == 'textQuestionName_' || modifiedA == 'subSection_title_text_') { - - // console.log('1'); + if (modifiedA == 'section_title_text_' || modifiedA == 'textQuestionName_' || modifiedA == 'subSection_title_text_' || modifiedA == 'subSection_description_text_') { const previousElement = element.previousElementSibling; var focus = previousElement.querySelector('.jodit-workplace').querySelector('.jodit-wysiwyg'); focus.scrollIntoView({ behavior: "smooth", block: "center" }); } else{ - // console.log('2'); element.scrollIntoView({ behavior: "smooth", block: "center" }); } if (modifiedA == 'removeAndCloneQroupQuestion_') { @@ -5039,15 +5007,13 @@ function scrollToElementWithoutLink(elementId) { } - if (modifiedA == 'section_title_text_' || modifiedA == 'textQuestionName_' || modifiedA == 'subSection_title_text_') { + if (modifiedA == 'section_title_text_' || modifiedA == 'textQuestionName_' || modifiedA == 'subSection_title_text_' || modifiedA == 'subSection_description_text_') { - // console.log('1'); const previousElement = element.previousElementSibling; var focus = previousElement.querySelector('.jodit-workplace').querySelector('.jodit-wysiwyg'); focus.focus(); } else{ - // console.log('2'); element.focus(); } @@ -5155,9 +5121,7 @@ function removeClonedTextQuestion(index) var myArray = localStorage.getItem('JSON_FOR_EMPTY_QUESTION'); if(myArray !== null && myArray !== undefined){ var idOfArray = removeNonExistentIds(myArray) - // console.log(idOfArray); localStorage.setItem('JSON_FOR_EMPTY_QUESTION', JSON.stringify(idOfArray)); - // console.log(localStorage.getItem('JSON_FOR_EMPTY_QUESTION')); } element.remove(); @@ -5170,7 +5134,6 @@ function removeClonedTextQuestion(index) // remove the cloned choice or group type questions function function removeClonedQroupQuestion(index) { - // console.log(index); var element = document.getElementById('removeAndCloneQroupQuestion_'+ index); if (element) { var GroupTextQuestionTitle = 'textQuestionName_'+index; @@ -5284,8 +5247,8 @@ function removeQuestionGroup(index) { if (element) { var GroupQuestionTitle = 'subSection_title_text_'+index; check_Remove_Empty_Question(GroupQuestionTitle,1); - var GroupQuestionDescription = 'subSectionDescriptionWorkarea_'+index; - check_Remove_Empty_Question(GroupQuestionDescription) + var GroupQuestionDescription = 'subSection_description_text_'+index; + check_Remove_Empty_Question(GroupQuestionDescription,1) var GroupQuestionSerialNo = 'idOfArrayQuestions_Group_id_'+index; check_Remove_Empty_Question(GroupQuestionSerialNo,1); element.remove(); @@ -5524,7 +5487,6 @@ document.body.removeEventListener('click', clickOutsideHandler); // Function to execute the script and display its output in the popup function executeScriptAndDisplayOutput() { -// console.log("dddddddddddddddddddddddddddddddddddddddddddddddddddd"); const popups = document.getElementById("output"); popups.innerHTML = ""; // Display the popup with the output @@ -5535,7 +5497,6 @@ const jsonData = JSON.parse(localStorage.getItem('JSON_FOR_NAV')); const reorderpop = document.getElementById('output'); const addsection= document.querySelector('#addNewSection'); // Replace with your actual right list ID -// console.log("addsection:",addsection); // Function to add a section name to the left side function addSectionName(section) { @@ -5777,7 +5738,6 @@ if (!parsedArray.includes(e.id)) { parsedArray.push(e.id); const arrayString = JSON.stringify(parsedArray); - collect_Empty_Question_Id(arrayString); localStorage.setItem('JSON_FOR_EMPTY_QUESTION', arrayString); } @@ -5891,7 +5851,6 @@ setInterval(addTitleforTable,2000) @@ -6274,7 +6232,7 @@ document.addEventListener('keyup', nagvigationAlgimnetDragandDrop); - + + + + diff --git a/dashboard.html b/dashboard.html index faa7a39..5c350fc 100644 --- a/dashboard.html +++ b/dashboard.html @@ -749,13 +749,59 @@ function duplicateFile(oldfilename) { if(isEncrypted == 'YES'){ - const decodeData = decode(xmlFilePath); - const encodeData = encode(decodeData, filePathToSave); - if(fileList !== false) - { - const jsonDecodeData = decode(jsonFilePath); - const jsonEncodeData = encode(jsonDecodeData, jsonFilePathToSave); + // const content = fs.readFileSync(`${xmlFilePath}${oldfilename}`, 'utf-8'); + const content =decode(`${xmlFilePath}${oldfilename}`); + const encrypt = encode(content); + try { + fs.writeFileSync(`${xmlFilePath}${entervalue}.xml`, encrypt, 'utf-8'); + Swal.fire({ + title: "File Duplicated", + icon: "success" + }); + } catch (err) { + let errorMessage = ""; + if (err.code === 'EACCES') { + errorMessage = `Permission Denied.
Path: ${filePathToSave}`; + } else if (err.code === 'ENOENT') { + errorMessage = `No Such File Directory.
Path: ${filePathToSave}`; + } else { + errorMessage = `Unknown Error.
Path: ${filePathToSave}`; + } + Swal.fire({ + title: "File Duplicate Failed", + html: errorMessage, + icon: "error" + }); } + + if (fileList !== false) + { + try { + const content =decode(jsonFilePath); + const encrypt = encode(content); + // console.log('json', content); + fs.writeFileSync(`${jsonFilePathToSave}${newJsonFileName}`, encrypt, 'utf-8'); + Swal.fire({ + title: "File Duplicated", + icon: "success" + }); + } catch (err) { + let errorMessage = ""; + if (err.code === 'EACCES') { + errorMessage = `Permission Denied.
Path: ${jsonFilePathToSave}`; + } else if (err.code === 'ENOENT') { + errorMessage = `No Such File Directory.
Path: ${jsonFilePathToSave}`; + } else { + errorMessage = `Unknown Error.
Path: ${jsonFilePathToSave}`; + } + Swal.fire({ + title: "File Duplicate Failed", + html: errorMessage, + icon: "error" + }); + } + } + }else{ try { const content = fs.readFileSync(`${xmlFilePath}${oldfilename}`, 'utf-8'); diff --git a/xml2json_for_Questionpaper_preview.js b/xml2json_for_Questionpaper_preview.js index e3cd81f..b41858a 100644 --- a/xml2json_for_Questionpaper_preview.js +++ b/xml2json_for_Questionpaper_preview.js @@ -120,6 +120,7 @@ function getQuestionGroupNodes(questionGroup) //busi logic start +console.log(xmlData); var xmlString = xmlData; const parser = new DOMParser(); @@ -133,6 +134,7 @@ jsonObj['attributes'] = getAttributesOfXMLNode(xmlDoc.documentElement); jsonObj['sections'] = []; + sectionsList = xmlDoc.getElementsByTagName("Items")[0].childNodes; // console.log(sectionsList); // console.log('no of sections:'+sectionsList.length);