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.

720 lines
24 KiB
JavaScript

1 year ago

var QuestionOption = new arrayHelper("Sort");//选项
var QuestionAnswer = new arrayHelper("Sort");//答案
var QuestionAttachments = new arrayHelper("Name");//附件
var CurQuestionCount = 0;
$(function () {
//文件选择
$("#FileChoose4").click(function () {
$("#HFilePath4").click();
});
//将file的值赋值给input
$("#HFilePath4").live("change", function () {
var filepath = $(this).val();
$("#filePath4").val(filepath);
});
//上传附件按钮
$("#btnAdd4").click(function () {
dialogHelper.Show("addpop4", 756);
$("#txtResourceName4").val("");
$("#filePath4").val("");
});
//附件确定按钮
$("#FileUpload4").click(function () {
FileUpload4();
});
//附件上传取消按钮
$("#addclose4").click(function () {
//$(".popup").hide();
//$(".windowBg").hide();
//$("#addpop4").hide();
dialogHelper.Close("addpop4");
$("#txtResourceName4").val("");
$("#filePath4").val("");
var CurQuestionCounts = $("#CurQuestionCount4").html();
QuestionAttachments.Remove(CurQuestionCounts);
});
//保存按钮
$("#preserve4").click(function () {
//章节Id
var TheoryChapterId = $.getUrlParam("TheoryChapterId");
var typeid = $.getUrlParam("typeid");
var PaperId = $("#TestPapersId").val();
AddTitle4(TheoryChapterId, typeid, PaperId);
});
});
//加载试题
function LoadTitle4(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 != "") {
$("#Context4").val(mode.Context);
$("#Analysis4").val(mode.Analysis);
$("#option4").find("li").remove();
$("#QuestionIdAdd4").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);
});
}
createOptions4();
}
});
}
var type = "";
//查询对应题型
function SelectTitle4(strList) {
//题型下拉列表
selectHelper.GetSelect({
url: "/Teacher/TheoryQuestion/TiXingSelList",
Id: "#TypeName",
value: "全部",
data: { strList: strList }
});
}
var Index = 0;
//保存题目
function AddTitle4(TheoryChapterId, typeid, PaperId) {
if ($("#preserve4").val() == "编辑") {
$("#preserve4").val("保存");
//启用文本框
$("#Context4").attr('disabled', false);
//选项
var Fobj = $("#option4").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();
});
$("#btnAdd4").attr('disabled', false);
//添加选项按
$("#Add").hide();
//附件
var Fobj = $("#Dappendix4").find("a");
$.each(Fobj, function (i, n) {
$(n).find("b").show();
});
//解析
$("#Analysis4").attr('disabled', false);
} else {
if (!VerificationHelper.checkFrom("popQuestionBankAdd5")) {
return false;
}
QuestionOption.RemoveAll();//选项
QuestionAnswer.RemoveAll();//答案
//添加试题
var obg = new Object();
obg["Id"] = $("#QuestionIdAdd4").val();//Id
obg["Context"] = $("#Context4").val();//题干
obg["LibraryID"] = 1;//所属题库(理论考核/认证考试)
obg["StructType"] = 4;//题目类型(枚举)
obg["CharpterID"] = typeid;//认证类型Id/章节Id(对应下面的题型)
obg["Analysis"] = $("#Analysis4").val();//解析
obg["Status"] = 1;//状态 开启
obg["PaperId"] = PaperId;//状态 开启
obg["AnswerList"] = QuestionAnswer.GetList();//答案
obg["AttachmentList"] = QuestionAttachments.GetList();//附件
$.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;
$("#QuestionIdAdd4").val(data.result);
$("#preserve4").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");
$("#upward4").attr('disabled', false);
$("#upward4").css("background-color", "#00a2e2");
$("#down4").attr('disabled', false);
$("#down4").css("background-color", "#00a2e2");
//禁用文本框
$("#Context4").attr('disabled', true);
$("#btnAdd4").attr('disabled', true);
//附件
var Fobj = $("#Dappendix4").find("a");
$.each(Fobj, function (i, n) {
$(n).find("b").hide();
});
//解析
$("#Analysis4").attr('disabled', true);
if (Index == 0) {
$("#upward4").attr('disabled', true);
$("#upward4").css("background-color", "#808080");
}
//QuestionOption.RemoveAll();//选项
QuestionAnswer.RemoveAll(); //答案
QuestionAttachments.RemoveAll(); //附件
ShowQuestionsList("", "");
}
});
}, error: function (msg) {
$(".background,.progressBar").hide();
}
});
}
}
//文件上传
function FileUpload4() {
var chapterId = $.getUrlParam("TheoryChapterId");
//var resourceName = $.trim($("#txtResourceName4").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 = $("#filePath4").val();
if (filePath == "") {
dialogHelper.Error({ context: "请选择要上传的文件!" });
return false;
}
//文件上传
$.ajaxFileUpload({
url: "/Teacher/TheoryQuestion/UploadFile",
secureuri: false,
fileElementId: 'HFilePath4',
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);
//生成附件
createOptions4();
$("#HFilePath4").val("");
$("#txtResourceName4").val("");
$("#filePath4").val("");
$("#txtResourceName4").val("");
$("#filePath4").val("");
//$(".popup").hide();
//$(".windowBg").hide();
//$(".warn-box").hide();
// $("#resourceList").empty();
ShowQuestionsList("", "");
dialogHelper.Close("addpop4");
}
});
}
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 UploaDappendix4(valu) {
var list = $("#Dappendix4").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 createOptions4() {
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 + '">附件' + Num4((i + 1)) + '</span>';
html += '<b class="close" tag="' + n.Url + '" onclick="DeleteAttachments(this)"></b>';
html += '</a>';
});
$("#Dappendix4").html(html);
}
function Num4(valu) {
switch (valu) {
case 1:
return "一";
break;
case 2:
return "二";
break;
case 3:
return "三";
break;
};
}
//删除上传文件
function DeleteAttachments4(valu) {
var url = $(valu).attr("tag");
QuestionAttachments.Remove(url);
$(valu).parent().remove();
}
//返回按钮
function ComeBack4() {
if ($("#Context4").attr("disabled") != "disabled") {
dialogHelper.Confirm({
content: "当前试题未保存,是否继续退出?", success: function () {
dialogHelper.Close("popQuestionBankAdd5");
ShowQuestionsList("", "");
},
cancle: function () {
}
});
} else {
dialogHelper.Close("popQuestionBankAdd5");
ShowQuestionsList("", "");
}
}
//下拉框的改变事件
function SelectChange4(valu) {
//类型Id
var typeid = 0;
//获得界面题型名称
var typeName = $(valu).find("option:selected").text();
//章节Id
var TheoryChapterId = $.getUrlParam("TheoryChapterId");
//章节名称
var ChapterName = unescape($.getUrlParam("ChapterName"));
var CertificationId = $.getUrlParam("CertificationId");
//题目数量
var CurQuestionCount = 0;
$.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 GetTitleCount4(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 AddTitleClick4() {
//清除集合
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);
$("#CurQuestionCount4").html(count + 1);
//清空文本
$("#Context4").val("");
$("#Analysis4").val("");
$("#Context4").attr('disabled', false);
$("#Analysis4").attr('disabled', false);
$("#preserve4").val("保存");
//选项
var Fobj = $("#option4").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");
$("#upward4").attr('disabled', true);
$("#upward4").css("background-color", "#808080");
$("#down4").attr('disabled', true);
$("#down4").css("background-color", "#808080");
}
//上一题
function Thelast4() {
//章节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($("#CurQuestionCount4").html());
if (count == 1) {
Index = 0;
$("#upward4").attr("disabled", true);
$("#upward4").css("background-color", "#808080");
} else {
$("#upward4").attr("disabled", false);
$("#upward4").css("background-color", "#00a2e2");
}
if ($("#down4").attr("disabled") == "disabled") {
$("#down4").attr("disabled", false);
$("#down4").css("background-color", "#00a2e2");
}
if (mode != undefined) {
var html = "<option text='" + mode.StrStructType + "'>" + mode.StrStructType + "</option>";
$("#TypeName4").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($("#CurQuestionCount4").html());
if (count > 1) {
$("#CurQuestionCount4").html(count - 1);
}
$("#Context4").val(mode.Context);
$("#Analysis4").val(mode.Analysis);
$("#option4").find("li").remove();
$("#Id").val(mode.Id);
}
//附件
if (mode.AttachmentList != null) {
$.each(mode.AttachmentList, function (i1, n1) {
QuestionAttachments.Add(n1);
});
}
createOptions4();
}
}
});
jinyong()
}
var styles = 0;
//下一题
function Thedown4() {
//章节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>";
$("#TypeName4").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($("#CurQuestionCount4").html());
$("#CurQuestionCount4").html(count + 1);
$("#Context4").val(mode.Context);
$("#Analysis4").val(mode.Analysis);
$("#option4").find("li").remove();
$("#Id").val(mode.Id);
}
//附件
if (mode.AttachmentList != null) {
$.each(mode.AttachmentList, function (i1, n1) {
QuestionAttachments.Add(n1);
});
}
createOptions4();
if ($("#upward3").attr("disabled") == "disabled") {
$("#upward3").attr("disabled", false);
$("#upward3").css("background-color", "#00a2e2");
}
}
}
});
jinyong();
}
}
//禁用文本
function jinyong4() {
//禁用文本框
$("#Context4").attr('disabled', true);
//选项
var Fobj = $("#option4").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();
});
$("#btnAdd4").attr('disabled', true);
//添加选项按
$("#Add4").hide();
//附件
var Fobj = $("#Dappendix4").find("a");
$.each(Fobj, function (i, n) {
$(n).find("b").hide();
});
//解析
$("#Analysis4").attr('disabled', true);
}