You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

906 lines
30 KiB
JavaScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

var QuestionOption = new arrayHelper("Sort");//选项
var QuestionAnswer = new arrayHelper("Sort");//答案
var QuestionAttachments = new arrayHelper("Name");//附件
var CurQuestionCount = 0;
$(function () {
//文件选择
$("#FileChoose").click(function () {
$("#HFilePath3").click();
});
//将file的值赋值给input
$("#HFilePath3").live("change", function () {
var filepath = $(this).val();
$("#filePath3").val(filepath);
});
//上传附件按钮
$("#btnAdd3").click(function () {
dialogHelper.Show("addpop3", 756);
$("#txtResourceName3").val("");
$("#filePath3").val("");
});
//附件确定按钮
$("#FileUpload3").click(function () {
FileUpload3();
});
//附件上传取消按钮
$("#addclose3").click(function () {
//$(".popup").hide();
//$(".windowBg").hide();
//$("#addpop3").hide();
dialogHelper.Close("addpop3");
$("#txtResourceName3").val("");
$("#filePath3").val("");
var CurQuestionCounts = $("#CurQuestionCount3").html();
QuestionAttachments.Remove(CurQuestionCounts);
});
//保存按钮
$("#preserve3").click(function () {
//章节Id
var TheoryChapterId = $.getUrlParam("TheoryChapterId");
var typeid = $.getUrlParam("typeid");
var PaperId = $("#TestPapersId").val();
AddTitle3(TheoryChapterId, typeid, PaperId);
});
});
//加载试题
function LoadTitle3(QuestionId) {
$.ajax({
url: "/Teacher/TheoryQuestion/GetQuestionObj",
async: false,
type: "POST",
data: {
QuestionId: QuestionId,
},
success: function (data) {
QuestionOption.RemoveAll();//选项
QuestionAnswer.RemoveAll(); //答案
QuestionAttachments.RemoveAll(); //附件
var mode = data.TE;
if (mode.Context != "") {
$("#Context3").val(mode.Context);
$("#Analysis3").val(mode.Analysis);
// $("#option3").find("li").remove();
$("#QuestionIdAdd3").val(mode.Id);
}
//选项
if (mode.OptionList != null) {
var html = "";
$.each(mode.OptionList, function (i, n) {
QuestionOption.Add(n);
});
}
//附件
if (mode.AttachmentList != null) {
$.each(mode.AttachmentList, function (i1, n1) {
QuestionAttachments.Add(n1);
});
}
createOptions3();
CreateSelect3();
//答案
if (mode.AnswerList != null) {
$.each(mode.AnswerList, function (i2, n2) {
QuestionAnswer.Add(n2);
switch (n2.Answer1) {
case 0:
$("#A3").attr("checked", true);
break;
case 1:
$("#B3").attr("checked", true);
break;
case 2:
$("#C3").attr("checked", true);
break;
case 3:
$("#D3").attr("checked", true);
break;
default:
$("#option3").find("li:eq(4)").find("input").attr("checked", true);
break;
}
});
}
}
});
}
var type = "";
//查询对应题型
function SelectTitle3(strList) {
//题型下拉列表
selectHelper.GetSelect({
url: "/Teacher/TheoryQuestion/TiXingSelList",
Id: "#TypeName",
value: "全部",
data: { strList: strList }
});
}
var Index = 0;
//保存题目
function AddTitle3(TheoryChapterId, typeid, PaperId) {
if ($("#preserve3").val() == "编辑") {
$("#preserve3").val("保存");
//启用文本框
$("#Context3").attr('disabled', false);
//选项
var Fobj = $("#option3").find("li");
$.each(Fobj, function (i, n) {
$(n).find("input:eq(0)").attr('disabled', false);
$(n).find("input:eq(1)").attr('disabled', false);
$(n).find("span").show();
});
$("#btnAdd").attr('disabled', false);
//添加选项按
$("#Add").hide();
//附件
var Fobj = $("#Dappendix3").find("a");
$.each(Fobj, function (i, n) {
$(n).find("b").show();
});
//解析
$("#Analysis3").attr('disabled', false);
} else {
if (!VerificationHelper.checkFrom("popQuestionBankAdd3")) {
return false;
}
QuestionOption.RemoveAll();//选项
QuestionAnswer.RemoveAll();//答案
//添加试题
var obg = new Object();
obg["Id"] = $("#QuestionIdAdd3").val();//Id
obg["Context"] = $("#Context3").val();//题干
obg["LibraryID"] = 1;//所属题库(理论考核/认证考试)
obg["StructType"] = 3;//题目类型(枚举)
obg["CharpterID"] = typeid;//认证类型Id/章节Id(对应下面的题型)
obg["Analysis"] = $("#Analysis3").val();//解析
obg["Status"] = 1;//状态 开启
obg["PaperId"] = PaperId;//状态 开启
//添加选项和答案
var num = 0;
var num2 = 0;
var Fobj = $("#option3").find("li").find("label").find("input");
$.each(Fobj, function (i, n) {
var obj = new Object();
//obj["QuestionId"] = CurQuestionCount;
obj["OptionName"] = $(n).val();
obj["Sort"] = i;
QuestionOption.Add(obj);
num2 = num2 + 1;
//选中的为答案
if ($(n).attr("checked") == "checked") {
var objs = new Object();
objs["Answer1"] = i;
objs["Sort"] = i;
QuestionAnswer.Add(objs);
num = num + 1;
}
});
obg["OptionList"] = QuestionOption.GetList();//选项
obg["AnswerList"] = QuestionAnswer.GetList();//答案
obg["AttachmentList"] = QuestionAttachments.GetList();//附件
if (num == 0) {
dialogHelper.Error({ content: "请选择正确答案!", success: function () { } });
return false;
}
$.ajax({
url: "/Teacher/TheoryQuestion/AddUpdateQuestion2",
type: "POST",
async: false,
dataType: "json",
data: JSON.stringify(obg),
contentType: "application/json",
success: function (data) {
dialogHelper.Success({
content: "保存成功!", success: function () {
Index = data.index;
$("#QuestionIdAdd3").val(data.result);
$("#preserve3").val("编辑");
//更新题目选择JS缓存
var old_question = AlreadyQuestionsHelper.FindRecord(obg["Id"]);
if (old_question != null && old_question != undefined) {
AlreadyQuestionsHelper.Remove(obg["Id"]);
old_question.QuesionId = data.result;
AlreadyQuestionsHelper.Add(old_question);
}
//激活按钮
$("#AddTitle").attr('disabled', false);
$("#AddTitle").css("background-color", "#00a2e2");
$("#upward3").attr('disabled', false);
$("#upward3").css("background-color", "#00a2e2");
$("#down3").attr('disabled', false);
$("#down3").css("background-color", "#00a2e2");
//禁用文本框
$("#Context3").attr('disabled', true);
//选项
var Fobj = $("#option3").find("li");
$.each(Fobj, function (i, n) {
$(n).find("input:eq(0)").attr('disabled', true);
$(n).find("input:eq(1)").attr('disabled', true);
$(n).find("span").hide();
});
$("#btnAdd").attr('disabled', true);
//添加选项按
$("#Add").hide();
//附件
var Fobj = $("#Dappendix3").find("a");
$.each(Fobj, function (i, n) {
$(n).find("b").hide();
});
//解析
$("#Analysis3").attr('disabled', true);
if (Index == 0) {
$("#upward3").attr('disabled', true);
$("#upward3").css("background-color", "#808080");
}
QuestionOption.RemoveAll();//选项
QuestionAnswer.RemoveAll(); //答案
QuestionAttachments.RemoveAll(); //附件
ShowQuestionsList("", "");
}
});
}, error: function (msg) {
$(".background,.progressBar").hide();
}
});
}
}
//删除选项
function DeleteSelect3(obj) {
$(obj).parent().remove();
var optionName = $(obj).parent().find("input:eq(1)").val();
QuestionOption.Remove(optionName);
$(obj).parent().remove();
var Fobj = $("#option3").find("li");
var num = 0;
$.each(Fobj, function (i, n) {
var valu = Option(i);
var li = $(n).find("label").html('<label><input name="dm" type="radio">' + valu);
num = num + 1;
});
if (num < 5) {
$("#Add").show();
}
}
//添加选项
function AddOption3() {
var html = '<li><label><input name="dm" type="radio">D</label><div><input type="text" id="D" class="inputtext IsRequired IsMaxLength IsMinLength" msgname="选项" maxlength="80" minlength="1" /></div><span class="close" onclick="DeleteSelect(this)"></span></li>';
$("#Add").prevAll("li:eq(0)").after(html);
var Fobj = $("#option3").find("li");
var num = 0;
$.each(Fobj, function (i, n) {
var valu = Option(i);
var li = $(n).find("label").html('<label><input name="dm" type="radio">' + valu);
num = num + 1;
});
if (num >= 5) {
$("#Add3").hide();
}
}
//文件上传
function FileUpload3() {
var chapterId = $.getUrlParam("TheoryChapterId");
//var resourceName = $.trim($("#txtResourceName3").val());
//resourceName = resourceName.replace(/[<>&"]/g, function (c) { return { '<': '&lt;', '>': '&gt;', '&': '&amp;', '"': '&quot;', '"': '&quot;', "'": '&prime;', "'": '&prime;' }[c]; })
var resourceName = "";
var i = $("#Dappendix").find("a").length;
resourceName = "附件" + Num((i + 1));
var num = UploaDappendix2(resourceName);
if (num == 3) {
dialogHelper.Error({
content: "本章节资源数量超过最大限制3个"
})
return;
}
if (num == 5) {
dialogHelper.Error({
content: "已存在该资源名称,请重新命名"
})
return;
}
if (chapterId != "" && chapterId != 0) {
var filePath = $("#filePath3").val();
if (filePath == "") {
dialogHelper.Error({ context: "请选择要上传的文件!" });
return false;
}
//文件上传
$.ajaxFileUpload({
url: "/Teacher/TheoryQuestion/UploadFile",
secureuri: false,
fileElementId: 'HFilePath3',
dataType: 'json',
data: {
resourceName: resourceName
},
success: function (data, status) {
$(".window-mask,.progressBar").hide();
if (data.IsSuccess) {
dialogHelper.Success({
content: "资源上传成功",
success: function () {
var obj = new Object();
//obj["QuestionId"] = CurQuestionCount;
obj["Name"] = resourceName;
obj["Url"] = $("#HFilePath3").val();
obj["FileUrl"] = data.Data.TE;
QuestionAttachments.Add(obj);
//生成附件
createOptions3();
$("#HFilePath2").val("");
$("#txtResourceName3").val("");
$("#filePath2").val("");
$("#txtResourceName3").val("");
$("#filePath3").val("");
//$(".popup").hide();
//$(".windowBg").hide();
//$(".warn-box").hide();
// $("#resourceList").empty();
ShowQuestionsList("", "");
dialogHelper.Close("addpop3");
}
});
}
else {
if (data.error != "" && data.error != undefined) {
dialogHelper.Error({
content: data.error,
success: function () {
}
});
}
else {
dialogHelper.Error({
content: "您上传的资源超过500KB请重新上传",
success: function () {
}
});
}
}
},
error: function (data, status, e) {
dialogHelper.Error({ context: "上传异常" });
}
});
}
else { dialogHelper.Error({ context: "系统出错,没有选中章节" }); }
}
function UploaDappendix3(valu) {
var list = $("#Dappendix3").find("a");
var num = 0;
$.each(list, function (i, n) {
num = num + 1;
var a = $(n).find("span").attr("tag");
if (a == valu) {
num = 5;
}
});
return num;
}
//生成附件
function createOptions3() {
var list = QuestionAttachments.GetList();
var html = "";
$.each(list, function (i, n) {
html += '<a href="#">';
html += '<img src="/Content/images/text-icon.png">';
html += '<span tag="' + n.Name + '" title="' + n.Name + '">附件' + Num3((i + 1)) + '</span>';
html += '<b class="close" tag="' + n.Name + '" onclick="DeleteAttachments3(this)"></b>';
html += '</a>';
});
$("#Dappendix3").html(html);
}
function Num3(valu) {
switch (valu) {
case 1:
return "一";
break;
case 2:
return "二";
break;
case 3:
return "三";
break;
};
}
//生成选项
function CreateSelect3()//生成选项
{
var list = QuestionOption.GetList();
$.each(list, function (i, n) {
switch (n.Sort) {
case 0: $("#labA").text(n.OptionName); break;
case 1: $("#labB").text(n.OptionName); break;
default: break;
}
});
}
//删除上传文件
function DeleteAttachments3(valu) {
var url = $(valu).attr("tag");
QuestionAttachments.Remove(url);
$(valu).parent().remove();
}
//返回按钮
function ComeBack3() {
if ($("#Context3").attr("disabled") != "disabled") {
dialogHelper.Confirm({
content: "当前试题未保存,是否继续退出?", success: function () {
dialogHelper.Close("popQuestionBankAdd3");
ShowQuestionsList("", "");
},
cancle: function () {
}
});
} else {
dialogHelper.Close("popQuestionBankAdd3");
ShowQuestionsList("", "");
}
}
//选项
function Option3(valu) {
var option = "";
switch (valu) {
case 0:
option = "A";
break;
case 1:
option = "B";
break;
case 2:
option = "C";
break;
case 3:
option = "D";
break;
case 4:
option = "E";
break;
}
return option;
}
//下拉框的改变事件
function SelectChange3(valu) {
//类型Id
var typeid = 0;
//获得界面题型名称
var typeName = $(valu).find("option:selected").text();
//章节Id
var TheoryChapterId = $.getUrlParam("TheoryChapterId");
//章节名称
var ChapterName = unescape($.getUrlParam("ChapterName"));
//题目数量
var CurQuestionCount = 0;
var CertificationId = $.getUrlParam("CertificationId");
$.ajax({
url: "/Teacher/TheoryQuestion/GetQuestionTypeList",
type: "POST",
async: false,
data: { charpterId: TheoryChapterId, },
success: function (data) {
var html = "";
$(data).each(function (index, dom) {
if (typeName == dom.TypeName) {
typeid = dom.Id;
CurQuestionCount = dom.CurQuestionCount;
}
});
}
});
switch (typeName) {
case "单选题":
window.location.href = "/Teacher/TheoryQuestion/QuestionBankAdd1?TheoryChapterId=" + TheoryChapterId + "&CertificationId=" + CertificationId + "&typeid=" + typeid + "&ChapterName=" + escape(ChapterName) + "&CurQuestionCount=" + CurQuestionCount + "";//
break;
case "多选题":
window.location.href = "/Teacher/TheoryQuestion/QuestionBankAdd2?TheoryChapterId=" + TheoryChapterId + "&CertificationId=" + CertificationId + "&typeid=" + typeid + "&ChapterName=" + escape(ChapterName) + "&CurQuestionCount=" + CurQuestionCount + "";//
break;
case "判断题":
window.location.href = "/Teacher/TheoryQuestion/QuestionBankAdd3?TheoryChapterId=" + TheoryChapterId + "&CertificationId=" + CertificationId + "&typeid=" + typeid + "&ChapterName=" + escape(ChapterName) + "&CurQuestionCount=" + CurQuestionCount + "";//
break;
case "填空题":
window.location.href = "/Teacher/TheoryQuestion/QuestionBankAdd4?TheoryChapterId=" + TheoryChapterId + "&CertificationId=" + CertificationId + "&typeid=" + typeid + "&ChapterName=" + escape(ChapterName) + "&CurQuestionCount=" + CurQuestionCount + "";//
break;
default:
window.location.href = "/Teacher/TheoryQuestion/QuestionBankAdd4?TheoryChapterId=" + TheoryChapterId + "&CertificationId=" + CertificationId + "&typeid=" + typeid + "&ChapterName=" + escape(ChapterName) + "&CurQuestionCount=" + CurQuestionCount + "";//
break;
}
}
//获取题号
function GetTitleCount3(StructTypeName, CharpterID, Value) {
var count = 0;
$.ajax({
url: "/Teacher/TheoryQuestion/GetTitleCount",
type: "POST",
async: false,
dataType: "json",
data: { StructTypeName: StructTypeName, CharpterID: CharpterID, Values: Value },
success: function (data) {
count = data.Count;
}
});
return count;
}
//新增按钮
function AddTitleClick3() {
//清除集合
QuestionOption.RemoveAll();
QuestionAnswer.RemoveAll();
QuestionAttachments.RemoveAll();
$("#Id").val("0");
//题号加1
var StructTypeName = $("#TypeName").find("option:selected").text();
var typeid = $.getUrlParam("typeid");
var count = GetTitleCount(StructTypeName, typeid);
$("#CurQuestionCount3").html(count + 1);
//清空文本
$("#Context3").val("");
$("#Analysis3").val("");
$("#Context3").attr('disabled', false);
$("#Analysis3").attr('disabled', false);
$("#preserve3").val("保存");
//选项
var Fobj = $("#option3").find("li");
$.each(Fobj, function (i, n) {
$(n).find("input:eq(0)").attr('disabled', false);
$(n).find("input:eq(1)").attr('disabled', false);
$(n).find("span").show();
$(n).find("input:eq(0)").attr("checked", false);
$(n).find("input:eq(1)").val("");
});
//附件
var Fobj = $("#Dappendix3").find("a");
$.each(Fobj, function (i, n) {
$(n).remove();
});
$("#btnAdd").attr('disabled', false);
$("#Add").show();
//屏蔽按钮
$("#AddTitle").attr('disabled', true);
$("#AddTitle").css("background-color", "#808080");
$("#upward2").attr('disabled', true);
$("#upward2").css("background-color", "#808080");
$("#down2").attr('disabled', true);
$("#down2").css("background-color", "#808080");
}
//上一题
function Thelast3() {
//章节Id
var typeid = $.getUrlParam("typeid");
if (typeid == null) {
typeid = 0;
}
var PaperId = $("#TestPapersId").val();
Index = Index - 1;
if (Index < 0) {
Index = 0;
}
//清除集合
QuestionOption.RemoveAll();
QuestionAnswer.RemoveAll();
QuestionAttachments.RemoveAll();
$.ajax({
url: "/Teacher/TheoryQuestion/GetQuestionId",
async: false,
type: "POST",
data: {
Index: Index,
CharpterID: typeid,
PaperId: PaperId
},
success: function (data) {
var mode = data.model;
var count = Number($("#CurQuestionCount3").html());
if (count == 1) {
Index = 0;
$("#upward3").attr("disabled", true);
$("#upward3").css("background-color", "#808080");
} else {
$("#upward3").attr("disabled", false);
$("#upward3").css("background-color", "#00a2e2");
}
if ($("#down3").attr("disabled") == "disabled") {
$("#down3").attr("disabled", false);
$("#down3").css("background-color", "#00a2e2");
}
if (mode != undefined) {
var html = "<option text='" + mode.StrStructType + "'>" + mode.StrStructType + "</option>";
$("#TypeName3").html(html);
if (mode.StrStructType != "单选题" && mode.StrStructType != "多选题" && mode.StrStructType != "判断题") {
$("#xuanxaing3").hide();
$("#xuanxaing2").hide();
$("#xuanxaing1").hide();
} else {
$("#xuanxaing3").show();
$("#xuanxaing2").show();
$("#xuanxaing1").show();
}
if (mode.Context != "") {
var count = Number($("#CurQuestionCount3").html());
if (count > 1) {
$("#CurQuestionCount3").html(count - 1);
}
$("#Context3").val(mode.Context);
$("#Analysis3").val(mode.Analysis);
$("#option3").find("li").remove();
$("#Id").val(mode.Id);
}
//选项
if (mode.OptionList != null) {
var html = "";
$.each(mode.OptionList, function (i, n) {
QuestionOption.Add(n);
});
}
//附件
if (mode.AttachmentList != null) {
$.each(mode.AttachmentList, function (i1, n1) {
QuestionAttachments.Add(n1);
});
}
createOptions3();
CreateSelect3();
//答案
if (mode.AnswerList != null) {
$.each(mode.AnswerList, function (i2, n2) {
QuestionAnswer.Add(n2);
switch (n2.Sort) {
case 0:
$("#A3").attr("checked", true);
break;
case 1:
$("#B3").attr("checked", true);
break;
case 2:
$("#C3").attr("checked", true);
break;
case 3:
$("#D3").attr("checked", true);
break;
default:
$("#option3").find("li:eq(4)").find("input").attr("checked", true);
break;
}
});
}
}
}
});
jinyong()
}
var styles = 0;
//下一题
function Thedown3() {
//章节Id
var typeid = $.getUrlParam("typeid");
if (typeid == null) {
typeid = 0;
}
var PaperId = $("#TestPapersId").val();
//清除集合
QuestionOption.RemoveAll();
QuestionAnswer.RemoveAll();
QuestionAttachments.RemoveAll();
var sty = Index;
Index = Index + 1;
if (Index > 0) {
$.ajax({
url: "/Teacher/TheoryQuestion/GetQuestionId",
async: false,
type: "POST",
data: {
Index: Index,
CharpterID: typeid,
PaperId: PaperId
},
success: function (data) {
var mode = data.model;
styles = data.style;
if (styles == -1) {
$("#down").attr("disabled", true);
$("#down").css("background-color", "#808080");
$("#down2").attr("disabled", true);
$("#down2").css("background-color", "#808080");
$("#down3").attr("disabled", true);
$("#down3").css("background-color", "#808080");
$("#down4").attr("disabled", true);
$("#down4").css("background-color", "#808080");
Index = sty;
} else {
$("#down").attr("disabled", false);
$("#down").css("background-color", "#00a2e2");
$("#down2").attr("disabled", false);
$("#down2").css("background-color", "#00a2e2");
$("#down3").attr("disabled", false);
$("#down3").css("background-color", "#00a2e2");
$("#down4").attr("disabled", false);
$("#down4").css("background-color", "#00a2e2");
}
if (mode != undefined) {
var html = "<option text='" + mode.StrStructType + "'>" + mode.StrStructType + "</option>";
$("#TypeName3").html(html);
if (mode.StrStructType != "单选题" && mode.StrStructType != "多选题" && mode.StrStructType != "判断题") {
$("#xuanxaing3").hide();
$("#xuanxaing2").hide();
$("#xuanxaing1").hide();
} else {
$("#xuanxaing3").show();
$("#xuanxaing2").show();
$("#xuanxaing1").show();
}
if (mode.Context != "") {
var count = Number($("#CurQuestionCount3").html());
$("#CurQuestionCount3").html(count + 1);
$("#Context3").val(mode.Context);
$("#Analysis3").val(mode.Analysis);
$("#option3").find("li").remove();
$("#Id").val(mode.Id);
}
//选项
if (mode.OptionList != null) {
var html = "";
$.each(mode.OptionList, function (i, n) {
QuestionOption.Add(n);
});
}
//附件
if (mode.AttachmentList != null) {
$.each(mode.AttachmentList, function (i1, n1) {
QuestionAttachments.Add(n1);
});
}
createOptions3();
CreateSelect3();
//答案
if (mode.AnswerList != null) {
$.each(mode.AnswerList, function (i2, n2) {
QuestionAnswer.Add(n2);
switch (n2.Sort) {
case 0:
$("#A3").attr("checked", true);
break;
case 1:
$("#B3").attr("checked", true);
break;
case 2:
$("#C3").attr("checked", true);
break;
case 3:
$("#D3").attr("checked", true);
break;
default:
$("#option3").find("li:eq(4)").find("input").attr("checked", true);
break;
}
});
}
if ($("#upward3").attr("disabled") == "disabled") {
$("#upward3").attr("disabled", false);
$("#upward3").css("background-color", "#00a2e2");
}
}
}
});
jinyong();
}
}
//禁用文本
function jinyong3() {
//禁用文本框
$("#Context3").attr('disabled', true);
//选项
var Fobj = $("#option3").find("li");
$.each(Fobj, function (i, n) {
$(n).find("input:eq(0)").attr('disabled', true);
$(n).find("input:eq(1)").attr('disabled', true);
$(n).find("span").hide();
});
$("#btnAdd").attr('disabled', true);
//添加选项按
$("#Add").hide();
//附件
var Fobj = $("#Dappendix3").find("a");
$.each(Fobj, function (i, n) {
$(n).find("b").hide();
});
//解析
$("#Analysis3").attr('disabled', true);
}