Blame view

WebRoot/static/js/en_paper_view.js 6.38 KB
efdefb1b   孙向锦   添加语言English
1
2
3
4
5
6
7
  var url="";
  	var question_box=[];
  	function slide(obj){                      //查看解析
  		obj.closest(".star_box").siblings(".resolve").slideToggle(function(){
  			if($(".resolve").css("display") == "none")
  				obj.text("View Analysis");
  			else
0e4da37e   孙向锦   学校管理员界面
8
  				obj.text("Hide analysis");
efdefb1b   孙向锦   添加语言English
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
  		});
  	}
  			
  function getQueryString(name) {
  	  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  	  var r = window.location.search.substr(1).match(reg);
  	  if (r != null) return unescape(r[2]); return null;
    	}
  	var PAPER_ID=getQueryString("PAPER_ID");
  	var classId=getQueryString("classId");
  	var userid=getQueryString("userid");
  	
  	var gradleId =  getQueryString("gradleid");
  	
  	var _html="";
  	var question_id_arry="";
  	$(document).ready(function(){
  		window.top.loading.remove();
  			var data=JSON.parse(sessionStorage.getItem("data")); 
  				console.log(data);
  				$("#paper_title").html(data.title);
  				$("#time").html(data.exam_time);
  				if(data.questions.length>0){
  					for(var i=0;i<data.questions.length;i++){
  						question_id_arry+=data.questions[i].question_id+',';
  					}
  					getQuestionInfo(question_id_arry,data.questions);
  				}
  		
  	})
  	function getQuestionInfo(id,knowledge_ids){      //获取试题详情
  		$.ajax({
  			url:url+"/SunvoteEducation/api/v1/question",
  			async:true,
  			type:"post",
  			data:{ID:id},
  			success:function(data){
  				console.log(data);
  				if(data.data.length>0){				
  					for(var i=0;i<data.data.length;i++){
0e4da37e   孙向锦   学校管理员界面
49
  						_html += '<li class="question_li" data-id="'+data.data[i].QUESTION_ID+'" data-knowledge="' +getknowledgeid(data.data[i].QUESTION_ID,knowledge_ids) + '"><div class="stem"></div><div class="option"><ul></ul><div class="clearfix"></div></div><div class="resolve"><div class="resolve_box"><p>【Answer】 '+data.data[i].ANSWER+'</p><p><span>【Analysis】</span>'+data.data[i].ANALYSIS+'</p></div><div class="clearfix"></div></div><div class="star_box"><div class="col-md-6 move"><img src="../static/images/up_ico.png" class="up"/><img src="../static/images/down_ico.png" class="down"/></div><div class="col-md-6"><div class="star"><span style="float:left;">Difficulty Level </span></div><div class="resolve_click"><a  onclick="slide($(this))">View Analysis</a></div></div><div class="clearfix"></div></div></li>';
efdefb1b   孙向锦   添加语言English
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
  					}
  					console.log(_html);
  					$(".analysis ul").html(_html);
  					for(var j=0;j<data.data.length;j++){
  						var option_html="";
  						var sum=0;
  						var right_num=0;
  						var data1=[];
  						var data2=[];
  						var answer="";
  						var color=[];
  						$(".analysis li .stem").eq(j).append('<span class="li_index">'+(j+1)+'</span>、'+data.data[j].CONTENT);
  						var arry_option=data.data[j].OPTION_CONTENT;
  
  						for(var x=0;x<arry_option.length;x++){
  							option_html += '<li><span>'+String.fromCharCode(64 + parseInt(x+1))+'.</span>'+arry_option[x]+'</li>';
  						}
  						$(".option").eq(j).html(option_html);
  						star(j,parseInt(data.data[j].DIFFICULTY));
  					}
  				}
  			},
  			error: function (XMLHttpRequest, textStatus, errorThrown) {
  				// 错误信息   
  				alert("Status code:"+XMLHttpRequest.status+"Status:"+XMLHttpRequest.readyState+"Wrong massage:"+textStatus+"");
  				window.top.loading.remove();
  			}
  		})
  		
  	}
  	
  	function getknowledgeid(question_id,knowledge_ids){
  		for(var i = 0 ; i < knowledge_ids.length; i++){
  			if(knowledge_ids[i].question_id == question_id){
  				return knowledge_ids[i].knowledge_id;
  			}
  		}
  		return '';
  		
  	}
  	function star(index,num){                //难度星级
  			$(".star").eq(index).append('<ul></ul>');
  			var li_html="";
  			for(var i=1;i<=num;i++){
  				li_html +='<li class="on"></li>';
  			}
  			for(var j=num;j<5;j++){
  				li_html += '<li class="off"></li>';
  			}
  			
  			$(".star").eq(index).find("ul").html(li_html);
  		}
  	$(document).on('click', '.move img', function(event) {           //上移、下移
  		  event.preventDefault();
  		  var parent=$(this).closest("li");
  		  var this_index=parent.children(".stem").find(".li_index").html();
  		  var up_index=parent.prev().children(".stem").find(".li_index").html()
  		  console.log(this_index);
  		  console.log(up_index);
  		  var parents=$(this).closest(".analysis").children("ul");
  		  var len=parents.children().length;
  		  if(($(this).is(".up") || $(this).is(".top")) && parent.index()==0){
  		   alert("Stikied!!");
  		   return false;
  		  }else if(($(this).is(".down") || $(this).is(".bottom")) && parent.index()==len-1){
  		   alert("Bottomed!");
  		   return false;
  		  }
  		  switch (true) {
  		   case $(this).is(".up"):
  			var prev = parent.prev();
  			var this_index=parent.children(".stem").find(".li_index").html();
  			var up_index=prev.children(".stem").find(".li_index").html();
  			prev.children(".stem").find(".li_index").html(this_index);
  			parent.children(".stem").find(".li_index").html(up_index);
  			parent.insertBefore(prev);
  			break;
  		   case $(this).is(".down"):
  			var next = parent.next();
  			var this_index=parent.children(".stem").find(".li_index").html();
  			var up_index=next.children(".stem").find(".li_index").html();
  			next.children(".stem").find(".li_index").html(this_index);
  			parent.children(".stem").find(".li_index").html(up_index);
  			parent.insertAfter(next);
  			break;
  		   case $(this).is(".top"):
  			parents.prepend(parent);
  			break;
  		   case $(this).is(".bottom"):
  			parents.append(parent);
  			break;
  		  }
  	});
  	 $(".save").click(function(){          //保存,提交试卷
  		 	var question_arry=[];
  			for(var i=0;i<$(".question_li").length;i++){
  				question_arry[i]={
  						score: "0",
  						part_score: "0",
  						question_id: $(".question_li").eq(i).attr("data-id"),
  						knowledge_id: $(".question_li").eq(i).attr("data-knowledge"),
  						rank: i.toString(),
  						no_name: i.toString()
  					};
  				
  			}
  			var data={
  				title: $("#paper_title").html(),
  				exam_time: $("#time").html(),
  				paper_type: "101",
  				subject_id: subjectId,
  				grade_id: gradleId,
  				class_id: classId,
  				user_id: userid,
  				score: "100",
  				questions: question_arry
  			};
  
  			$.ajax({
  			url:url+"/SunvoteEducation/api/v1/publishpaper",
  			async:false,
  			type:"post",
  			dataType: "json",
  			headers: {'Content-Type': 'application/json'},
  			data:JSON.stringify(data),
  			success:function(data){
  				alert("Success");
  				window.history.go(-2);
  			},
  			error: function (XMLHttpRequest, textStatus, errorThrown) {
  				// 错误信息   
  				alert("Status code:"+XMLHttpRequest.status+"Status:"+XMLHttpRequest.readyState+"Wrong massage:"+textStatus+"");
  				window.top.loading.remove();
  			}
  		})	
  	 })