<!DOCTYPE html>
|
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
|
<head>
|
<th:block th:include="include :: header('请选择题目')"/>
|
<style>
|
.changeColor {
|
background-color: #337dff !important;
|
color: #fffefa !important;
|
}
|
</style>
|
</head>
|
<body class="gray-bg">
|
<div class="container-div">
|
<div class="row">
|
<div class="col-sm-12 search-collapse">
|
<form id="formId">
|
<input type="hidden" id="questionTemplateId" name="questionTemplateId"
|
th:value="${param.questionTemplateId}"/>
|
<div class="select-list">
|
<ul>
|
<li>
|
<p>题干:</p>
|
<input type="text" name="infoTextContentId"/>
|
</li>
|
<li>
|
<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
|
class="fa fa-search"></i> [[#{basis.search}]]</a>
|
<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
|
class="fa fa-refresh"></i> [[#{basis.reset}]]</a>
|
</li>
|
</ul>
|
</div>
|
</form>
|
</div>
|
<div class="col-sm-12 select-table table-striped">
|
<table id="bootstrap-table" data-mobile-responsive="true"></table>
|
<div class="col-sm-offset-5 col-sm-10">
|
<button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i
|
class="fa fa-check"></i>save
|
</button>
|
<button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i
|
class="fa fa-reply-all"></i>close
|
</button>
|
</div>
|
</div>
|
</div>
|
</div>
|
<th:block th:include="include :: footer"/>
|
<script th:inline="javascript">
|
var editFlag = [[${@permission.hasPermi('exam:question:edit')}]];
|
var removeFlag = [[${@permission.hasPermi('exam:question:remove')}]];
|
var prefix = ctx + "exam/question";
|
var $parent = $.operate.parentHtml();
|
$(function () {
|
var levelId = [[${levelId}]];
|
var langType = [[${langType}]];
|
var template = [[${template}]];
|
|
var options = {
|
url: prefix + "/listForProductAddQuestion",
|
queryParams: function () {
|
var temp = {
|
levelId: levelId,
|
langType: langType,
|
template: template
|
};
|
|
return temp;
|
},
|
modalName: [[#{menu.exam.question.view}]],
|
columns: [{
|
checkbox: true,
|
//formatter:stateFormatter
|
},
|
{
|
field: 'id',
|
title: [[#{jsp.exam.product.titleCode}]],
|
visible: false
|
},
|
{
|
field: 'permanentId',
|
title: [[#{jsp.exam.question.questionNumberPermanent}]]
|
},
|
{
|
field: 'title',
|
title: [[#{jsp.exam.product.questionStem}]]
|
},
|
{
|
field: 'levelName',
|
title: [[#{menu.exam.level.view}]]
|
},
|
],
|
onLoadSuccess: function (data) {
|
// var $thisContent = $parent.$('[add-question-edit = "true"]').parents('.segmentation');
|
var $thisContent = $parent.$('[add-question-now-part="true"]');
|
$thisContent.removeAttrs('add-question-now-part');
|
var $checkedValues = $thisContent.find('[name="questionId"]');
|
// job选择维度
|
if ($('#questionTemplateId').val() != "" && $('#questionTemplateId').val() != undefined) {
|
var $ibox = $parent.$('#headline').find('.ibox').eq(0);
|
$checkedValues = $ibox.find('[name="questionId"]');
|
}
|
//打开的时候选中
|
$.btTable.bootstrapTable('uncheckAll');
|
var template = [[${template}]];
|
|
// 如果是大题目,不选择
|
if (isTitle(template)) {
|
return;
|
}
|
var checkby = {};
|
checkby['field'] = 'id';
|
checkby['values'] = [];
|
$($checkedValues).each(function (i) {
|
checkby['values'].push(parseInt($(this).val()));
|
});
|
$.btTable.bootstrapTable('checkBy', checkby);
|
}
|
};
|
$.table.init(options);
|
});
|
|
function stateFormatter(value, row, index) {
|
// var $thisContent = $parent.$('[add-question-edit="true"]').parents('#headline');
|
var $thisContent = $parent.$('[add-question-edit="true"]').parents('.segmentation');
|
var $checkedValues = $thisContent.find('[name="questionId"]');
|
var flag = true;
|
row['checked'] = false;
|
$($checkedValues).each(function (i) {
|
if (row.id == parseInt($(this).val())) {
|
row.checked = true;
|
flag = false;
|
}
|
});
|
|
if (!flag) {
|
return {
|
disabled: true,//设置是否可用
|
checked: true//设置选中
|
};
|
}
|
return value;
|
}
|
|
function jobSubmit($tableSelect, $editConten) {
|
$editConten.empty();
|
$.each($tableSelect, function (index, obj) {
|
if (!obj.checked) {// if do not checked
|
var $questionContent = $parent.$('#questionSelect').clone();
|
$questionContent.removeAttrs('id');
|
$questionContent.removeAttrs('hidden');
|
$questionContent.children('div').eq(0).html(1 + ")");
|
$questionContent.children('p').eq(0).html(obj.permanentId);
|
$questionContent.children('p').eq(1).html(obj.title);
|
$questionContent.children('[name="contentId"]').eq(0).val(obj.infoTextContentId);
|
$questionContent.children('[name="questionId"]').eq(0).val(obj.id);
|
|
$.each(obj.choiceInput, function (index, select) {
|
str = "<li><li>" + select + "</li><li>" + obj.selectInput[index] + "</li></li>";
|
$questionContent.children('ul').eq(0).append(str);
|
});
|
$editConten.append($questionContent);
|
}
|
});
|
|
$editConten.find('[name="question-seq"]').each(function (i) {
|
var $permanentId = $(this).parents('.segmentation').find('[name = "permanentId"]');
|
if ($permanentId.val().trim() != "" && $permanentId != undefined) {
|
$(this).html($permanentId.val() + "-" + String.fromCharCode(i + 97));
|
} else {
|
$(this).html((i + 1) + '.');
|
}
|
});
|
}
|
|
function selectItem(obj, $questionContent) {
|
$.each(obj.choiceInput, function (index, select) {
|
str = "<li><li>" + select + "</li><li>" + obj.selectInput[index] + "</li></li>";
|
$questionContent.children('ul').eq(0).append(str);
|
});
|
}
|
|
function setParentQuestionId($questionContent) {
|
var $iboxContent = $questionContent.prev();
|
while ($iboxContent.hasClass('ibox-content') && !isTitle($questionContent.find('[name="template"]').eq(0).val())) {
|
if ($iboxContent.attr("add-intelligence-title") == "true" || $iboxContent.find('[name="template"]').eq(0).val() == "intelligence_title") {
|
$questionContent.children('[name="parentQuestionId"]').eq(0).val($iboxContent.children('[name="questionId"]').val());
|
$iboxContent = $iboxContent.prev();
|
break;
|
}
|
$iboxContent = $iboxContent.prev();
|
}
|
}
|
|
function setQuestionTitle($questionContent, obj) {
|
$questionContent.removeAttrs('id');
|
$questionContent.removeAttrs('hidden');
|
$questionContent.children('div').eq(0).html(1 + ")");
|
$questionContent.children('p').eq(0).html(obj.permanentId);
|
$questionContent.children('p').eq(1).html(obj.title);
|
$questionContent.children('[name="contentId"]').eq(0).val(obj.infoTextContentId);
|
$questionContent.children('[name="questionId"]').eq(0).val(obj.id);
|
$questionContent.children('[name="template"]').eq(0).val(obj.template);
|
}
|
|
function isVerify(template, $tableSelect) {
|
return template == "intelligence_title" && $tableSelect.length > 1;
|
}
|
|
function isTitle(template) {
|
return template == "intelligence_title";
|
}
|
|
function isIntelligenceQuestion(template) {
|
return template == "intelligence";
|
}
|
|
function setNumber($editConten) {
|
var smallQuestionNum = 1;
|
var orderNum = 1;
|
$editConten.find('[name="question-seq"]').each(function (i) {
|
var $permanentId = $(this).parents('.segmentation').find('[name = "permanentId"]');
|
if ($permanentId.val().trim() != "" && $permanentId != undefined) {
|
$(this).html($permanentId.val() + "-" + String.fromCharCode(i + 97));
|
} else {
|
var parentQuestionId = $(this).parent().find('[name="parentQuestionId"]').eq(0).val();
|
// 智力题没有不分片的,所以其他地方不需要这样
|
if (parentQuestionId == null || parentQuestionId == undefined || parentQuestionId.trim() == "") {
|
$(this).html((orderNum++) + '.');
|
smallQuestionNum = 1;
|
} else {
|
$(this).html("(" + (smallQuestionNum++) + ")");
|
}
|
}
|
});
|
}
|
|
function delteQuetion($editConten, $addPartEdit) {
|
// 如果是设置题目不分段
|
if ($parent.$('[add-part-edit="true"]').length == 0) {
|
$parent.$('.add-part').css("display", "none");
|
}
|
$addPartEdit.removeAttr('add-part-edit');
|
if ($addPartEdit.length != 0) {
|
$deleteNode = undefined;
|
$addPartEdit = $addPartEdit.next();
|
while (true) {
|
console.log($addPartEdit.html());
|
if ($addPartEdit.hasClass('part-value') || $addPartEdit.attr("add-question-button-edit") != undefined) {
|
break;
|
} else {
|
$deleteNode = $addPartEdit;
|
$addPartEdit = $addPartEdit.next();
|
$deleteNode.remove();
|
}
|
}
|
} else {
|
$editConten.empty();
|
}
|
}
|
|
function setTitleAttr($questionContent) {
|
if ($questionContent.children('[name="template"]').val() == "intelligence_title") {
|
$questionContent.attr("add-intelligence-title", "true");
|
$questionContent.append('<p style="text-align:right;" class="add-part add-question-click"><a href="#" onclick="deleteTitleAndTheQuestion(this)" style="color:red">删除</a></p>');
|
}
|
}
|
|
function deleteTitleOrTitleQuestion() {
|
// 删除问答题或者删除问答题下面的题目,属性在add-question-now-title在add-intelligence添加
|
$parent.$('[delete-question="true"]').remove();
|
$parent.$('[add-question-now-title="true"]').remove();
|
}
|
|
// add-question
|
function submitHandler() {
|
var $tableSelect = $.btTable.bootstrapTable('getSelections');
|
var template = [[${template}]];
|
if (isVerify(template, $tableSelect)) {
|
$.modal.alertWarning([[#{jsp.exam.product.selectIntelliAlert}]]);
|
return;
|
}
|
|
// job选择维度
|
if ($('#questionTemplateId').val() != "" && $('#questionTemplateId').val() != undefined) {
|
$editConten = $parent.$('#headline').find('.ibox');
|
if ($('#questionTemplateId').val() != "job_batch") {
|
$editConten.each(function (i) {
|
jobSubmit($tableSelect, $(this));
|
});
|
$.modal.closeTab();
|
return;
|
}
|
}
|
|
var $editConten = $parent.$('[add-question-edit="true"]');
|
$editConten.removeAttrs('add-question-edit');
|
$addPartEdit = $parent.$('[add-part-edit="true"]');
|
|
// 删除每一个分片的题目
|
if (isTitle(template) || isIntelligenceQuestion(template)) {
|
deleteTitleOrTitleQuestion();
|
} else {
|
delteQuetion($editConten, $addPartEdit);
|
}
|
|
|
// 题目设置的那个按钮
|
$addQButtonEdit = $parent.$('[add-question-button-edit="true"]');
|
$addQButtonEdit.removeAttr('add-question-button-edit');
|
|
$.each($tableSelect, function (index, obj) {
|
if (!obj.checked) {// if do not checked
|
|
// 判断是否已经选过了
|
var flag = true;
|
if ($('#questionTemplateId').val() != "job_batch") {
|
$parent.$('#headline').find('[name="questionId"]').each(function () {
|
if ($(this).val() == obj.id) {
|
flag = false;
|
}
|
});
|
}
|
flag = true; // 可以重复添加
|
// 盒子里面有了就不用添加了
|
if (flag) {
|
var $questionContent = $parent.$('#questionSelect').clone();// 问题的展示
|
|
// 题目题干
|
setQuestionTitle($questionContent, obj);
|
setTitleAttr($questionContent);// add-intelligence-title
|
|
// 智力题的题目不需要选贤
|
if (!isTitle(template)) {
|
// 选项1,2,3,4
|
selectItem(obj, $questionContent);
|
} else {
|
// 删除子选项
|
$questionContent.remove('ul');
|
}
|
|
if ($addPartEdit.length != 0) {
|
$addQButtonEdit.before($questionContent);
|
setParentQuestionId($questionContent);
|
} else {
|
$editConten.append($questionContent);
|
}
|
}
|
|
}
|
});
|
|
// 给题目编号
|
setNumber($editConten);
|
|
$.modal.closeTab();
|
}
|
</script>
|
</body>
|
</html>
|