123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385 |
- questionBankAddEdit = function() {
- /**定义变量**/
- var _this = this;
- /**私有方法**/
- /***新增信息***/
- _this.save = function(addType){
- /*var pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?]");
- if(pattern.test($("#QUESTION_NAME_603").val())){
- top.Dialog.alert("题目名称不能包含特殊字符");
- return;
- }*/
- var option_num = $("#opt_input").val();
- var question_type = $("#QUESTION_TYPE_603").val();
- if(question_type=="4"){
- $("#QUESTION_ANSWER_603").val(getAnswerValue(option_num,"OPTIONS_"));
- $("#ANSWER_OPTION_603").val(getAnswerValue(option_num,"opt_type_"));
- }else{
- $("#QUESTION_ANSWER_603").val(getRadioOrCheckboxValue("OPTIONS"));
- }
-
- $("#APPLICABLE_OBJECT_603").val(getRadioOrCheckboxValue("applicable_type"));
- $("#ANSWER_TYPE_603").val(getRadioOrCheckboxValue("opt_type"));
- $("#603Class").val("603");
-
- $form = $('#editForm');
- var valid = $form.validationEngine({returnIsValid: true});
- if(!valid){
- top.Dialog.alert(CHECKREDBOX);
- return;
- }
- if(!validateCheck("applicable_type")){
- top.Dialog.alert("请选择适用对象!");
- return;
- }
- if($("#ANSWER_TYPE_603").val()=="2"){
- if(!validateFile()){
- top.Dialog.alert("请选择上传文件!");
- return;
- }
- }
- if(question_type=="4"){
- for(var i=1;i<=option_num;i++){
- if(!validateCheck("OPTIONS_"+i)){
- top.Dialog.alert("请选择第"+i+"个选项答案!");
- return;
- }
- /*if(checkScoreOption("score_option_"+i)){
- top.Dialog.alert("请填写第"+i+"个单项分值!");
- return;
- }*/
- }
- /*if(!checkTotalOption(option_num)){
- top.Dialog.alert("总分值与单项分值不一致");
- return;
- }*/
- }else{
- if(!validateCheck("OPTIONS")){
- top.Dialog.alert("请选择选项答案!");
- return;
- }
- }
-
- $("#QUESTION_SCORE_603").val(getScore(option_num));
- $form = $('#editForm');
- if(valid){
- showProgressBar("正在提交中...");
- var url = $.pathname() + '/ws/crud/CRUDService/create/';
- if(fd_id!=undefined&&fd_id!=""){
- url = $.pathname() + "/ws/crud/CRUDService/update/";
- }
- var formValue = $form.serialize();
- //alert("formValue==="+JSON.stringify(formValue));
- $.request.add(url,formValue,function(data){//保存题目主表数据
- //alert("data=="+JSON.stringify(data));
- saveSubTableData(data.Msg.objectID,addType);
- });
- }
-
- };
- _this.saveAndAgain = function(){
- _this.save("again");
- };
-
- _this.formReset = function(){
- $('#frmright',window.parent.document).attr('src',$.pathname()+"/page/business/exercise/examineManagement/questionBankAddEdit.jsp?fd_id="+fd_id);
- };
- return {
- init : function() {
- $('#save').bind('click',function(){
- _this.save();
- });
- $("#saveAndAgain").bind("click",function(){
- _this.saveAndAgain();
- });
- $('#goback').bind('click',function(){
- $('#frmright',window.parent.document).attr('src',$.pathname()+"/page/business/exercise/examineManagement/questionBank.jsp");
-
- });
- $('#giveUp').bind('click',function(){
- $('#frmright',window.parent.document).attr('src',$.pathname()+"/page/business/exercise/examineManagement/questionBank.jsp");
-
- });
-
- }
- };
- }();
- $(function() {
- questionBankAddEdit.init();
- });
- function saveSubTableData(questionId,addType){
- //alert("questionId=="+questionId)
- var question_type = $("#QUESTION_TYPE_603").val();
- // if(question_type=="3"){//判断题,判断题不需要在副表保存题目
- // var options = $("input[name=OPTIONS]").val();
- // alert(options);
- // $("#OPTION_604").val(options);
- // $("#QUESTION_ID_604").val(questionId);
- // var option_content = "";
- // if($("input[name=OPTIONS][checked=checked]").index("input[name=OPTIONS]")==1){
- // option_content = "正确";
- // }else{
- // option_content = "错误";
- // }
- // $("#OPTION_CONTENT_604").val(option_content);
- // }else
- if(question_type=="4"){//情景选择题
- var option_num = $("#opt_input").val();
- var fd_ids_604 = $("#FD_OBJECTID604").val();
- fd_ids_604 = fd_ids_604.split(",");
- var arr = $("#FD_OBJECTID604").val().split(",");
- var sum = 0;
- for(var j =1;j<=option_num;j++){
- var $optionDom = $("input[name=OPTIONS_"+j+"]");
- for (var i = 0; i < $optionDom.length; i++) {//循环保存
- $("#OPTION_604").val($optionDom.eq(i).val());//存序号
- $("#604Class").val("604");
- $("#QUESTION_ID_604").val(questionId);
- var option_content = $optionDom.eq(i).parent().find(".answer_content").val();
- $("#OPTION_CONTENT_604").val(option_content);
- $("#OPTION_INDEX_604").val(j);
- var url = $.pathname() + '/ws/crud/CRUDService/create/';
- if(!(fd_id=="null"||fd_id=="")){
- var answer_id = $optionDom.eq(i).parent().find(".answer_id").val();//获取答案id
- $("#FD_OBJECTID604").val(answer_id);
- arr = removeArr(arr,answer_id);//将多余的答案移除
- if(answer_id!=""){
- url = $.pathname() +"/ws/crud/CRUDService/update/";
- }
- }
- /*var url = $.pathname() + '/ws/crud/CRUDService/create/';
- if(fd_ids_604[sum]!=undefined&&fd_ids_604[sum]!=""){
- url = $.pathname() +"/ws/crud/CRUDService/update/";
- }*/
- var formValue = $("#editFormSub").serialize();
- //alert("formValue_sub===="+JSON.stringify(formValue));
-
- /*$.request.add(url,formValue,function(data){
- closeProgress();
- });*/
- $.ajax({//保存题目主表数据
- url : url,
- data : formValue,
- type : 'post',
- timeout : 15000,
- dataType : 'json',
- async : false,
- success : function(data) {
- }
- });
- if(i==$optionDom.length-1 && j == option_num){
- closeProgress();
- top.Dialog.alert("保存成功!");
- if(addType=="again"){
- $('#frmright',window.parent.document).attr('src',$.pathname()+"/page/business/exercise/examineManagement/questionBankAddEdit.jsp?versionId="+versionId+"&fd_id=");
- }else{
- $('#frmright',window.parent.document).attr('src',$.pathname()+"/page/business/exercise/examineManagement/questionBank.jsp");
- }
- }
- sum++;
- }
- }
-
- //删除移除的答案
- if(!(fd_id=="null"||fd_id=="")){
- for(var i=0;i<arr.length;i++){
- var url = $.pathname() + '/ws/crud/CRUDService/delete/';
- var params = {
- objectIDs : arr[i],
- classid : 604
- };
- $.ajax({
- url : url,
- data : params,
- type : 'post',
- timeout : 15000,
- dataType : 'json',
- async : false,
- success : function(data) {
- }
- });
- }
- }
-
- }else{//选择题(单选or多选)
- var answer_type = $("#ANSWER_TYPE_603").val();
- var $optionDom = $("input[name=OPTIONS]");
- var fd_ids_604 = $("#FD_OBJECTID604").val();
- fd_ids_604 = fd_ids_604.split(",");
- var arr = fd_ids_604;
- for (var i = 0; i < $optionDom.length; i++) {//循环保存
- $("#OPTION_604").val($optionDom.eq(i).val());//存序号
- $("#604Class").val("604");
- $("#FD_OBJECTID604").val(fd_ids_604[i]);
- $("#QUESTION_ID_604").val(questionId);
-
- if(question_type=="3"){//判断题
- var content = $optionDom.eq(i).next().next().text();
- $("#OPTION_CONTENT_604").val(content);
- }else{
- var option_content = "";
- if(answer_type == 1){
- option_content = $optionDom.eq(i).parent().find(".answer_content").val();
- }else{
- option_content = $optionDom.eq(i).parent().find("#file_name").val();
- }
- $("#OPTION_CONTENT_604").val(option_content);
- }
- var url = $.pathname() + '/ws/crud/CRUDService/create/';
- if(fd_ids_604[i]!=undefined&&fd_ids_604[i]!=""){
- url = $.pathname() +"/ws/crud/CRUDService/update/";
- arr = removeArr(arr,fd_ids_604[i]);//将多余的答案移除
- //fd_ids_604.splice(i,1);
- }
- var formValue = $("#editFormSub").serialize();
- //alert("formValue_sub===="+JSON.stringify(formValue));
- /*$.request.add(url,formValue,function(data){//保存题目主表数据
- closeProgress();
- });*/
- $.ajax({//保存题目主表数据
- url : url,
- data : formValue,
- type : 'post',
- timeout : 15000,
- dataType : 'json',
- async : false,
- success : function(data) {
- }
- });
- if(i==$optionDom.length-1){
- top.Dialog.alert("保存成功!");
- if(addType=="again"){
- $('#frmright',window.parent.document).attr('src',$.pathname()+"/page/business/exercise/examineManagement/questionBankAddEdit.jsp?versionId="+versionId+"&fd_id=");
- }else{
- $('#frmright',window.parent.document).attr('src',$.pathname()+"/page/business/exercise/examineManagement/questionBank.jsp");
- }
- }
- }
- //删除移除的答案
- if(fd_id!=""){
- for(var i=0;i<arr.length;i++){
- var url = $.pathname() + '/ws/crud/CRUDService/delete/';
- var params = {
- objectIDs : arr[i],
- classid : 604
- };
- $.ajax({
- url : url,
- data : params,
- type : 'post',
- timeout : 15000,
- dataType : 'json',
- async : false,
- success : function(data) {
- }
- });
- }
- }
- }
- }
- //求单选or多选按钮的值,传radio 或 checkbox的名字作为参数
- function getRadioOrCheckboxValue(name){
- var checkValues = "";
- var $dom = $("input[name="+name+"]");
- for (var i = 0; i < $dom.length; i++) {
- //alert($dom.eq(i).attr("checked"));
- if($dom.eq(i).attr("checked")=="checked"){
- checkValues += $dom.eq(i).val()+",";
- }
- }
- checkValues = checkValues.substring(0, checkValues.length-1);
- //alert(checkValues);
- return checkValues;
- }
- //检查是否选中
- function validateCheck(name){
- var flag = false;
- var $dom = $("input[name="+name+"]");
- for (var i = 0; i < $dom.length; i++) {
- if($dom.eq(i).is(':checked')){
- flag = true;
- }
- }
- return flag;
- }
- //检查是否上传图片
- function validateFile(){
- var flag = true;
- var $dom = $("input[name='OPTIONS']");
- for (var i = 0; i < $dom.length; i++) {
- if($dom.eq(i).parent().find("#file_name").val()==""){
- flag = false;
- }
- }
- return flag;
- }
- //情景选择题的答案
- function getAnswerValue(num,name){
-
- var str ="";
- for(var i=1;i<=num;i++){
- str += getRadioOrCheckboxValue(name+i)+"|";
- }
- return str = str.substring(0, str.length-1);
- }
- //判断单项分值是否为空
- function checkScoreOption(){
- var flag = false;
- var val = $("input[name="+name+"]").val();
- if(val == ""){
- flag = true;
- }
- return flag;
- }
- //判断单项分值与总分值
- function checkTotalOption(option_num){
- var flag = false;
- var single = 0;
- for(var i=1;i<=option_num;i++){
- var val = $("input[name='score_option_"+i+"']").val();
- single += parseInt(val);
- }
- var total = $("#QUESTION_SCORE_603").val();
-
- if(single == total){
- flag = true;
- }
- return flag;
- }
- //情景选择题分值 如:10|4,3,3 总分值与各单项分值
- function getScore(option_num){//单项个数
- var score = $("#QUESTION_SCORE_603").val();
- var str = score+"|";
- for(var i=1;i<=option_num;i++){
- var val = $("input[name='score_option_"+i+"']").val();
- str += val+",";
- }
- str = str.substring(0, str.length-1);
- return str;
- }
- function removeArr(arr,content){
- if(content==""){
- return arr;
- }
- for(var i=0;i<arr.length;i++){
- if(arr[i]==content){
- arr.splice(i,1);
- }
- }
- return arr;
- }
|