<commit_before>{% load ndf_tags %}
{% load i18n %}
{% get_group_name groupid as group_name_tag %}
{% get_user_quiz_resp node request.user as total_and_curr_ans_dict %}
<style type="text/css">
	.quiz_qtn{
		margin-left:20px !important;
		font-size: 20px;
	}
	.question_edit{
		margin-left: 20px !important;
	}

	input[type=checkbox], input[type=radio]{
	    margin-right: 10px;
	    width: 15px;
		height: 15px;
	}

	.chk_ans_lbl, .rad_ans_lbl{
		font-size: 22px;
		margin-left: 5px;
	}

	.fi-check{
		color: green;
	}

	.fi-x{
		color: red;
	}
</style>

<div class="row">
<label class="attempts_count right fi-info">You attempted this question {{total_and_curr_ans_dict.count}} times </label>
	<fieldset>
	    <legend >
	    	<span>Question</span>
			{% check_is_gstaff groupid request.user as is_gstaff %}
			{% if is_gstaff %}
		    	<a href="{% url 'quiz_item_edit' group_id node.pk %}?return_url={{ request.META.HTTP_REFERER }}" class="right question_edit" target="_blank" >Edit</a>
		    {% endif %}
	    </legend>

		<div class="row">
			<div class="quiz_qtn">
				<b>{{node.content|safe}}</b>
				<div class="quiz_qtn">
					{% if node.quiz_type == "Single-Choice" %}
						{% for each_opt in node.options %}
							<input type="radio" name="quiz_ans"  value="{{each_opt}}"
							{% if each_opt in node.correct_answer %}
								class="choice" id="{{each_opt}}">{{each_opt}}<span class='fi-check hide chk_ans_lbl'></span>
							{% else %}
								class="choice" id="{{each_opt}}">{{each_opt}}<span class='fi-x hide chk_ans_lbl'></span>
							{% endif %}
							<br/>
						{% endfor %}
						{% comment %}
						<div class="row">
							{% if node.quizitem_check_answer %}
								<input type="button" value="Check" class="button tiny check-ans radius check-btn">
							{% endif %}
							{% if node.quizitem_show_correct_ans %}
								<input type="button" value="Show Answer" class="button tiny radius show-ans-btn hide">
							{% endif %}
						</div>
						{% endcomment %}
					{% elif node.quiz_type == "Multiple-Choice" %}
						{% for each_opt in node.options %}
							<input type="checkbox" name="quiz_ans" value="{{each_opt}}"
							{% if each_opt in node.correct_answer %}
								class="choice" id="{{each_opt}}">{{each_opt}}<span class='fi-check hide chk_ans_lbl'></span>
							{% else %}
								class="choice"  id="{{each_opt}}">{{each_opt}}<span class='fi-x hide chk_ans_lbl'></span>
							{% endif %}
							<br/>
						{% endfor %}
					{% elif node.quiz_type == "Short-Response" %}
						<textarea rows="4" cols="50" name="quiz_ans" class="choice" placeholder="Enter answer here" class="short_ans_txt" >{{total_and_curr_ans_dict.recent_ans|default_if_none:""}}</textarea>
						<!-- <input type="button" value="Submit" class="button tiny radius short-ans_chk"> -->
					{% endif %}
					<div class="row">
						{% if node.quizitem_check_answer and node.quiz_type != "Short-Response"  %}
							<input type="button" value="Check" class="button tiny check-ans radius check-btn">
						{% endif %}
						{% if node.quizitem_show_correct_ans %}
							<input type="button" value="Show Answer" class="button tiny radius show-ans-btn hide">
						{% endif %}
						{% if not node.quizitem_show_correct_ans %}
						<input type="button" value="Submit" class="tiny button radius submit-btn">
						{% endif %}
					</div>

				</div>
			</div>
		</div>
	</fieldset>
</div>

<script type="text/javascript">
	user_submitted_ans_list = {{total_and_curr_ans_dict.recent_ans|jsonify|safe}}

	// On load ---------------------------------------------------------------
		$(document).ready(function() {
			display_sub_ans()
		})

	// Toggle Check to Clear btn after some actions --------------------------
		$(".check-btn").click(function(){
			{% if node.quiz_type == "Multiple-Choice" %}
				var selected_ans = $('input:checkbox:checked')
			{% elif node.quiz_type == "Single-Choice" %}
				var selected_ans = $('input:radio:checked')
			{% endif %}

			if($(this).val() == "Check"){
				if( selected_ans.length > 0){
					all_ans = user_ans()
					$(".check-btn").val("Clear")
					$(".show-ans-btn").removeClass("hide")
					save_user_action("check",all_ans)
				}
				else{
					alert("Please select an answer")
				}
			}
			else if ($(this).val() == "Clear"){
				hide_options();
				display_sub_ans()
			}
		})

	// Show/Hide Submit button -----------------------------------------------
		function submit_btn_status(show_hide){
			if(show_hide == "show"){
				$(".submit-btn")
					.removeAttr("disabled")
					.removeClass("secondary")
			}
			else{
				$(".submit-btn")
					.attr("disabled","disabled")
					.addClass("secondary")
			}
		}

	// Select user's recent submitted answer ---------------------------------
		function display_sub_ans(){
			user_ans_list = user_submitted_ans_list
			if(user_ans_list){
				$.each(user_ans_list,function(ind,each_opt_val){
					var re = /[.*+=~`<>;:'"_?^${}()!%\^|[\]\\\/#]/g;
					if(re.test(each_opt_val)){
						each_opt_val = each_opt_val.replace(re,"\\$&")
						$(":radio[value='"+each_opt_val+"']").prop("checked", true)
					}
					else{
						$("#"+each_opt_val).prop("checked", true)
					}
				})
				submit_btn_status("hide")
			}
		}

	// Fecth user's selected answer ------------------------------------------

		function user_ans(){<commit_msg>quiz-resp for short response type bug fixed<commit_after>{% load ndf_tags %}
{% load i18n %}
{% get_group_name groupid as group_name_tag %}
{% get_user_quiz_resp node request.user as total_and_curr_ans_dict %}
<style type="text/css">
	.quiz_qtn{
		margin-left:20px !important;
		font-size: 20px;
	}
	.question_edit{
		margin-left: 20px !important;
	}

	input[type=checkbox], input[type=radio]{
	    margin-right: 10px;
	    width: 15px;
		height: 15px;
	}

	.chk_ans_lbl, .rad_ans_lbl{
		font-size: 22px;
		margin-left: 5px;
	}

	.fi-check{
		color: green;
	}

	.fi-x{
		color: red;
	}
</style>

<div class="row">
<label class="attempts_count right fi-info">You attempted this question {{total_and_curr_ans_dict.count}} times </label>
	<fieldset>
	    <legend >
	    	<span>Question</span>
			{% check_is_gstaff groupid request.user as is_gstaff %}
			{% if is_gstaff %}
		    	<a href="{% url 'quiz_item_edit' group_id node.pk %}?return_url={{ request.META.HTTP_REFERER }}" class="right question_edit" target="_blank" >Edit</a>
		    {% endif %}
	    </legend>

		<div class="row">
			<div class="quiz_qtn">
				<b>{{node.content|safe}}</b>
				<div class="quiz_qtn">
					{% if node.quiz_type == "Single-Choice" %}
						{% for each_opt in node.options %}
							<input type="radio" name="quiz_ans"  value="{{each_opt}}"
							{% if each_opt in node.correct_answer %}
								class="choice" id="{{each_opt}}">{{each_opt}}<span class='fi-check hide chk_ans_lbl'></span>
							{% else %}
								class="choice" id="{{each_opt}}">{{each_opt}}<span class='fi-x hide chk_ans_lbl'></span>
							{% endif %}
							<br/>
						{% endfor %}
						{% comment %}
						<div class="row">
							{% if node.quizitem_check_answer %}
								<input type="button" value="Check" class="button tiny check-ans radius check-btn">
							{% endif %}
							{% if node.quizitem_show_correct_ans %}
								<input type="button" value="Show Answer" class="button tiny radius show-ans-btn hide">
							{% endif %}
						</div>
						{% endcomment %}
					{% elif node.quiz_type == "Multiple-Choice" %}
						{% for each_opt in node.options %}
							<input type="checkbox" name="quiz_ans" value="{{each_opt}}"
							{% if each_opt in node.correct_answer %}
								class="choice" id="{{each_opt}}">{{each_opt}}<span class='fi-check hide chk_ans_lbl'></span>
							{% else %}
								class="choice"  id="{{each_opt}}">{{each_opt}}<span class='fi-x hide chk_ans_lbl'></span>
							{% endif %}
							<br/>
						{% endfor %}
					{% elif node.quiz_type == "Short-Response" %}
						<textarea rows="4" cols="50" name="quiz_ans" class="choice" placeholder="Enter answer here" class="short_ans_txt" >{{total_and_curr_ans_dict.recent_ans|default_if_none:""}}</textarea>
						<!-- <input type="button" value="Submit" class="button tiny radius short-ans_chk"> -->
					{% endif %}
					<div class="row">
						{% if node.quizitem_check_answer and node.quiz_type != "Short-Response"  %}
							<input type="button" value="Check" class="button tiny check-ans radius check-btn">
						{% endif %}
						{% if node.quizitem_show_correct_ans %}
							<input type="button" value="Show Answer" class="button tiny radius show-ans-btn hide">
						{% endif %}
						{% if not node.quizitem_show_correct_ans %}
						<input type="button" value="Submit" class="tiny button radius submit-btn">
						{% endif %}
					</div>

				</div>
			</div>
		</div>
	</fieldset>
</div>

<script type="text/javascript">
	user_submitted_ans_list = {{total_and_curr_ans_dict.recent_ans|jsonify|safe}}

	// On load ---------------------------------------------------------------
		$(document).ready(function() {
			display_sub_ans()
		})

	// Toggle Check to Clear btn after some actions --------------------------
		$(".check-btn").click(function(){
			{% if node.quiz_type == "Multiple-Choice" %}
				var selected_ans = $('input:checkbox:checked')
			{% elif node.quiz_type == "Single-Choice" %}
				var selected_ans = $('input:radio:checked')
			{% endif %}

			if($(this).val() == "Check"){
				if( selected_ans.length > 0){
					all_ans = user_ans()
					$(".check-btn").val("Clear")
					$(".show-ans-btn").removeClass("hide")
					save_user_action("check",all_ans)
				}
				else{
					alert("Please select an answer")
				}
			}
			else if ($(this).val() == "Clear"){
				hide_options();
				display_sub_ans()
			}
		})

	// Show/Hide Submit button -----------------------------------------------
		function submit_btn_status(show_hide){
			if(show_hide == "show"){
				$(".submit-btn")
					.removeAttr("disabled")
					.removeClass("secondary")
			}
			else{
				$(".submit-btn")
					.attr("disabled","disabled")
					.addClass("secondary")
			}
		}

	// Select user's recent submitted answer ---------------------------------
		function display_sub_ans(){
			{% if node.quiz_type != "Short-Response" %}
			user_ans_list = user_submitted_ans_list
			if(user_ans_list){
				$.each(user_ans_list,function(ind,each_opt_val){
					var re = /[.*+=~`<>;:'"_?^${}()!%\^|[\]\\\/#]/g;
					if(re.test(each_opt_val)){
						each_opt_val = each_opt_val.replace(re,"\\$&")
						$(":radio[value='"+each_opt_val+"']").prop("checked", true)
					}
					else{
						$("#"+each_opt_val).prop("checked", true)
					}
				})
				submit_btn_status("hide")
			}
			{% endif %}
		}

	// Fecth user's selected answer ------------------------------------------

		function user_ans(){
{'fraction_non_alphanumeric': 0.21485682409817777, 'fraction_numerical': 0.003904797322424693, 'mean_word_length': 2.759874169870675, 'pattern_counts': {'":': 2, '<': 101, '<?xml version=': 0, '>': 107, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1561452', 'n_tokens_mistral': 4719, 'n_tokens_neox': 3605, 'n_words': 679}