262 lines
7.2 KiB
JavaScript
262 lines
7.2 KiB
JavaScript
function markCalculation() {
|
|
|
|
// Get jsonData from the Localstorage
|
|
var jsonString = localStorage.getItem('JSON_FOR_NAV');
|
|
// console.log('jsonData markCalculation');
|
|
const jsonData = JSON.parse(jsonString);
|
|
// console.log(jsonData);
|
|
|
|
|
|
//Section Level foreach
|
|
jsonData.sections.forEach(function(section, index) {
|
|
|
|
var sectionMarks = section.section_marks;
|
|
var sectionAttemptAny = section.section_attempt_any;
|
|
var section_id = section.section_id;
|
|
|
|
// console.log('sectionMarks : ', sectionMarks);
|
|
// console.log('sectionAttemptAny : ', sectionAttemptAny);
|
|
// console.log('#########################################################################');
|
|
|
|
|
|
var sectionRandomID = section_id.split("_")[3];
|
|
var Section_Marks = document.getElementById('Section_Marks_Id_'+ sectionRandomID);
|
|
|
|
//condition for disable and enable Section Marks field
|
|
if(sectionAttemptAny == "")
|
|
{
|
|
Section_Marks.disabled = true;
|
|
|
|
}
|
|
else
|
|
{
|
|
Section_Marks.disabled = false;
|
|
}
|
|
|
|
|
|
//send a object for generateSingleQuestions() function using foreach and mark calc
|
|
var ParentObjects = {
|
|
|
|
'questionData' : section,
|
|
'parentMarks' : sectionMarks,
|
|
'parentAttemptAny' : sectionAttemptAny,
|
|
}
|
|
|
|
var returnvalue = generateSingleQuestions(ParentObjects);
|
|
// console.log('returnvalue of child sum in section : ' , returnvalue);
|
|
|
|
if(sectionAttemptAny == "")
|
|
{
|
|
Section_Marks.value = returnvalue;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//Function for Question Level foreach
|
|
function generateSingleQuestions(ParentObjects)
|
|
{
|
|
var questionData = false; //set default value for reciveing questionObjects
|
|
|
|
//set values from QuestionObjects param if exists
|
|
if(ParentObjects.hasOwnProperty('questionData'))
|
|
{
|
|
questionData = ParentObjects.questionData;
|
|
}
|
|
|
|
var childMarks = 0;
|
|
|
|
//Questions Foreach Start
|
|
questionData.questions.forEach(function(Question, index) {
|
|
|
|
var questionTypeFormets = "";
|
|
if(Question.question_type)
|
|
{
|
|
questionTypeFormets = Question.question_type;
|
|
}
|
|
else
|
|
{
|
|
questionTypeFormets ='question_group';
|
|
}
|
|
|
|
//Questions Variables
|
|
var questionType = questionTypeFormets;
|
|
var questionMarks = Question.marks;
|
|
var question_Id = Question.question_Id;
|
|
|
|
// console.log('questionType : ' , questionType);
|
|
// console.log('questionMarks : ' , questionMarks);
|
|
// console.log('##########################################################');
|
|
|
|
|
|
var parentMarks = ParentObjects.parentMarks;
|
|
var parentAttemptAny = ParentObjects.parentAttemptAny;
|
|
var DivideValue = parentMarks / parentAttemptAny;
|
|
const twoDigitsAfterDecimal = DivideValue.toFixed(2);
|
|
var MarkDivideValue = parseFloat(twoDigitsAfterDecimal);
|
|
// console.log(MarkDivideValue)
|
|
|
|
// console.log('parentMarks : ', parentMarks);
|
|
// console.log('new_parentAttemptAny : ', parentAttemptAny);
|
|
// console.log('new_Child_Mark_DivideValue : ', MarkDivideValue);
|
|
// console.log('################################################################################');
|
|
|
|
|
|
//end of section mark divided by section attempt any
|
|
var QuestionMarkField = "";
|
|
|
|
if(questionType == 'text')
|
|
{
|
|
var QuestionId = question_Id.split("_")[1];
|
|
QuestionMarkField = document.getElementById('Text_Question_Marks_Id_'+ QuestionId);
|
|
onlyQuestionMarks = questionMarks !== undefined && questionMarks !== "" ? questionMarks : 0;
|
|
var questionMarksINT = parseFloat(onlyQuestionMarks, 2);
|
|
childMarks = childMarks + questionMarksINT;
|
|
}
|
|
else if(questionType == 'group')
|
|
{
|
|
var QuestionId = question_Id.split("_")[1];
|
|
QuestionMarkField = document.getElementById('Choice_Question_Marks_Id_' + QuestionId);
|
|
onlyQuestionMarks = questionMarks !== undefined && questionMarks !== "" ? questionMarks : 0;
|
|
var questionMarksINT = parseFloat(onlyQuestionMarks, 2);
|
|
childMarks = childMarks + questionMarksINT;
|
|
}
|
|
|
|
|
|
if (questionType == 'question_group')
|
|
{
|
|
|
|
//the objects contain QuestionGroup Data for send generateGroupQuestions()
|
|
var QuestionGroupObjects = {
|
|
|
|
'questionGroupData': Question,
|
|
'parentMarks' : MarkDivideValue,
|
|
'parentAttemptAny' : ParentObjects.parentAttemptAny,
|
|
|
|
}
|
|
|
|
var returnValue = generateGroupQuestions(QuestionGroupObjects); //function for forEach QuestionGroups and Questions
|
|
onlyQuestionMarks = returnValue !== undefined && returnValue !== "" ? returnValue : 0;
|
|
var questionGroupMarksINT = parseFloat(onlyQuestionMarks, 2);
|
|
childMarks = childMarks + questionGroupMarksINT;
|
|
}
|
|
else
|
|
{
|
|
if(ParentObjects.parentAttemptAny !== "")
|
|
{
|
|
QuestionMarkField.value = MarkDivideValue;
|
|
QuestionMarkField.disabled = true;
|
|
}
|
|
else
|
|
{
|
|
QuestionMarkField.disabled = false;
|
|
}
|
|
}
|
|
|
|
|
|
//sum the child marks to set parent
|
|
|
|
|
|
|
|
})
|
|
|
|
//End of Questions Foreach
|
|
|
|
// console.log('ChildMarks sum in Questions: ', childMarks);
|
|
return childMarks;
|
|
|
|
}
|
|
|
|
|
|
|
|
// function for QuestionGroups and QuestionGroup questions Level Foreach
|
|
function generateGroupQuestions(QuestionGroupObjects)
|
|
{
|
|
//set default value for reciveing questionObjects
|
|
var Question = false;
|
|
//end of set default value for reciveing questionObjects
|
|
|
|
|
|
//set values from QuestionObjects param if exists
|
|
if(QuestionGroupObjects.hasOwnProperty('questionGroupData'))
|
|
{
|
|
Question = QuestionGroupObjects.questionGroupData;
|
|
}
|
|
|
|
//end of set values from QuestionObjects param if exists
|
|
|
|
|
|
//QuestionGroup Variables
|
|
var group_marks = Question.group_marks;
|
|
var group_attempt_any = Question.group_attempt_any;
|
|
var question_group_id = Question.question_group_id;
|
|
//end of QuestionGroup Variables
|
|
|
|
// console.log('old_group_marks : ', group_marks);
|
|
// console.log('old_group_attempt_any : ', group_attempt_any);
|
|
// console.log('################################################################################');
|
|
|
|
|
|
|
|
//Section AttemptAny for first level QuestionGroup
|
|
var QuestionGroup_ID = question_group_id.split("_")[3];
|
|
var Question_Group_Marks_Field = document.getElementById('Question_Group_Marks_Id_' + QuestionGroup_ID);
|
|
|
|
if(QuestionGroupObjects.parentAttemptAny !== "" )
|
|
{
|
|
Question_Group_Marks_Field.value = QuestionGroupObjects.parentMarks !== undefined ? QuestionGroupObjects.parentMarks : '';
|
|
group_marks= QuestionGroupObjects.parentMarks !== undefined ? QuestionGroupObjects.parentMarks : ''; //set the new value of group-marks using the divided value of parent marks
|
|
Question_Group_Marks_Field.disabled = true;
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
Question_Group_Marks_Field.disabled = false;
|
|
|
|
}
|
|
|
|
|
|
//condition for disable and enable QuestionGroup Marks field
|
|
if(group_attempt_any == "")
|
|
{
|
|
Question_Group_Marks_Field.disabled = true;
|
|
}
|
|
else
|
|
{
|
|
Question_Group_Marks_Field.disabled = false;
|
|
}
|
|
|
|
|
|
var QuestionGroupObjects = {
|
|
|
|
'questionData' : Question,
|
|
'parentMarks' : group_marks,
|
|
'parentAttemptAny': group_attempt_any,
|
|
|
|
}
|
|
|
|
|
|
var returnvalue = generateSingleQuestions(QuestionGroupObjects);
|
|
// console.log('ReturnValue of child sum in questionGroup: ' , returnvalue);
|
|
|
|
if(returnvalue)
|
|
{
|
|
if(group_attempt_any == "")
|
|
{
|
|
Question_Group_Marks_Field.value = returnvalue;
|
|
group_marks = returnvalue;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
return group_marks;
|
|
|
|
|
|
}
|