INITIAL_COMMIT : RV
This commit is contained in:
parent
34740eb09d
commit
64dc8a7133
@ -26,4 +26,11 @@ This README would normally document whatever steps are necessary to get your app
|
||||
### Who do I talk to? ###
|
||||
|
||||
* Repo owner or admin
|
||||
* Other community or team contact
|
||||
* Other community or team contact
|
||||
|
||||
|
||||
### Replace Quill to Jodit ##
|
||||
|
||||
* 06-01-2024 Saturday 11:28 AM
|
||||
* Reason : Quill Table is Not Working Properly
|
||||
* So we prefer JODIT Text editor
|
||||
1337
addform.html
1337
addform.html
File diff suppressed because it is too large
Load Diff
2688
addform_old.html
2688
addform_old.html
File diff suppressed because it is too large
Load Diff
224
html2json_old.js
224
html2json_old.js
@ -1,224 +0,0 @@
|
||||
function html2json() {
|
||||
// console.clear();
|
||||
|
||||
$.fn.getTextQuestion = function(element_id) {
|
||||
var questionTitle = document.getElementById('textQuestionName_' + element_id).querySelector('.ql-editor').innerHTML;
|
||||
var isMathEnabled = document.getElementById('math_' + element_id).checked;
|
||||
var questionSubTitle = "";
|
||||
if(isMathEnabled == true)
|
||||
{
|
||||
questionSubTitle = document.getElementById('textQuestionSubtitle_math_' + element_id).value;
|
||||
}
|
||||
else
|
||||
{
|
||||
questionSubTitle = document.getElementById('textQuestionSubtitle_' + element_id).querySelector('.ql-editor').innerHTML;
|
||||
}
|
||||
var questionType = document.getElementById('question_type_' + element_id).value;
|
||||
var questionSubType = document.getElementById('longAnswer_' + element_id).checked;
|
||||
|
||||
return {
|
||||
"question": questionTitle,
|
||||
"question_description": questionSubTitle,
|
||||
"question_type": questionType,
|
||||
"question_sub_type": questionSubType,
|
||||
"is_math_enabled": isMathEnabled
|
||||
}
|
||||
}
|
||||
|
||||
$.fn.getChoiceQuestion = function(element_id) {
|
||||
|
||||
var questionTitle = document.getElementById('textQuestionName_' + element_id).querySelector('.ql-editor').innerHTML;
|
||||
var isMathEnabled = document.getElementById('math_' + element_id).checked;
|
||||
var questionSubTitle = "";
|
||||
if(isMathEnabled == true)
|
||||
{
|
||||
questionSubTitle = document.getElementById('textQuestionSubtitle_math_' + element_id).value;
|
||||
}
|
||||
else
|
||||
{
|
||||
questionSubTitle = document.getElementById('textQuestionSubtitle_' + element_id).querySelector('.ql-editor').innerHTML;
|
||||
}
|
||||
var questionType = document.getElementById('question_type_' + element_id).value;
|
||||
var questionSubType = document.getElementById('multipleAnswer_' + element_id).checked;
|
||||
var answers = [];
|
||||
|
||||
//get choice group
|
||||
|
||||
//get default choice details
|
||||
var choice_name = "";
|
||||
if(isMathEnabled == true)
|
||||
{
|
||||
choice_name = document.getElementById('choiceTextField_math_' + element_id).value;
|
||||
}
|
||||
else
|
||||
{
|
||||
choice_name = document.getElementById('choiceTextField_' + element_id).querySelector('.ql-editor').innerHTML;
|
||||
}
|
||||
var choice_description = document.getElementById('commentField_' + element_id).value;
|
||||
// var choice_image = document.getElementById('imageInput_' + element_id).value;
|
||||
answers.push({
|
||||
"choice_name": choice_name,
|
||||
"choice_description": choice_description
|
||||
});
|
||||
|
||||
// console.log('before group');
|
||||
//get dynamically added choice detailscolor: #999;
|
||||
var $newlyAddedChoices = $('#addChoiceArea_' + element_id);
|
||||
|
||||
$newlyAddedChoices.children().each(function(index, element) {
|
||||
|
||||
var groupChoiceId = ((element.id).split('_').slice(-1)[0]).split('.').slice(0)[0];
|
||||
var individualChoiceId = (element.id).split('.').slice(-1)[0];
|
||||
// console.log('newChoiceTextField_'+groupChoiceId+'.'+individualChoiceId);
|
||||
var choice_name = "";
|
||||
if(isMathEnabled == true)
|
||||
{
|
||||
choice_name = document.getElementById('newchoiceTextField_math_' + groupChoiceId + '.' + individualChoiceId).value;
|
||||
}
|
||||
else
|
||||
{
|
||||
choice_name = document.getElementById('newChoiceTextField_' + groupChoiceId + '.' + individualChoiceId).querySelector('.ql-editor').innerHTML;
|
||||
}
|
||||
// console.log('choice_description id in the html to json script');
|
||||
var id = document.getElementById('newChoiceCommentField_' + groupChoiceId + '.' + individualChoiceId);
|
||||
// console.log(id);
|
||||
var choice_description = document.getElementById('newChoiceCommentField_' + groupChoiceId + '.' + individualChoiceId).value;
|
||||
|
||||
|
||||
// var choice_image = document.getElementById('newChoiceImageInput_' + groupChoiceId + '.' + individualChoiceId).value;
|
||||
|
||||
answers.push({
|
||||
"choice_name": choice_name,
|
||||
"choice_description": choice_description,
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
return {
|
||||
"question": questionTitle,
|
||||
"question_description": questionSubTitle,
|
||||
"question_type": questionType,
|
||||
"question_sub_type": questionSubType,
|
||||
"is_math_enabled": isMathEnabled,
|
||||
"answers": answers
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$.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 = {}
|
||||
var group_title = document.getElementById('subSection_title_text_' + rand_id);
|
||||
var group_description = document.getElementById('subSection_description_text_' + rand_id);
|
||||
groupQuestion['group_title'] = ((typeof group_title !== null && group_title !== 'undefined') ? (group_title !== null ? group_title.querySelector('.ql-editor').innerHTML : null) : null);
|
||||
groupQuestion['group_description'] = ((typeof group_description !== null && group_description !== 'undefined') ? (group_description !== null ? group_description.querySelector('.ql-editor').innerHTML : null) : null);
|
||||
|
||||
if (group_title !== null) {
|
||||
var questionsData = $.fn.getQuestionsData(rand_id, 'group');
|
||||
// console.log('Section Data');
|
||||
// console.log(questionsData);
|
||||
groupQuestion['questions'] = questionsData;
|
||||
return groupQuestion;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
$.fn.getSectionData = 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 = {}
|
||||
var section_title = document.getElementById('section_title_text_' + rand_id);
|
||||
var section_description = document.getElementById('section_description_text_' + rand_id);
|
||||
section['section_title'] = ((typeof section_title !== null && section_title !== 'undefined') ? (section_title !== null ? section_title.querySelector('.ql-editor').innerHTML : null) : null);
|
||||
section['section_description'] = ((typeof section_description !== null && section_description !== 'undefined') ? (section_description !== null ? section_description.querySelector('.ql-editor').innerHTML : 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 question_paper_title = document.getElementById('Question_title').querySelector('.ql-editor').innerHTML;
|
||||
var question_paper_description = document.getElementById('Question_description').querySelector('.ql-editor').innerHTML;
|
||||
formData['question_paper_title'] = question_paper_title;
|
||||
formData['question_paper_description'] = question_paper_description;
|
||||
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.getSectionData(element);
|
||||
// console.log(sectionData);
|
||||
if (sectionData !== null && sectionData !== undefined) {
|
||||
formData['sections'].push(sectionData);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// console.log((formData));
|
||||
// console.log(JSON.stringify(formData, null, 1));
|
||||
localStorage.setItem("json", JSON.stringify((formData)));
|
||||
console.log(JSON.stringify(formData));
|
||||
// console.log(OBJtoXML(({'question_paper' : formData})));
|
||||
}
|
||||
3441
style_old.css
3441
style_old.css
File diff suppressed because it is too large
Load Diff
157
xml2json_old.js
157
xml2json_old.js
@ -1,157 +0,0 @@
|
||||
|
||||
function xml2json(xmlData) {
|
||||
// console.clear();
|
||||
console.log('xml to json converstion');
|
||||
console.log(xmlData);
|
||||
|
||||
function getAttributesOfXMLNode(node)
|
||||
{
|
||||
// Get attributes of the node (if any)
|
||||
attributes = {};
|
||||
if (node.attributes.length > 0) {
|
||||
for (let i = 0; i < node.attributes.length; i++) {
|
||||
const attribute = node.attributes[i];
|
||||
attributes[attribute.nodeName] = attribute.nodeValue;
|
||||
}
|
||||
}
|
||||
|
||||
return attributes;
|
||||
}
|
||||
|
||||
function getQuestionsNodes(questionNode,type)
|
||||
{
|
||||
// console.log(questionNode);
|
||||
var questionObj = {};
|
||||
if(type == 1)
|
||||
{
|
||||
questionObj['question'] = questionNode.childNodes[0].firstChild.nodeValue;
|
||||
questionObj['question_description'] = (questionNode.childNodes[1].firstChild !== null? questionNode.childNodes[1].firstChild.nodeValue : "");
|
||||
questionObj['question_type'] = 'text';
|
||||
questionObj['attributes'] = getAttributesOfXMLNode(questionNode);
|
||||
questionObj['question_sub_type'] = 'false';
|
||||
questionObj['is_math_enabled'] = questionNode.childNodes[3].firstChild.nodeValue;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
questionObj['question'] = questionNode.childNodes[0].firstChild.nodeValue;
|
||||
questionObj['question_description'] = (questionNode.childNodes[1].firstChild !== null? questionNode.childNodes[1].firstChild.nodeValue : "");
|
||||
questionObj['question_type'] = 'group';
|
||||
questionObj['attributes'] = getAttributesOfXMLNode(questionNode);
|
||||
questionObj['question_sub_type'] = questionNode.childNodes[4].firstChild.nodeValue;
|
||||
questionObj['is_math_enabled'] = questionNode.childNodes[3].firstChild.nodeValue;
|
||||
questionObj['answers'] = [];
|
||||
|
||||
var choiceList = questionNode.childNodes[5].childNodes;
|
||||
|
||||
if(choiceList.length > 0)
|
||||
{
|
||||
for (let k = 0; k < choiceList.length ;k++)
|
||||
{
|
||||
var tempChoiceobj = {};
|
||||
tempChoiceobj['id'] = choiceList[k].childNodes[0].firstChild.nodeValue;
|
||||
tempChoiceobj['choice_name'] = choiceList[k].childNodes[1].firstChild.nodeValue;
|
||||
tempChoiceobj['choice_description'] = (choiceList[k].childNodes[2].firstChild !== null ? choiceList[k].childNodes[2].firstChild.nodeValue : "");
|
||||
// console.log(tempChoiceobj);
|
||||
questionObj['answers'].push(tempChoiceobj);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return questionObj;
|
||||
|
||||
}
|
||||
|
||||
function getQuestionGroupNodes(questionGroup)
|
||||
{
|
||||
var questionGroupObj = {};
|
||||
|
||||
questionGroupObj['group_title'] = questionGroup.childNodes[0].firstChild.nodeValue;
|
||||
questionGroupObj['group_description'] = (questionGroup.childNodes[1].firstChild !== null ? questionGroup.childNodes[1].firstChild.nodeValue : "");
|
||||
questionGroupObj['attributes'] = getAttributesOfXMLNode(questionGroup);
|
||||
questionGroupObj['questions'] = [];
|
||||
//handle questions
|
||||
var questionList = questionGroup.childNodes[3].childNodes;
|
||||
console.log('No of quetions in GQ:' + questionList.length);
|
||||
for(let q = 0; q < questionList.length ;q++)
|
||||
{
|
||||
|
||||
var questionType = questionList[q].getAttribute("xsi:type");
|
||||
console.log(questionType);
|
||||
if(questionType == 'DescriptiveQuestion')
|
||||
{
|
||||
questionGroupObj['questions'].push(getQuestionsNodes(questionList[q],1));
|
||||
}
|
||||
else if(questionType == 'MultiChoiceQuestion')
|
||||
{
|
||||
questionGroupObj['questions'].push(getQuestionsNodes(questionList[q],2));
|
||||
}
|
||||
|
||||
}
|
||||
return questionGroupObj;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//busi logic start
|
||||
var xmlString = xmlData;
|
||||
const parser = new DOMParser();
|
||||
|
||||
// Parse the XML string into an XML document
|
||||
const xmlDoc = parser.parseFromString(xmlString, 'text/xml');
|
||||
const jsonObj = {};
|
||||
|
||||
jsonObj['question_paper_title'] = xmlDoc.getElementsByTagName("Title")[0].childNodes[0].nodeValue;
|
||||
jsonObj['question_paper_description'] = xmlDoc.getElementsByTagName("Subtitle")[0].childNodes[0].nodeValue;
|
||||
//get attributes of root/question paper element
|
||||
jsonObj['attributes'] = getAttributesOfXMLNode(xmlDoc.documentElement);
|
||||
jsonObj['sections'] = [];
|
||||
|
||||
|
||||
sectionsList = xmlDoc.getElementsByTagName("Items")[0].childNodes;
|
||||
console.log(sectionsList);
|
||||
console.log('no of sections:'+sectionsList.length);
|
||||
for (let i = 0; i < sectionsList.length ;i++) {
|
||||
var tempObj = {};
|
||||
|
||||
console.log('Section :' + i + '-' + sectionsList[i].childNodes[0].firstChild.nodeValue);
|
||||
tempObj['section_title'] = sectionsList[i].childNodes[0].firstChild.nodeValue;
|
||||
tempObj['section_description'] = sectionsList[i].childNodes[1].firstChild.nodeValue;
|
||||
tempObj['attributes'] = getAttributesOfXMLNode(sectionsList[i]);
|
||||
tempObj['questions'] = [];
|
||||
|
||||
//handle questions
|
||||
var questionList = sectionsList[i].childNodes[3].childNodes;
|
||||
console.log('No of quetions:' + questionList.length);
|
||||
// console.log(questionList[2]);
|
||||
for(let j = 0; j < questionList.length ;j++)
|
||||
{
|
||||
//check weather quesiotn or question grup
|
||||
console.log('QUESTION :' + j );
|
||||
// console.log(questionList[j].getAttribute("xsi:type"));
|
||||
var questionType = questionList[j].getAttribute("xsi:type");
|
||||
console.log(questionType);
|
||||
if(questionType == 'DescriptiveQuestion')
|
||||
{
|
||||
tempObj['questions'].push(getQuestionsNodes(questionList[j],1));
|
||||
}
|
||||
else if(questionType == 'MultiChoiceQuestion')
|
||||
{
|
||||
tempObj['questions'].push(getQuestionsNodes(questionList[j],2));
|
||||
}
|
||||
else if(questionType == 'QuestionGroup')
|
||||
{
|
||||
tempObj['questions'].push(getQuestionGroupNodes(questionList[j]));
|
||||
}
|
||||
}
|
||||
jsonObj['sections'].push(tempObj);
|
||||
}
|
||||
|
||||
var jsonData = JSON.stringify(jsonObj);
|
||||
console.log('Xml to Json Conversion ');
|
||||
console.log(jsonData);
|
||||
console.log(jsonObj);
|
||||
jsonToHtml(jsonObj);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user