题目更新代码编写,表单验证
This commit is contained in:
parent
d4e84057dc
commit
dc9612e102
|
|
@ -4,8 +4,12 @@ import java.util.ArrayList;
|
|||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
import cn.hutool.json.JSONArray;
|
||||
import com.ruoyi.common.json.JSONObject;
|
||||
import com.ruoyi.exam.domain.ExamQuestionCategory;
|
||||
import com.ruoyi.exam.domain.ExamQuestionItem;
|
||||
import com.ruoyi.exam.service.IExamQuestionCategoryService;
|
||||
import com.ruoyi.exam.service.IExamQuestionItemService;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
|
@ -38,6 +42,9 @@ public class ExamQuestionController extends BaseController
|
|||
|
||||
@Autowired
|
||||
private IExamQuestionCategoryService examQuestionCategoryService;
|
||||
|
||||
@Autowired
|
||||
private IExamQuestionItemService examQuestionItemService;
|
||||
|
||||
@RequiresPermissions("exam:examQuestion:view")
|
||||
@GetMapping()
|
||||
|
|
@ -139,6 +146,18 @@ public class ExamQuestionController extends BaseController
|
|||
return toAjax(examQuestionService.insertQuestion(examQuestion,number,content));
|
||||
}
|
||||
|
||||
|
||||
@RequiresPermissions("exam:examQuestion:edit")
|
||||
@Log(title = "问题", businessType = BusinessType.INSERT)
|
||||
@PostMapping("/update")
|
||||
@ResponseBody
|
||||
public AjaxResult update(ExamQuestion examQuestion,@RequestParam(value = "number", required = true) String[] number,
|
||||
@RequestParam(value = "content", required = true) String[] content)
|
||||
{
|
||||
|
||||
return toAjax(examQuestionService.updateQuestion(examQuestion,number,content));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改问题
|
||||
*/
|
||||
|
|
@ -147,7 +166,21 @@ public class ExamQuestionController extends BaseController
|
|||
{
|
||||
ExamQuestion examQuestion = examQuestionService.selectExamQuestionById(id);
|
||||
mmap.put("examQuestion", examQuestion);
|
||||
return prefix + "/edit";
|
||||
ExamQuestionItem examQuestionItem = new ExamQuestionItem();
|
||||
examQuestionItem.setExamQuestionId(id);
|
||||
List<ExamQuestionItem> examQuestionItems = examQuestionItemService.selectList(examQuestionItem);
|
||||
JSONArray arr = new JSONArray();
|
||||
arr.addAll(examQuestionItems);
|
||||
mmap.put("examQuestionItem", arr.toString());
|
||||
String s = "";
|
||||
if(examQuestion.getType().equals("1")){
|
||||
s= "/choiceUpdate";
|
||||
}else if(examQuestion.getType().equals("2")){
|
||||
s = "/morechoiceUpdate";
|
||||
}else{
|
||||
s = "/judgeUpdate";
|
||||
}
|
||||
return prefix + s;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -170,7 +203,8 @@ public class ExamQuestionController extends BaseController
|
|||
@PostMapping( "/remove")
|
||||
@ResponseBody
|
||||
public AjaxResult remove(String ids)
|
||||
{
|
||||
{
|
||||
examQuestionItemService.deleteByQuestionIds(ids);
|
||||
return toAjax(examQuestionService.deleteExamQuestionByIds(ids));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -60,4 +60,5 @@ public interface ExamQuestionItemMapper extends MyMapper<ExamQuestionItem>
|
|||
*/
|
||||
public int deleteExamQuestionItemByIds(String[] ids);
|
||||
|
||||
void deleteByQuestionIds(String[] ids);
|
||||
}
|
||||
|
|
@ -26,5 +26,6 @@ public interface IExamQuestionItemService extends AbstractBaseService<ExamQuesti
|
|||
*/
|
||||
public List<ExamQuestionItem> selectExamQuestionItemList(ExamQuestionItem examQuestionItem);
|
||||
|
||||
|
||||
|
||||
void deleteByQuestionIds(String ids);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,4 +52,6 @@ public interface IExamQuestionService extends AbstractBaseService<ExamQuestion>
|
|||
public int deleteExamQuestionByIds(String ids);
|
||||
|
||||
int insertQuestion(ExamQuestion examQuestion, String[] number, String[] content);
|
||||
|
||||
int updateQuestion(ExamQuestion examQuestion, String[] number, String[] content);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,13 @@ public class ExamQuestionItemServiceImpl extends AbstractBaseServiceImpl<ExamQue
|
|||
{
|
||||
return examQuestionItemMapper.selectExamQuestionItemList(examQuestionItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteByQuestionIds(String ids) {
|
||||
String[] split = ids.split(",");
|
||||
examQuestionItemMapper.deleteByQuestionIds(split);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询问题选项分页列表
|
||||
*
|
||||
|
|
|
|||
|
|
@ -113,4 +113,31 @@ public class ExamQuestionServiceImpl extends AbstractBaseServiceImpl<ExamQuestio
|
|||
return i ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateQuestion(ExamQuestion examQuestion, String[] number, String[] content) {
|
||||
Date date = new Date();
|
||||
examQuestion.setUpdateDate(date);
|
||||
examQuestion.setUpdateBy(ShiroUtils.getLoginName());
|
||||
int i = examQuestionMapper.updateExamQuestion(examQuestion);
|
||||
examQuestion.setCreateDate(null);
|
||||
examQuestion.setUpdateDate(null);
|
||||
List<ExamQuestion> select = examQuestionMapper.selectExamQuestionList(examQuestion);
|
||||
String id = select.get(0).getId();
|
||||
examQuestionItemMapper.deleteByQuestionIds(new String[]{id});
|
||||
ExamQuestionItem examQuestionItem = new ExamQuestionItem();
|
||||
for (int i1 = 0; i1 < number.length; i1++) {examQuestionItem.setContent(content[i1]);
|
||||
examQuestionItem.setNumber(number[i1]);
|
||||
examQuestionItem.setExamQuestionId(select.get(0).getId()+"");
|
||||
examQuestionItem.setCreateDate(date);
|
||||
examQuestionItem.setCreateBy(ShiroUtils.getLoginName());
|
||||
examQuestionItemMapper.insertExamQuestionItem(examQuestionItem);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return i ;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,5 +96,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
|
||||
|
||||
<delete id="deleteByQuestionIds">
|
||||
delete from exam_question_item where exam_question_id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
|
|
@ -0,0 +1,206 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
|
||||
<meta charset="utf-8">
|
||||
<head th:include="include :: header"></head>
|
||||
<body class="white-bg">
|
||||
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
|
||||
<form class="form-horizontal m" id="form-examQuestion-add">
|
||||
<div class="form-group">
|
||||
<input type="hidden" id="id" name="id" th:value="${examQuestion.id}">
|
||||
<input type="hidden" id="categoryId" name="categoryId" th:value="${examQuestion.categoryId}">
|
||||
<input type="hidden" id="type" name="type" th:value="${examQuestion.type}">
|
||||
<input type="hidden" id="answer" name="questionAnswer" th:value="${examQuestion.answer}">
|
||||
<input type="hidden" id="item" name="item" th:value="${examQuestionItem}">
|
||||
<label class="col-sm-3 control-label">问题标题:</label>
|
||||
<div class="col-sm-8">
|
||||
<input id="title" name="title" class="form-control" type="text" th:value="${examQuestion.title}">
|
||||
</div>
|
||||
</div>
|
||||
<!--<div class="form-group">-->
|
||||
<!--<label class="col-sm-3 control-label">问题答案:</label>-->
|
||||
<!--<div class="col-sm-8">-->
|
||||
<!--<input id="answer" name="answer" class="form-control" type="text">-->
|
||||
<!--</div>-->
|
||||
<!--</div>-->
|
||||
|
||||
<div class="form-group" >
|
||||
<label class="col-sm-3 control-label">问题选项:</label>
|
||||
<div class="col-sm-1" style="padding-right: 0px;">
|
||||
<input class="form-control" name="answer" value="A" type="radio" style="margin: 0 0 0;">
|
||||
</div>
|
||||
<div class="col-sm-1" style="padding-right: 0px;padding-left: 0px">
|
||||
<input style="padding: 6px 10px;text-align: center" id="number1" name="number" class="form-control" type="text" value="A" readonly>
|
||||
</div>
|
||||
<div class="col-sm-6" style="padding-left: 0px">
|
||||
<input id="content1" name="content" class="form-control" type="text">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group" >
|
||||
<label class="col-sm-3 control-label"></label>
|
||||
<div class="col-sm-1" style="padding-right: 0px;">
|
||||
<input class="form-control" name="answer" value="B" type="radio" style="margin: 0 0 0;">
|
||||
</div>
|
||||
<div class="col-sm-1" style="padding-right: 0px;padding-left: 0px">
|
||||
<input style="padding: 6px 10px;text-align: center" id="number2" name="number" class="form-control" type="text" value="B" readonly>
|
||||
</div>
|
||||
<div class="col-sm-6" style="padding-left: 0px">
|
||||
<input id="content2" name="content" class="form-control" type="text">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group" id="addOption">
|
||||
<label class="col-sm-4 control-label"></label>
|
||||
<div class="col-sm-7" style="padding-left: 0px">
|
||||
<a style="text-align: center;color: #999;border: 1px #ccc dashed;display:block;height: 34px
|
||||
;line-height: 34px" href="javascript:addOption();">添加选项</a>
|
||||
</div>
|
||||
</div>
|
||||
<!--</div>-->
|
||||
|
||||
<!--<div class="form-group">-->
|
||||
<!--<label class="col-sm-3 control-label">标签:</label>-->
|
||||
<!--<div class="col-sm-8">-->
|
||||
<!--<input id="label" name="label" class="form-control" type="text">-->
|
||||
<!--</div>-->
|
||||
<!--</div>-->
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">备注信息:</label>
|
||||
<div class="col-sm-8">
|
||||
<input id="remarks" name="remarks" class="form-control" type="text" th:value="${examQuestion.remarks}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
<div th:include="include::footer"></div>
|
||||
<script type="text/javascript">
|
||||
$(function () {
|
||||
|
||||
|
||||
if ($.validator) {
|
||||
$.validator.prototype.elements = function () {
|
||||
var validator = this,
|
||||
rulesCache = {};
|
||||
return $([]).add(this.currentForm.elements)
|
||||
.filter(":input")
|
||||
.not(":submit, :reset, :image, [disabled]")
|
||||
.not(this.settings.ignore)
|
||||
.filter(function () {
|
||||
var elementIdentification = this.id || this.name;
|
||||
!elementIdentification && validator.settings.debug && window.console && console.error("%o has no id nor name assigned", this);
|
||||
if (elementIdentification in rulesCache || !validator.objectLength($(this).rules()))
|
||||
return false;
|
||||
rulesCache[elementIdentification] = true;
|
||||
return true;
|
||||
});
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
var questionItem = $("#item").val();
|
||||
var questionAnswer = $("#answer").val();
|
||||
questionItem =$.parseJSON(questionItem)
|
||||
|
||||
for(var i in questionItem){
|
||||
var number = questionItem[i].number;
|
||||
if(number == "A"){
|
||||
$("#content1").val(questionItem[i].content);
|
||||
continue;
|
||||
}
|
||||
if(number == "B"){
|
||||
$("#content2").val(questionItem[i].content);
|
||||
continue;
|
||||
}
|
||||
$("#addOption").before(' <div class="form-group update1" id="div'+item[index]+'"> <label class="col-sm-3 control-label"></label><div class="col-sm-1" style="padding-right: 0px;"> <input class="form-control update4" name="answer" value="'+item[index]+'" type="radio" style="margin: 0 0 0;">' +
|
||||
'</div><div class="col-sm-1" style="padding-right: 0px;padding-left: 0px"> ' +
|
||||
'<input style="padding: 6px 10px;text-align: center" id="number'+item[index]+'" name="number" class="form-control update2" type="text" value="'+item[index]+'" readonly> ' +
|
||||
'</div> <div class="col-sm-6" style="padding-left: 0px"> <input name="content" id = "con'+item[index]+'" class="form-control" type="text" value="'+questionItem[i].content+'"> </div> <div class="col-sm-1"> <a class="update3" style="text-align: center;color: #999;border: 1px #ccc dashed;display:block;height: 34px;line-height: 34px" href="javascript:deleteOption(\''+item[index++]+'\');">X</a> </div></div>')
|
||||
}
|
||||
|
||||
var radios = document.getElementsByName("answer");
|
||||
|
||||
for ( var i = 0; i < radios.length; i++) {
|
||||
|
||||
if (radios[i].value==questionAnswer) {
|
||||
radios[i].checked=true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
var item = ["C","D","E","F","G","H","I","G","K","L","M","N"];
|
||||
var index = 0;
|
||||
var prefix = ctx + "exam/examQuestion"
|
||||
|
||||
$("#form-examQuestion-add").validate({
|
||||
rules:{
|
||||
title:{
|
||||
required:true,
|
||||
},
|
||||
content:{
|
||||
required:true,
|
||||
},
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
function submitHandler() {
|
||||
debugger
|
||||
if (!$.validate.form()) {
|
||||
return
|
||||
}
|
||||
|
||||
var radios = document.getElementsByName("answer");
|
||||
var i = 0
|
||||
for ( ; i < radios.length; i++) {
|
||||
|
||||
if (radios[i].checked == true) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(i==radios.length){
|
||||
$.modal.alertError("请至少选择一个答案");
|
||||
return;
|
||||
}
|
||||
|
||||
$.operate.save(prefix + "/update", $('#form-examQuestion-add').serialize());
|
||||
}
|
||||
|
||||
|
||||
|
||||
function addOption(){
|
||||
$("#addOption").before(' <div class="form-group update1" id="div'+item[index]+'"> <label class="col-sm-3 control-label"></label><div class="col-sm-1" style="padding-right: 0px;"> <input class="form-control update4" name="answer" value="'+item[index]+'" type="radio" style="margin: 0 0 0;">' +
|
||||
'</div><div class="col-sm-1" style="padding-right: 0px;padding-left: 0px"> ' +
|
||||
'<input style="padding: 6px 10px;text-align: center" id="number'+item[index]+'" name="number" class="form-control update2" type="text" value="'+item[index]+'" readonly> ' +
|
||||
'</div> <div class="col-sm-6" style="padding-left: 0px"> <input name="content" id = "con'+item[index]+'" class="form-control" type="text"> </div> <div class="col-sm-1"> <a class="update3" style="text-align: center;color: #999;border: 1px #ccc dashed;display:block;height: 34px;line-height: 34px" href="javascript:deleteOption(\''+item[index++]+'\');">X</a> </div></div>')
|
||||
}
|
||||
|
||||
function deleteOption(id){
|
||||
debugger
|
||||
$("#div"+id).remove();
|
||||
index--;
|
||||
var index1 = 0;
|
||||
var index2 = 0;
|
||||
var index3 = 0;
|
||||
var index4 = 0
|
||||
$(".update1").each(function(){
|
||||
$(this).attr("id","div"+item[index1++])
|
||||
})
|
||||
$(".update2").each(function(){
|
||||
$(this).attr("value",item[index2++])
|
||||
})
|
||||
$(".update3").each(function(){
|
||||
$(this).attr("href",'javascript:deleteOption(\''+item[index3++]+'\');');
|
||||
})
|
||||
$(".update4").each(function(){
|
||||
$(this).attr("value",'javascript:deleteOption(\''+item[index4++]+'\');');
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -78,9 +78,7 @@
|
|||
shiro:hasPermission="exam:examQuestion:remove">
|
||||
<i class="fa fa-remove"></i> 删除
|
||||
</a>
|
||||
<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="exam:examQuestion:export">
|
||||
<i class="fa fa-download"></i> 导出
|
||||
</a>
|
||||
|
||||
</div>
|
||||
<div class="col-sm-12 select-table table-striped">
|
||||
<table id="bootstrap-table" data-mobile-responsive="true"></table>
|
||||
|
|
@ -93,6 +91,7 @@
|
|||
<script th:inline="javascript">
|
||||
var editFlag = [[${@permission.hasPermi('exam:examQuestion:edit')}]];
|
||||
var removeFlag = [[${@permission.hasPermi('exam:examQuestion:remove')}]];
|
||||
var type = [[${@dict.getType('exam_question_type')}]];
|
||||
var prefix = ctx + "exam/examQuestion";
|
||||
|
||||
$(function () {
|
||||
|
|
@ -115,6 +114,10 @@
|
|||
showExport: true,
|
||||
columns: [{
|
||||
checkbox: true
|
||||
},{
|
||||
field:"id",
|
||||
title: '#',
|
||||
visible: false
|
||||
},
|
||||
{
|
||||
field: 'title',
|
||||
|
|
@ -124,12 +127,12 @@
|
|||
{
|
||||
field: 'type',
|
||||
title: '问题类型',
|
||||
sortable: true
|
||||
},
|
||||
{
|
||||
field: 'label',
|
||||
title: '标签',
|
||||
sortable: true
|
||||
sortable: true,
|
||||
formatter: function(value, item, index) {
|
||||
debugger
|
||||
return $.table.selectDictLabel(type, item.type);
|
||||
}
|
||||
|
||||
},
|
||||
{
|
||||
field: 'createBy',
|
||||
|
|
@ -141,11 +144,6 @@
|
|||
title: '创建时间',
|
||||
sortable: true
|
||||
},
|
||||
{
|
||||
field: 'remarks',
|
||||
title: '答案解析',
|
||||
sortable: true
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
align: 'center',
|
||||
|
|
|
|||
|
|
@ -0,0 +1,192 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
|
||||
<meta charset="utf-8">
|
||||
<head th:include="include :: header"></head>
|
||||
<body class="white-bg">
|
||||
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
|
||||
<form class="form-horizontal m" id="form-examQuestion-add">
|
||||
<div class="form-group">
|
||||
<input type="hidden" id="id" name="id" th:value="${examQuestion.id}">
|
||||
<input type="hidden" id="categoryId" name="categoryId" th:value="${examQuestion.categoryId}">
|
||||
<input type="hidden" id="type" name="type" th:value="${examQuestion.type}">
|
||||
<input type="hidden" id="answer" name="questionAnswer" th:value="${examQuestion.answer}">
|
||||
<input type="hidden" id="item" name="item" th:value="${examQuestionItem}">
|
||||
<label class="col-sm-3 control-label">问题标题:</label>
|
||||
<div class="col-sm-8">
|
||||
<input id="title" name="title" class="form-control" type="text" th:value="${examQuestion.title}">
|
||||
</div>
|
||||
</div>
|
||||
<!--<div class="form-group">-->
|
||||
<!--<label class="col-sm-3 control-label">问题答案:</label>-->
|
||||
<!--<div class="col-sm-8">-->
|
||||
<!--<input id="answer" name="answer" class="form-control" type="text">-->
|
||||
<!--</div>-->
|
||||
<!--</div>-->
|
||||
|
||||
<div class="form-group" >
|
||||
<label class="col-sm-3 control-label">问题选项:</label>
|
||||
<div class="col-sm-1" style="padding-right: 0px;">
|
||||
<input class="form-control" name="answer" value="A" type="radio" style="margin: 0 0 0;">
|
||||
</div>
|
||||
<div class="col-sm-1" style="padding-right: 0px;padding-left: 0px">
|
||||
<input style="padding: 6px 10px;text-align: center" id="number1" name="number" class="form-control" type="text" value="A" readonly>
|
||||
</div>
|
||||
<div class="col-sm-6" style="padding-left: 0px">
|
||||
<input id="content1" name="content" class="form-control" type="text" value="正确" readonly>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group" >
|
||||
<label class="col-sm-3 control-label"></label>
|
||||
<div class="col-sm-1" style="padding-right: 0px;">
|
||||
<input class="form-control" name="answer" value="B" type="radio" style="margin: 0 0 0;" >
|
||||
</div>
|
||||
<div class="col-sm-1" style="padding-right: 0px;padding-left: 0px">
|
||||
<input style="padding: 6px 10px;text-align: center" id="number2" name="number" class="form-control" type="text" value="B" readonly>
|
||||
</div>
|
||||
<div class="col-sm-6" style="padding-left: 0px">
|
||||
<input id="content2" name="content" class="form-control" type="text" value="错误" readonly>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!--</div>-->
|
||||
|
||||
<!--<div class="form-group">-->
|
||||
<!--<label class="col-sm-3 control-label">标签:</label>-->
|
||||
<!--<div class="col-sm-8">-->
|
||||
<!--<input id="label" name="label" class="form-control" type="text">-->
|
||||
<!--</div>-->
|
||||
<!--</div>-->
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">备注信息:</label>
|
||||
<div class="col-sm-8">
|
||||
<input id="remarks" name="remarks" class="form-control" type="text" th:value="${examQuestion.remarks}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
<div th:include="include::footer"></div>
|
||||
<script type="text/javascript">
|
||||
$(function () {
|
||||
if ($.validator) {
|
||||
$.validator.prototype.elements = function () {
|
||||
var validator = this,
|
||||
rulesCache = {};
|
||||
return $([]).add(this.currentForm.elements)
|
||||
.filter(":input")
|
||||
.not(":submit, :reset, :image, [disabled]")
|
||||
.not(this.settings.ignore)
|
||||
.filter(function () {
|
||||
var elementIdentification = this.id || this.name;
|
||||
!elementIdentification && validator.settings.debug && window.console && console.error("%o has no id nor name assigned", this);
|
||||
if (elementIdentification in rulesCache || !validator.objectLength($(this).rules()))
|
||||
return false;
|
||||
rulesCache[elementIdentification] = true;
|
||||
return true;
|
||||
});
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
var questionItem = $("#item").val();
|
||||
var questionAnswer = $("#answer").val();
|
||||
questionItem =$.parseJSON(questionItem)
|
||||
|
||||
for(var i in questionItem){
|
||||
var number = questionItem[i].number;
|
||||
if(number == "A"){
|
||||
$("#content1").val(questionItem[i].content);
|
||||
continue;
|
||||
}
|
||||
if(number == "B"){
|
||||
$("#content2").val(questionItem[i].content);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
var radios = document.getElementsByName("answer");
|
||||
|
||||
for ( var i = 0; i < radios.length; i++) {
|
||||
|
||||
if (radios[i].value==questionAnswer) {
|
||||
radios[i].checked=true
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
var item = ["C","D","E","F","G","H","I","G","K","L","M","N"];
|
||||
var index = 0;
|
||||
var prefix = ctx + "exam/examQuestion"
|
||||
$("#form-examQuestion-add").validate({
|
||||
rules:{
|
||||
title:{
|
||||
required:true,
|
||||
},
|
||||
content:{
|
||||
required:true,
|
||||
},
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
function submitHandler() {
|
||||
debugger
|
||||
if (!$.validate.form()) {
|
||||
return
|
||||
}
|
||||
|
||||
var radios = document.getElementsByName("answer");
|
||||
var i = 0
|
||||
for ( ; i < radios.length; i++) {
|
||||
|
||||
if (radios[i].checked == true) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(i==radios.length){
|
||||
$.modal.alertError("请至少选择一个答案");
|
||||
return;
|
||||
}
|
||||
|
||||
$.operate.save(prefix + "/update", $('#form-examQuestion-add').serialize());
|
||||
}
|
||||
|
||||
|
||||
|
||||
function addOption(){
|
||||
$("#addOption").before(' <div class="form-group update1" id="div'+item[index]+'"> <label class="col-sm-3 control-label"></label><div class="col-sm-1" style="padding-right: 0px;"> <input class="form-control update4" name="answer" value="'+item[index]+'" type="checkbox" style="margin: 0 0 0;">' +
|
||||
'</div><div class="col-sm-1" style="padding-right: 0px;padding-left: 0px"> ' +
|
||||
'<input style="padding: 6px 10px;text-align: center" id="number'+item[index]+'" name="number" class="form-control update2" type="text" value="'+item[index]+'" readonly> ' +
|
||||
'</div> <div class="col-sm-6" style="padding-left: 0px"> <input name="content" class="form-control" type="text"> </div> <div class="col-sm-1"> <a class="update3" style="text-align: center;color: #999;border: 1px #ccc dashed;display:block;height: 34px;line-height: 34px" href="javascript:deleteOption(\''+item[index++]+'\');">X</a> </div></div>')
|
||||
}
|
||||
|
||||
function deleteOption(id){
|
||||
debugger
|
||||
$("#div"+id).remove();
|
||||
index--;
|
||||
var index1 = 0;
|
||||
var index2 = 0;
|
||||
var index3 = 0;
|
||||
var index4 = 0
|
||||
$(".update1").each(function(){
|
||||
$(this).attr("id","div"+item[index1++])
|
||||
})
|
||||
$(".update2").each(function(){
|
||||
$(this).attr("value",item[index2++])
|
||||
})
|
||||
$(".update3").each(function(){
|
||||
$(this).attr("href",'javascript:deleteOption(\''+item[index3++]+'\');');
|
||||
})
|
||||
$(".update4").each(function(){
|
||||
$(this).attr("value",'javascript:deleteOption(\''+item[index4++]+'\');');
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,206 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
|
||||
<meta charset="utf-8">
|
||||
<head th:include="include :: header"></head>
|
||||
<body class="white-bg">
|
||||
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
|
||||
<form class="form-horizontal m" id="form-examQuestion-add">
|
||||
<div class="form-group">
|
||||
<input type="hidden" id="id" name="id" th:value="${examQuestion.id}">
|
||||
<input type="hidden" id="categoryId" name="categoryId" th:value="${examQuestion.categoryId}">
|
||||
<input type="hidden" id="type" name="type" th:value="${examQuestion.type}">
|
||||
<input type="hidden" id="answer" name="questionAnswer" th:value="${examQuestion.answer}">
|
||||
<input type="hidden" id="item" name="item" th:value="${examQuestionItem}">
|
||||
<label class="col-sm-3 control-label">问题标题:</label>
|
||||
<div class="col-sm-8">
|
||||
<input id="title" name="title" class="form-control" type="text" th:value="${examQuestion.title}">
|
||||
</div>
|
||||
</div>
|
||||
<!--<div class="form-group">-->
|
||||
<!--<label class="col-sm-3 control-label">问题答案:</label>-->
|
||||
<!--<div class="col-sm-8">-->
|
||||
<!--<input id="answer" name="answer" class="form-control" type="text">-->
|
||||
<!--</div>-->
|
||||
<!--</div>-->
|
||||
|
||||
<div class="form-group" >
|
||||
<label class="col-sm-3 control-label">问题选项:</label>
|
||||
<div class="col-sm-1" style="padding-right: 0px;">
|
||||
<input class="form-control" name="answer" value="A" type="checkbox" style="margin: 0 0 0;">
|
||||
</div>
|
||||
<div class="col-sm-1" style="padding-right: 0px;padding-left: 0px">
|
||||
<input style="padding: 6px 10px;text-align: center" id="number1" name="number" class="form-control" type="text" value="A" readonly>
|
||||
</div>
|
||||
<div class="col-sm-6" style="padding-left: 0px">
|
||||
<input id="content1" name="content" class="form-control" type="text">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group" >
|
||||
<label class="col-sm-3 control-label"></label>
|
||||
<div class="col-sm-1" style="padding-right: 0px;">
|
||||
<input class="form-control" name="answer" value="B" type="checkbox" style="margin: 0 0 0;">
|
||||
</div>
|
||||
<div class="col-sm-1" style="padding-right: 0px;padding-left: 0px">
|
||||
<input style="padding: 6px 10px;text-align: center" id="number2" name="number" class="form-control" type="text" value="B" readonly>
|
||||
</div>
|
||||
<div class="col-sm-6" style="padding-left: 0px">
|
||||
<input id="content2" name="content" class="form-control" type="text">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group" id="addOption">
|
||||
<label class="col-sm-4 control-label"></label>
|
||||
<div class="col-sm-7" style="padding-left: 0px">
|
||||
<a style="text-align: center;color: #999;border: 1px #ccc dashed;display:block;height: 34px
|
||||
;line-height: 34px" href="javascript:addOption();">添加选项</a>
|
||||
</div>
|
||||
</div>
|
||||
<!--</div>-->
|
||||
|
||||
<!--<div class="form-group">-->
|
||||
<!--<label class="col-sm-3 control-label">标签:</label>-->
|
||||
<!--<div class="col-sm-8">-->
|
||||
<!--<input id="label" name="label" class="form-control" type="text">-->
|
||||
<!--</div>-->
|
||||
<!--</div>-->
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">备注信息:</label>
|
||||
<div class="col-sm-8">
|
||||
<input id="remarks" name="remarks" class="form-control" type="text" th:value="${examQuestion.remarks}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
<div th:include="include::footer"></div>
|
||||
<script type="text/javascript">
|
||||
$(function () {
|
||||
if ($.validator) {
|
||||
$.validator.prototype.elements = function () {
|
||||
var validator = this,
|
||||
rulesCache = {};
|
||||
return $([]).add(this.currentForm.elements)
|
||||
.filter(":input")
|
||||
.not(":submit, :reset, :image, [disabled]")
|
||||
.not(this.settings.ignore)
|
||||
.filter(function () {
|
||||
debugger
|
||||
var elementIdentification = this.id || this.name;
|
||||
!elementIdentification && validator.settings.debug && window.console && console.error("%o has no id nor name assigned", this);
|
||||
if (elementIdentification in rulesCache || !validator.objectLength($(this).rules()))
|
||||
return false;
|
||||
rulesCache[elementIdentification] = true;
|
||||
return true;
|
||||
});
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
var questionItem = $("#item").val();
|
||||
var questionAnswer = $("#answer").val();
|
||||
questionItem =$.parseJSON(questionItem)
|
||||
|
||||
for(var i in questionItem){
|
||||
var number = questionItem[i].number;
|
||||
if(number == "A"){
|
||||
$("#content1").val(questionItem[i].content);
|
||||
continue;
|
||||
}
|
||||
if(number == "B"){
|
||||
$("#content2").val(questionItem[i].content);
|
||||
continue;
|
||||
}
|
||||
|
||||
$("#addOption").before(' <div class="form-group update1" id="div'+item[index]+'"> <label class="col-sm-3 control-label"></label><div class="col-sm-1" style="padding-right: 0px;"> <input class="form-control update4" name="answer" value="'+item[index]+'" type="checkbox" style="margin: 0 0 0;">' +
|
||||
'</div><div class="col-sm-1" style="padding-right: 0px;padding-left: 0px"> ' +
|
||||
'<input style="padding: 6px 10px;text-align: center" id="number'+item[index]+'" name="number" class="form-control update2" type="text" value="'+item[index]+'" readonly> ' +
|
||||
'</div> <div class="col-sm-6" style="padding-left: 0px"> <input name="content" id = "con'+item[index]+'" class="form-control" type="text" value="'+questionItem[i].content+'"> </div> <div class="col-sm-1"> <a class="update3" style="text-align: center;color: #999;border: 1px #ccc dashed;display:block;height: 34px;line-height: 34px" href="javascript:deleteOption(\''+item[index++]+'\');">X</a> </div></div>')
|
||||
}
|
||||
|
||||
var radios = document.getElementsByName("answer");
|
||||
debugger
|
||||
for ( var i = 0; i < radios.length; i++) {
|
||||
|
||||
if (questionAnswer.indexOf(radios[i].value)!=-1) {
|
||||
radios[i].checked=true
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
var item = ["C","D","E","F","G","H","I","G","K","L","M","N"];
|
||||
var index = 0;
|
||||
var prefix = ctx + "exam/examQuestion"
|
||||
$("#form-examQuestion-add").validate({
|
||||
rules:{
|
||||
title:{
|
||||
required:true,
|
||||
},
|
||||
content:{
|
||||
required:true,
|
||||
},
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
function submitHandler() {
|
||||
debugger
|
||||
if (!$.validate.form()) {
|
||||
return
|
||||
}
|
||||
|
||||
var radios = document.getElementsByName("answer");
|
||||
var i = 0
|
||||
for ( ; i < radios.length; i++) {
|
||||
|
||||
if (radios[i].checked == true) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(i==radios.length){
|
||||
$.modal.alertError("请至少选择一个答案");
|
||||
return;
|
||||
}
|
||||
|
||||
$.operate.save(prefix + "/update", $('#form-examQuestion-add').serialize());
|
||||
}
|
||||
|
||||
|
||||
|
||||
function addOption(){
|
||||
$("#addOption").before(' <div class="form-group update1" id="div'+item[index]+'"> <label class="col-sm-3 control-label"></label><div class="col-sm-1" style="padding-right: 0px;"> <input class="form-control update4" name="answer" value="'+item[index]+'" type="checkbox" style="margin: 0 0 0;">' +
|
||||
'</div><div class="col-sm-1" style="padding-right: 0px;padding-left: 0px"> ' +
|
||||
'<input style="padding: 6px 10px;text-align: center" id="number'+item[index]+'" name="number" class="form-control update2" type="text" value="'+item[index]+'" readonly> ' +
|
||||
'</div> <div class="col-sm-6" style="padding-left: 0px"> <input name="content" id = "con'+item[index]+'" class="form-control" type="text"> </div> <div class="col-sm-1"> <a class="update3" style="text-align: center;color: #999;border: 1px #ccc dashed;display:block;height: 34px;line-height: 34px" href="javascript:deleteOption(\''+item[index++]+'\');">X</a> </div></div>')
|
||||
}
|
||||
|
||||
function deleteOption(id){
|
||||
debugger
|
||||
$("#div"+id).remove();
|
||||
index--;
|
||||
var index1 = 0;
|
||||
var index2 = 0;
|
||||
var index3 = 0;
|
||||
var index4 = 0
|
||||
$(".update1").each(function(){
|
||||
$(this).attr("id","div"+item[index1++])
|
||||
})
|
||||
$(".update2").each(function(){
|
||||
$(this).attr("value",item[index2++])
|
||||
})
|
||||
$(".update3").each(function(){
|
||||
$(this).attr("href",'javascript:deleteOption(\''+item[index3++]+'\');');
|
||||
})
|
||||
$(".update4").each(function(){
|
||||
$(this).attr("value",'javascript:deleteOption(\''+item[index4++]+'\');');
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Reference in New Issue