Index: lams_tool_assessment/web/pages/learning/learning.jsp =================================================================== RCS file: /usr/local/cvsroot/lams_tool_assessment/web/pages/learning/learning.jsp,v diff -u -r1.33 -r1.34 --- lams_tool_assessment/web/pages/learning/learning.jsp 27 Jun 2014 23:18:18 -0000 1.33 +++ lams_tool_assessment/web/pages/learning/learning.jsp 9 Jul 2014 23:22:41 -0000 1.34 @@ -10,6 +10,7 @@ <fmt:message key="label.learning.title" /> <%@ include file="/common/header.jsp"%> + <%-- param has higher level for request attribute --%> @@ -127,14 +128,33 @@ ); + //check if we came back due to missing required question's answer + $(document).ready(function(){ + if (${requiredQuestionsDTO != null}) { + validateAnswers(); + } + }); + function finishSession(){ + if (!validateAnswers()) { + return; + } + document.location.href =''; return false; } function continueReflect(){ + if (!validateAnswers()) { + return; + } + document.location.href=''; } function nextPage(pageNumber){ + if (!validateAnswers()) { + return; + } + var secondsLeft = 0; if (${not finishedLock && assessment.timeLimit > 0}) { var times = $("#countdown").countdown('getTimes'); @@ -145,8 +165,17 @@ myForm.submit(); } function submitAll(){ + if (!validateAnswers()) { + return; + } + + var secondsLeft = 0; + if (${not finishedLock && assessment.timeLimit > 0}) { + var times = $("#countdown").countdown('getTimes'); + secondsLeft = times[4]*3600 + times[5]*60 + times[6]; + } var myForm = $("#answers"); - myForm.attr("action", ""); + myForm.attr("action", "&secondsLeft=" + secondsLeft); myForm.submit(); } function resubmit(){ @@ -199,6 +228,89 @@ }); } + function validateAnswers() { + + if (${finishedLock || !hasEditRight}) { + return true; + } + + var missingRequiredQuestions = []; + + + + + + //multiplechoice + if ($("input[name^=question${status.index}]:checked").length == 0) { + missingRequiredQuestions.push("${status.index}"); + } + + + + //matchingpairs + + var eachSelectHasBeenAnswered = true; + $("select[name^=question${status.index}_]").each(function() { + eachSelectHasBeenAnswered &= this.value != -1; + }); + + if (!eachSelectHasBeenAnswered) { + missingRequiredQuestions.push("${status.index}"); + } + + + + + //shortanswer or numerical or essay without ckeditor + var inputText = $("input[name=question${status.index}]")[0]; + if($.trim(inputText.value).length == 0) { + missingRequiredQuestions.push("${status.index}"); + } + + + + //truefalse + if ($("input[name=question${status.index}]:checked").length == 0) { + missingRequiredQuestions.push("${status.index}"); + } + + + + //essay with ckeditor + var ckeditorData = CKEDITOR.instances["question${status.index}"].getData(); + //can't be null and empty value + if((ckeditorData == null) || (ckeditorData.replace(/ | |
|\s|

|<\/p>|\xa0/g, "").length == 0)) { + missingRequiredQuestions.push("${status.index}"); + } + + + + //ordering - do nothing + + + + + + //return true in case all required questions were answered, false otherwise + if (missingRequiredQuestions.length == 0) { + return true; + + } else { + //remove .warning-answer-required from all questions + $('[id^=question-area-]').removeClass('warning-answer-required'); + + //add .warning-answer-required class to those needs to be filled + for (i = 0; i < missingRequiredQuestions.length; i++) { + $("#question-area-" + missingRequiredQuestions[i]).addClass('warning-answer-required'); + } + + //show alert message as well + $("#warning-answers-required").show(); + $("html, body").animate({ scrollTop: 0 }, "slow");//window.scrollTo(0, 0); + return false; + } + } + @@ -238,6 +350,10 @@

+
+ +
+