Commit dacf10553b2494add15fae2eb66a75dc847b49a0
1 parent
7c8fc682
Exists in
master
and in
5 other branches
created file modalExam Js #362
Showing
2 changed files
with
150 additions
and
3 deletions
Show diff stats
@@ -0,0 +1,147 @@ | @@ -0,0 +1,147 @@ | ||
1 | + | ||
2 | +//Insert Create select with question type | ||
3 | + var idQuestionType = 1; | ||
4 | + $("#addQuestion").on("click", function(event){ | ||
5 | + var element = | ||
6 | + '<div class="row form-group" id="questionType_' + idQuestionType +'">' + | ||
7 | + '<label for="questionType" class="col-md-2 control-label">' + | ||
8 | + '{% trans "Question Type" %}</label>' + '<div class="col-md-10">' + | ||
9 | + '<select id="questionType'+ idQuestionType +'" class="form-control" name="option_question" onchange="showDiv (this, '+ idQuestionType +')">' + | ||
10 | + '<option selected disabled>{% trans "Question Type" %}</option>' + | ||
11 | + '<option value="0">{% trans "Multiple Choice" %}</option>' + | ||
12 | + '<option value="1">{% trans "True or False" %}</option>' + | ||
13 | + '<option value="2">{% trans "Gap Filling" %}</option>' + | ||
14 | + '<option value="3">{% trans "Discursive Question" %}</option>' + | ||
15 | + '</select>' + | ||
16 | + '</div>' + | ||
17 | + '</div>' + '<hr id="hr_'+idQuestionType+'">' | ||
18 | + ; | ||
19 | + if (idQuestionType == 1){ | ||
20 | + $(element).insertAfter('#buttonAddQuestion'); | ||
21 | + }else{ | ||
22 | + var idhr = '#hr_'+(idQuestionType-1); | ||
23 | + $(element).insertAfter(idhr); | ||
24 | + } | ||
25 | + idQuestionType++; | ||
26 | + }) | ||
27 | + | ||
28 | + //Insert question choice | ||
29 | + function showDiv (elem, questionType_id) { | ||
30 | + if (elem.value == 0) { | ||
31 | + var questionChoice = | ||
32 | + '<div id="questionChoice_'+questionType_id+'">' + | ||
33 | + '<div class="row form-group">'+ | ||
34 | + '<label for="question-name" class="col-md-2 control-label">Question</label>'+ | ||
35 | + '<div class="col-md-10">'+ | ||
36 | + '<textarea class="form-control" rows="1" id="question-name" placeholder="Wording"></textarea>'+ | ||
37 | + '</div>'+ | ||
38 | + '</div>'+ | ||
39 | + '<div class="row form-group">'+ | ||
40 | + '<label for="alternatives" class="col-md-2 control-label">Alternatives</label>'+ | ||
41 | + '<div class="col-md-10" id="radios_'+questionType_id+'">'+ | ||
42 | + '<div class="radio radio-primary form-group">'+ | ||
43 | + '<label>'+ | ||
44 | + '<input checked type="radio" name="multiple-choice" id="alternative1" value="1">'+ | ||
45 | + '<textarea class="form-control" rows="1" placeholder="Write your alternative"></textarea>'+ | ||
46 | + '</label>'+ | ||
47 | + '</div>'+ | ||
48 | + '<div class="radio radio-primary form-group">'+ | ||
49 | + '<label>'+ | ||
50 | + '<input type="radio" name="multiple-choice" id="alternative2" value="2">'+ | ||
51 | + '<textarea class="form-control" rows="1" placeholder="Write your alternative"></textarea>'+ | ||
52 | + '</label>'+ | ||
53 | + '</div>'+ | ||
54 | + '</div>'+ | ||
55 | + '</div>'+ | ||
56 | + '<div class="form-group">'+ | ||
57 | + '<button type="button" class="btn btn-raised btn-primary" id="newAlternative_'+questionType_id+'" onclick="functionNewAlternative(radios_'+questionType_id+')">New Alternative</button>'+ | ||
58 | + '</div>'+ | ||
59 | + '</div>'; | ||
60 | + } else if (elem.value == 1) { | ||
61 | + var questionChoice = | ||
62 | + '<div id="questionChoice_'+questionType_id+'">'+ | ||
63 | + '<div class="row form-group">'+ | ||
64 | + '<label for="question-name" class="col-md-2 control-label">Question True or False</label>'+ | ||
65 | + '<div class="col-md-10">'+ | ||
66 | + '<textarea class="form-control" rows="1" id="question-name" placeholder="Wording"></textarea>'+ | ||
67 | + '</div>'+ | ||
68 | + '</div>'+ | ||
69 | + '<div class="row form-group">'+ | ||
70 | + '<label for="alternative" class="col-md-2 control-label">Alternatives: T/F</label>'+ | ||
71 | + '<div class="col-md-10" id="radiosTF_'+questionType_id+'">'+ | ||
72 | + '<div class="radio form-group" value="1">'+ | ||
73 | + '<div class="radio">'+ | ||
74 | + '<label>'+ | ||
75 | + '<textarea class="form-control" rows="1" placeholder="Write your alternative"></textarea>'+ | ||
76 | + '</label>'+ | ||
77 | + '<label>'+ | ||
78 | + '<input type="radio" name="true-or-false-1" value="T">'+ | ||
79 | + '</label>'+ | ||
80 | + '<label>'+ | ||
81 | + '<input type="radio" name="true-or-false-1" value="F">'+ | ||
82 | + '</label>'+ | ||
83 | + '</div>'+ | ||
84 | + '</div>'+ | ||
85 | + '<div class="radio form-group" value="2">'+ | ||
86 | + '<label>'+ | ||
87 | + '<textarea class="form-control" rows="1" placeholder="Write your alternative"></textarea>'+ | ||
88 | + '</label>'+ | ||
89 | + '<label>'+ | ||
90 | + '<input type="radio" name="true-or-false-2" value="T">'+ | ||
91 | + '</label>'+ | ||
92 | + '<label>'+ | ||
93 | + '<input type="radio" name="true-or-false-2" value="F">'+ | ||
94 | + '</label>'+ | ||
95 | + '</div>'+ | ||
96 | + '</div>'+ | ||
97 | + '</div>'+ | ||
98 | + '<div class="form-group">'+ | ||
99 | + '<button type="button" class="btn btn-raised btn-primary" id="newAlternative_'+questionType_id+'" onclick="functionNewAlternativeTF(radiosTF_'+questionType_id+')">New Alternative</button>'+ | ||
100 | + '</div>'+ | ||
101 | + '</div>'; | ||
102 | + } else if (elem.value == 3) { | ||
103 | + var questionChoice = | ||
104 | + '<div id="questionChoice_'+questionType_id+'">'+ | ||
105 | + '<div class="row form-group">'+ | ||
106 | + '<label for="question-name" class="col-md-2 control-label">Name Question discursive</label>'+ | ||
107 | + '<div class="col-md-10">'+ | ||
108 | + '<textarea class="form-control" rows="2" id="question" placeholder="Wording"></textarea>'+ | ||
109 | + '</div>'+ | ||
110 | + '</div>'+ | ||
111 | + '</div>'; | ||
112 | + } | ||
113 | + if(document.getElementById('questionChoice_'+ questionType_id)){ | ||
114 | + $('#questionChoice_'+ questionType_id).detach(); | ||
115 | + } | ||
116 | + $(questionChoice).insertBefore('#hr_'+questionType_id); | ||
117 | + $.material.init() //O material deve ser iniciado aqui para funcionar os botoes de radio. | ||
118 | + } | ||
119 | +//Bug quando criamos sem ser na ordem | ||
120 | +function functionNewAlternative(Question_Id){ | ||
121 | + var alternative = parseInt($("div input").last().val()) + 1; | ||
122 | + var element = '<div class="radio radio-primary form-group">' + | ||
123 | + '<label>' + | ||
124 | + '<input type="radio" name="alternatives" id="alternative_'+alternative+'_'+Question_Id+'"' + 'value="'+alternative+'">' + | ||
125 | + '<textarea class="form-control" rows="1" placeholder="Write your alternative"></textarea>' + | ||
126 | + '</label>'+ | ||
127 | + '</div>'; | ||
128 | + $(Question_Id).append(element); | ||
129 | + $.material.init() //O material deve ser iniciado aqui para funcionar os botoes de radio. | ||
130 | +} | ||
131 | +function functionNewAlternativeTF(Question_Id){ | ||
132 | + var alternative = parseInt($("div").last().val()) + 1; | ||
133 | + var element = | ||
134 | + '<div class="radio form-group">'+ | ||
135 | + '<label>'+ | ||
136 | + '<textarea class="form-control" rows="1" placeholder="Write your alternative"></textarea>'+ | ||
137 | + '</label>'+ | ||
138 | + '<label>'+ | ||
139 | + '<input type="radio" name="true-or-false-2" value="T">'+ | ||
140 | + '</label>'+ | ||
141 | + '<label>'+ | ||
142 | + '<input type="radio" name="true-or-false-2" value="F">'+ | ||
143 | + '</label>'+ | ||
144 | + '</div>'; | ||
145 | + $(Question_Id).append(element); | ||
146 | + $.material.init() //O material deve ser iniciado aqui para funcionar os botoes de radio. | ||
147 | +} | ||
0 | \ No newline at end of file | 148 | \ No newline at end of file |
exam/templates/exam/create.html
@@ -4,7 +4,7 @@ | @@ -4,7 +4,7 @@ | ||
4 | 4 | ||
5 | {# {% block style %} #} | 5 | {# {% block style %} #} |
6 | <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> | 6 | <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> |
7 | - <script src="{% static 'js/modal_exam.js' %}"></script> | 7 | + <script src="{% static 'js/modalExam.js' %}"></script> |
8 | 8 | ||
9 | {# {% endblock %} #} | 9 | {# {% endblock %} #} |
10 | 10 | ||
@@ -93,9 +93,9 @@ | @@ -93,9 +93,9 @@ | ||
93 | var id = 1; | 93 | var id = 1; |
94 | $("#add_question").click(function(){ | 94 | $("#add_question").click(function(){ |
95 | $.get("{% url 'course:exam:true_or_false_question' %}", function(data){ | 95 | $.get("{% url 'course:exam:true_or_false_question' %}", function(data){ |
96 | - | 96 | + |
97 | $("#questions").append(data); | 97 | $("#questions").append(data); |
98 | - | 98 | + |
99 | $("#0").attr("id","true_" + id++); | 99 | $("#0").attr("id","true_" + id++); |
100 | }); | 100 | }); |
101 | }); | 101 | }); |