summaryrefslogtreecommitdiff
path: root/testapp/static/exam/js/edit_question.js
blob: acba384fb02513af738d95c11eaa9879968ce1f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
function render_question(frm)
{
    for(var i=1;i<=frm.description.length;i++)
    {
        document.getElementById('my'+i).innerHTML = frm.description[i-1].value;
    }
   
}

function increase(frm,n)
{
	var newValue = document.getElementById('id_points'+ (n-1)).value ;
		
	if( newValue == "")
	{
		document.getElementById('id_points'+(n-1)).value = "0.5";
		return;
	}
	document.getElementById('id_points' + (n-1)).value = parseFloat(newValue) + 0.5;
}

function decrease(frm,n)
{
	var newValue = document.getElementById('id_points'+ (n-1)).value ;
		
	if( newValue > 0)
	{
		document.getElementById('id_points' + (n-1)).value = parseFloat(newValue) - 0.5;
	}
	else
	{
		document.getElementById('id_points' + (n-1)).value = 0;
	}
}

function grade_data(showHideDiv)
{
       var ele=document.getElementById(showHideDiv);
       if (ele.style.display=="block")
       {
               ele.style.display = "none";
       }
       else
       {
               ele.style.display = "block";
       }
}


function data(showContent,showHideDiv,a,summary)
{
    var con = document.getElementById(showContent);
    var ele=document.getElementById(showHideDiv);
    var atag=document.getElementById(a);
    if (ele.style.display=="block")
    {
        con.style.display = "none"
        ele.style.display = "none";
	atag.text = summary;
    }
    else
    {
        con.style.display = "block";
        ele.style.display = "block";
    }
}

function textareaformat()
{
	var point = document.getElementsByName('points');
	var test =  document.getElementsByName('test');
	var option =  document.getElementsByName('options');
	var descriptions = document.getElementsByName('description');
	var type = document.getElementsByName('type');
    var tags = document.getElementsByName('tags');
	
	for (var i=0;i<point.length;i++)
	{
		point[i].id = point[i].id + i;
		descriptions[i+1].id=descriptions[i+1].id + i;
		test[i].id=test[i].id + i;
		option[i].id=option[i].id + i;
		type[i].id = type[i].id + i;
        tags[i].id = tags[i].id + i;
	}

	for(var i=0;i<point.length;i++)
	{
		var point_id = document.getElementById('id_points'+i);
		point_id.setAttribute('class','mini-text');
    
        var tags_id = document.getElementById('id_tags'+i);
		tags_id.setAttribute('class','ac_input');
        tags_id.setAttribute('autocomplete','off');
       
        jQuery().ready(function() 
        { 
            jQuery("#id_tags" + i).autocomplete("/taggit_autocomplete_modified/json", { multiple: true }); 
        });
    		
        var type_id = document.getElementById('id_type'+i);
		type_id.setAttribute('class','select-type');
		type_id.onchange = showOptions;
		var value = type_id.value;
	
		var desc_id = document.getElementById('id_description'+i);
		desc_id.onfocus = gainfocus;
		desc_id.onblur = lostfocus;

		var test_id = document.getElementById('id_test' + i);
		test_id.onfocus = gainfocus;
		test_id.onblur = lostfocus;

		var option_id = document.getElementById('id_options' + i);
		option_id.onfocus = gainfocus;
		option_id.onblur = lostfocus;
		
		if(value != 'mcq')
		{
			document.getElementById('id_options'+i).style.visibility='hidden';
			document.getElementById('label_option'+(i+1)).innerHTML = "";

		}

		document.getElementById('my'+ (i+1)).innerHTML = desc_id.value;
	}
}

function showOptions(e)
{
		var value = this.value;
		var no = parseInt(this.id.substring(this.id.length-1));
		if( value == 'mcq')
		{	
			document.getElementById('id_options'+no).style.visibility = 'visible';
			document.getElementById('label_option'+ (no+1)).innerHTML = "Options : "
		}
		else
		{
			document.getElementById('id_options'+no).value = "";
			document.getElementById('id_options'+no).style.visibility = 'hidden';
			document.getElementById('label_option'+ (no+1)).innerHTML = "";
		}
		


}

function gainfocus(e)
{
	this.rows = 5;
}
function lostfocus(e)
{
	this.rows = 1;
}

function autosubmit()
{
	var total_form = document.getElementsByName('summary').length;
	var empty_options = 0 ;
	var count_mcq = 0;
		
	for (var i=0;i<total_form;i++)
	{
		if (document.getElementById('id_type' + i).value != 'mcq')
		{
			continue;
		}
		else
		{
			count_mcq = count_mcq + 1;
			var options = document.getElementById('id_options' + i).value;
			var total_words = options.split("\n").length ;
			if ( total_words < 4)
				empty_options = empty_options + 1 ;
		}
	}
	if (empty_options > 0)
	{
		alert('Enter 4 options. One option per line.');
		return false;
	}
	return true;
}