233 lines
9.7 KiB
JavaScript
233 lines
9.7 KiB
JavaScript
function json2nav() {
|
|
// console.clear();
|
|
|
|
$.fn.getTextQuestion = function(element_id) {
|
|
// var textQuestionId = 'textQuestionName_' + element_id;
|
|
var marks = document.getElementById('Text_Question_Marks_Id_' + element_id).value;
|
|
var questionType = document.getElementById('question_type_' + element_id).value;
|
|
var isMathEnabled = document.getElementById('titlemath_' + element_id).checked;
|
|
var questionTitle = "";
|
|
var textQuestionId = "";
|
|
|
|
if(isMathEnabled == true){
|
|
textQuestionId = 'textQuestiontitleMath_' + element_id;
|
|
}else{
|
|
textQuestionId = 'textQuestionName_' + element_id;
|
|
}
|
|
|
|
if(isMathEnabled == true){
|
|
|
|
questionTitle = document.getElementById('textQuestiontitleMath_' + element_id).value;
|
|
}else{
|
|
|
|
const element = document.getElementById('textQuestionName_' + element_id)
|
|
const previousElement = element.previousElementSibling;
|
|
var questionTitleData = previousElement.querySelector('.jodit-workplace').querySelector('.jodit-wysiwyg').innerHTML;
|
|
questionTitle = questionTitleData;
|
|
|
|
|
|
}
|
|
|
|
|
|
return {
|
|
"question": questionTitle,
|
|
"question_Id":textQuestionId,
|
|
"marks":marks,
|
|
"isMathEnabled":isMathEnabled,
|
|
"question_type":questionType
|
|
}
|
|
}
|
|
|
|
$.fn.getChoiceQuestion = function(element_id) {
|
|
|
|
// var choiceQuestionId = 'textQuestionName_' + element_id;
|
|
var marks = document.getElementById('Choice_Question_Marks_Id_' + element_id).value;
|
|
var questionType = document.getElementById('question_type_' + element_id).value;
|
|
var isMathEnabled = document.getElementById('titlemath_' + element_id).checked;
|
|
var questionTitle = "";
|
|
var choiceQuestionId = "";
|
|
|
|
if(isMathEnabled == true){
|
|
choiceQuestionId = 'textQuestiontitleMath_' + element_id;
|
|
}else{
|
|
choiceQuestionId = 'textQuestionName_' + element_id;
|
|
}
|
|
|
|
if(isMathEnabled == true){
|
|
|
|
questionTitle = document.getElementById('textQuestiontitleMath_' + element_id).value;
|
|
}else{
|
|
|
|
const element = document.getElementById('textQuestionName_' + element_id)
|
|
const previousElement = element.previousElementSibling;
|
|
var questionTitleData = previousElement.querySelector('.jodit-workplace').querySelector('.jodit-wysiwyg').innerHTML;
|
|
questionTitle = questionTitleData;
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
"question": questionTitle,
|
|
"question_Id":choiceQuestionId,
|
|
"marks":marks,
|
|
"isMathEnabled":isMathEnabled,
|
|
"question_type":questionType
|
|
}
|
|
}
|
|
|
|
|
|
$.fn.getQuestionsData = function(element_id, type = 'question') // type for single question or group question
|
|
{
|
|
// console.log('getQuestionsData - '+element_id);
|
|
|
|
var $questionArea = (type == 'question' ? $('#question_area_' + element_id) : $('#group_question_area_' + element_id));
|
|
// console.log('getQuestionsData');
|
|
// console.log($questionArea);
|
|
|
|
var questionsArr = [];
|
|
$questionArea.children("div").each(function(index, element) {
|
|
|
|
var questionRowID = (element.id).split("_").slice(-1)[0];
|
|
// console.log('row question' + questionRowID);
|
|
var question_type = document.getElementById('question_type_' + questionRowID);
|
|
// check whether current element is single question or question group
|
|
if (typeof question_type !== null && question_type != undefined) {
|
|
if (document.getElementById('question_type_' + questionRowID).value == 'text') {
|
|
//get text type question data
|
|
var textQuestion = $.fn.getTextQuestion(questionRowID);
|
|
questionsArr.push(textQuestion);
|
|
|
|
} else {
|
|
// console.log('get choice question');
|
|
//get choice type question data
|
|
var getChoiceQuestion = $.fn.getChoiceQuestion(questionRowID);
|
|
questionsArr.push(getChoiceQuestion)
|
|
}
|
|
} else // handle question group
|
|
{
|
|
// console.log('QUESTION GROUP');
|
|
// console.log('row question' + questionRowID);
|
|
var questionGroupData = $.fn.getQuestionQroupData(element);
|
|
questionsArr.push(questionGroupData)
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
return questionsArr
|
|
}
|
|
|
|
$.fn.getQuestionQroupData = function(element) {
|
|
// console.log('getSectionData');
|
|
// console.log(element.id);
|
|
const rand_id = (element.id).split("_").slice(-1)[0];
|
|
// console.log(rand_id);
|
|
// console.log('section_title_text_'+rand_id);
|
|
var groupQuestion = {}
|
|
|
|
const groupelement = document.getElementById('subSection_title_text_' + rand_id);
|
|
const previousElement = groupelement.previousElementSibling;
|
|
var group_title_data = previousElement.querySelector('.jodit-workplace').querySelector('.jodit-wysiwyg').innerHTML;
|
|
|
|
var group_title = group_title_data;
|
|
var group_attempt_any = document.getElementById('Question_Attempt_Any_Id_' + rand_id);
|
|
var group_marks = document.getElementById('Question_Group_Marks_Id_' + rand_id);
|
|
|
|
groupQuestion['group_title'] = ((typeof group_title !== null && group_title !== 'undefined') ? (group_title !== null ? group_title : null) : null);
|
|
groupQuestion['question_group_id'] = 'subSection_title_text_' + rand_id;
|
|
groupQuestion['group_attempt_any'] = ((typeof group_attempt_any !== null && group_attempt_any !== 'undefined') ? (group_attempt_any !== null ? group_attempt_any.value : null) : null);
|
|
groupQuestion['group_marks'] = ((typeof group_marks !== null && group_marks !== 'undefined') ? (group_marks !== null ? group_marks.value : null) : null);
|
|
groupQuestion['question_type'] = 'question_group';
|
|
if (group_title !== null) {
|
|
var questionsData = $.fn.getQuestionsData(rand_id, 'group');
|
|
groupQuestion['questions'] = questionsData;
|
|
return groupQuestion;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
$.fn.getSectionDataNavigation = function(element) {
|
|
// console.log('getSectionData');
|
|
// console.log(element.id);
|
|
const rand_id = (element.id).split("_").slice(-1)[0];
|
|
// console.log(rand_id);
|
|
// console.log('section_title_text_'+rand_id);
|
|
var section = {}
|
|
|
|
const sectionelement = document.getElementById('section_title_text_' + rand_id);
|
|
const previousElement = sectionelement.previousElementSibling;
|
|
var section_title_data = previousElement.querySelector('.jodit-workplace').querySelector('.jodit-wysiwyg').innerHTML;
|
|
|
|
|
|
var section_title = section_title_data;
|
|
var section_marks = document.getElementById('Section_Marks_Id_' + rand_id);
|
|
var section_attempt_any = document.getElementById('Section_Attempt_Any_Id_' + rand_id);
|
|
// console.log('section title in nav script');
|
|
// console.log(section_title);
|
|
// section['section_title'] = ((section_title !== null && section_title !== 'undefined') ? (section_title !== null ? section_title.innerHTML : null) : null);
|
|
section['section_title'] = ((typeof section_title !== null && section_title !== 'undefined') ? (section_title !== null ? section_title : null) : null);
|
|
section['section_id'] = 'section_title_text_' + rand_id;
|
|
section['section_attempt_any'] = ((typeof section_attempt_any !== null && section_attempt_any !== 'undefined') ? (section_attempt_any !== null ? section_attempt_any.value : null) : null);
|
|
section['section_marks'] = ((typeof section_marks !== null && section_marks !== 'undefined') ? (section_marks !== null ? section_marks.value : null) : null);
|
|
|
|
if (section_title !== null) {
|
|
var questionsData = $.fn.getQuestionsData(rand_id);
|
|
// console.log('Section Data');
|
|
// console.log(questionsData);
|
|
section['questions'] = questionsData;
|
|
return section;
|
|
}
|
|
|
|
}
|
|
|
|
var formData = {};
|
|
|
|
var questionTitleElement = document.getElementById('questionTitleValue');
|
|
|
|
var questionTitleData = '';
|
|
if (questionTitleElement) {
|
|
|
|
var joditWysiwygElement = questionTitleElement.querySelector('.jodit-wysiwyg');
|
|
var questionTitleData = joditWysiwygElement.innerHTML;
|
|
|
|
} else {
|
|
|
|
questionTitleData = document.getElementById('Question_title').innerHTML;
|
|
}
|
|
|
|
|
|
// console.log(questionPaperTitleData);
|
|
|
|
|
|
var question_paper_title = questionTitleData;
|
|
formData['question_paper_title'] = question_paper_title;
|
|
formData['Question_title_id'] = 'Question_title';
|
|
formData['sections'] = [];
|
|
// console.log(formData);
|
|
// return False;
|
|
|
|
var $parentSectionElement = $("#addNewSection");
|
|
$parentSectionElement.find(".section").each(function(index, element) {
|
|
// console.log(element);
|
|
// if(index == 2){return false;}
|
|
var sectionData = $.fn.getSectionDataNavigation(element);
|
|
// console.log('sectionData:',sectionData);
|
|
if (sectionData !== null && sectionData !== undefined) {
|
|
formData['sections'].push(sectionData);
|
|
}
|
|
|
|
});
|
|
|
|
// console.log((formData));
|
|
// console.log(JSON.stringify(formData, null, 1));
|
|
localStorage.setItem("JSON_FOR_NAV", JSON.stringify((formData)));
|
|
// console.log('JSON_FOR_NAV');
|
|
// console.log('*********************************************************************************');
|
|
// console.log(JSON.stringify(formData));
|
|
// console.log('*********************************************************************************');
|
|
|
|
// console.log(OBJtoXML(({'question_paper' : formData})));
|
|
}
|