index.js 一种js的写法模式

/**
 * 教师端——检查作业
 * Created with Eclipse.
 * User: taomeng@iflytek.com
 * Date: 15-07-14
 * Time: 上午11:09
 */
(function(win){
	
	var CheckHomework = function(){
		
	};
	
	CheckHomework.prototype.init = function(){
		this.analysisEvent();
		this.mouseoverEvent();
	};
	/**
	 * 显示已完成部分完成未完成学生信息 mouseover事件
	 */
	CheckHomework.prototype.mouseoverEvent = function(){
		$("div.check_hw_tit").hover(function(){
			$("div.check_hw_dl.hidenone").removeClass("hidenone");
		},function(){
			$("div.check_hw_dl").addClass("hidenone");
		});
	};
	CheckHomework.prototype.analysisEvent = function(){
		var _this = this;
		var flagIds = []; //存放已点击过的题目
		$("div.tip .detail").click(function(){
			var html = "";
			var  _Dthis = this;
			var topicId = $(this).data("topicid");
			var div = $("div#analysisContain_"+topicId);
			div.toggle("fast",function(){
				if($(_Dthis).hasClass("detail")){
					$(_Dthis).removeClass("detail").addClass("unopen").html("收起解析");
				}else{
					$(_Dthis).removeClass("unopen").addClass("detail").html("查看解析");
				}
			});
			
			if(flagIds.join().indexOf(topicId) == -1){ //如果已经加载过解析就不再请求
				_this.getAnalysis(homeworkId,topicPackId,topicId,function(result){
					var isSubjective = result.topicDetail.section.isSubjective;
					if(isSubjective == false && result.topicDetail.multiSubTopic == false){
						result = _this.geneResult(result);
					}
					flagIds.push(topicId);
					html = __analysisTemplate__({"topicDetail":result});
					div.html(html);
					
					//如果是客观题大题带小题的 选择题 则使用hightcharts展示
					if(result.topicDetail.multiSubTopic){
						var data = _this.geneChartsData(result);
						chartsShow(topicId+"_rate",data,1);
					}
				});
			}
			
		});
	};
	/**
	 * 构造前台所需结构
	 * @param result
	 */
	CheckHomework.prototype.geneResult = function(result){
		result.answerStudents = result.topicStatOfClass.rightCountOfTopicPack +  result.topicStatOfClass.wrongCountOfTopicPack;
		var subTopics = result.topicDetail.subTopics;
		var subs = result.topicStatOfClass.optionAnswerStat;
		for(var i=0; i<subTopics.length; i++){
			var subTopic = subTopics[i];
			var sub = subs[i];
			for(var j=0; j<subTopic.options.length; j++){
				var opt = sub[j];
				if(opt){
					subTopic.options[j].count = opt.answerCount;
				}else{
					subTopic.options[j].count = 0;
				}
			}
		}
		return result;
	};
	
	CheckHomework.prototype.getAnalysis = function(homeworkId,topicPackId,topicId,callback){
		Request.sendPostRequest(basePath + "/homework/sumHomework/getAnalysis/", 
				{"homeworkId":homeworkId,"topicPackId":topicPackId,"topicId":topicId,"classId":classId}, callback);
	};
	CheckHomework.prototype.geneChartsData = function(data){
		var result = {};
		//1. 题号列表(x轴用)
		result.categories = [];
		//2. y轴数据用
		result.series_temp = [];
		
		//2.1 正确答案
		var rightObj = {};
		rightObj.name = "正确选项";
		rightObj.data = []; //用来展示图标高度(人数为0时,为了展示柱状图高度 用1.00008代替)
		rightObj.count = []; //选择正确选项的人数
		rightObj.color = "#18a468";
		
		//2.2 错误答案
		var wrongObj = {};
		wrongObj.name = "错误选项";
		wrongObj.data = []; //用来展示图标高度(选错选项的人数之和)
		wrongObj.count = []; //选择错误选项的人数
		wrongObj.color = "#ff6a60";
		
		for(var i=0; i<data.seqtNoOfTopicPack.length; i++){
			result.categories.push(data.seqtNoOfTopicPack[i]+"");
			var subTopic = data.topicDetail.subTopics[i];
			//每一小题的答案
			var answer = subTopic.answer;
			//每一小题的答题情况
			var subStat = data.topicStatOfClass.optionAnswerStat[i];
			if(subStat){
				var rightCount = 0;
				var wrongCount = 0;
				for(var j=0;j<subStat.length; j++){
					if(answer == subStat[j].option.id){
						rightCount += subStat[j].answerCount;
					}else{//选择错误答案的人数之和
						wrongCount += subStat[j].answerCount;
					}
					rightObj.data.push(rightCount == 0 ? 1.00008 : rightCount);
					rightObj.count.push(rightCount);
					wrongObj.data.push(wrongCount == 0 ? 1.00008 : wrongCount);
					wrongObj.count.push(wrongCount);
				}
			}else{ //如果没有小题答题情况,则默认该小题答对人数为0
				rightObj.data.push(1.00008);
				rightObj.count.push(0);
				wrongObj.data.push(1.00008);
				wrongObj.count.push(0);
			}
		}
		
		result.series_temp.push(rightObj);
		result.series_temp.push(wrongObj);
		
		return result;
	};
	CheckHomework.prototype.init3 = function(){
		
	};


	/**
	 * 二维码展示
	 */
	CheckHomework.prototype.devShowTwoCode = function (obj) {
		var itemId = $(obj).attr("topicId");
		var dataId = "#img_" + itemId;
		(function(itemId, dataId){
			$(dataId).attr("src", basePath + "/class/generateTopicQRCode/?topicId=" + itemId);
			$(dataId).dialog({
				dialogClass: "alert",
				height: "auto",
				width: "auto",
				modal: true,
				overlay: {
					backgroundColor: '#000',
					opacity: 0.5
				}
			});
			//隐藏title
			$(".ui-dialog-titlebar").hide();

			$(".ui-widget-overlay").click(function () {
				$(dataId).dialog("close");
			})
		})(itemId, dataId);
	},
	
	$(function(){
		var check = new CheckHomework();
		check.init();

		$(".dev_showTwoCode").click(function () {
			check.devShowTwoCode(this);
		});

		$(".dev_hurry").on("click", function(){
			var hwId = $(this).data("id");
			var classId = $(this).data("classid");
			$.ajax({
				type:"GET",
				url: basePath + "/homework/sumHomework/pushHomework/",
				data:{homeworkId:hwId,classId:classId},
				dataType:"json",
				success: function(result){
					if(result.result == "success"){
						artDialogCommon.autoClosed(2, "已提醒同学们按时交作业!");
					}else{
						artDialogCommon.autoClosed(2, "已提醒同学们按时交作业");
					}
				},
				error:function(msg){
					artDialogCommon.autoClosed(2, "已提醒同学们交作业");
				}
			});
		});
	});
})(window);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值