7ead5e97b0a31b528e069bf16b3380089fcf8df0.svn-base 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. questionBankAddEdit = function() {
  2. /**定义变量**/
  3. var _this = this;
  4. /**私有方法**/
  5. /***新增信息***/
  6. _this.save = function(addType){
  7. /*var pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?]");
  8. if(pattern.test($("#QUESTION_NAME_603").val())){
  9. top.Dialog.alert("题目名称不能包含特殊字符");
  10. return;
  11. }*/
  12. var option_num = $("#opt_input").val();
  13. var question_type = $("#QUESTION_TYPE_603").val();
  14. if(question_type=="4"){
  15. $("#QUESTION_ANSWER_603").val(getAnswerValue(option_num,"OPTIONS_"));
  16. $("#ANSWER_OPTION_603").val(getAnswerValue(option_num,"opt_type_"));
  17. }else{
  18. $("#QUESTION_ANSWER_603").val(getRadioOrCheckboxValue("OPTIONS"));
  19. }
  20. $("#APPLICABLE_OBJECT_603").val(getRadioOrCheckboxValue("applicable_type"));
  21. $("#ANSWER_TYPE_603").val(getRadioOrCheckboxValue("opt_type"));
  22. $("#603Class").val("603");
  23. $form = $('#editForm');
  24. var valid = $form.validationEngine({returnIsValid: true});
  25. if(!valid){
  26. top.Dialog.alert(CHECKREDBOX);
  27. return;
  28. }
  29. if(!validateCheck("applicable_type")){
  30. top.Dialog.alert("请选择适用对象!");
  31. return;
  32. }
  33. if($("#ANSWER_TYPE_603").val()=="2"){
  34. if(!validateFile()){
  35. top.Dialog.alert("请选择上传文件!");
  36. return;
  37. }
  38. }
  39. if(question_type=="4"){
  40. for(var i=1;i<=option_num;i++){
  41. if(!validateCheck("OPTIONS_"+i)){
  42. top.Dialog.alert("请选择第"+i+"个选项答案!");
  43. return;
  44. }
  45. /*if(checkScoreOption("score_option_"+i)){
  46. top.Dialog.alert("请填写第"+i+"个单项分值!");
  47. return;
  48. }*/
  49. }
  50. /*if(!checkTotalOption(option_num)){
  51. top.Dialog.alert("总分值与单项分值不一致");
  52. return;
  53. }*/
  54. }else{
  55. if(!validateCheck("OPTIONS")){
  56. top.Dialog.alert("请选择选项答案!");
  57. return;
  58. }
  59. }
  60. $("#QUESTION_SCORE_603").val(getScore(option_num));
  61. $form = $('#editForm');
  62. if(valid){
  63. showProgressBar("正在提交中...");
  64. var url = $.pathname() + '/ws/crud/CRUDService/create/';
  65. if(fd_id!=undefined&&fd_id!=""){
  66. url = $.pathname() + "/ws/crud/CRUDService/update/";
  67. }
  68. var formValue = $form.serialize();
  69. //alert("formValue==="+JSON.stringify(formValue));
  70. $.request.add(url,formValue,function(data){//保存题目主表数据
  71. //alert("data=="+JSON.stringify(data));
  72. saveSubTableData(data.Msg.objectID,addType);
  73. });
  74. }
  75. };
  76. _this.saveAndAgain = function(){
  77. _this.save("again");
  78. };
  79. _this.formReset = function(){
  80. $('#frmright',window.parent.document).attr('src',$.pathname()+"/page/business/exercise/examineManagement/questionBankAddEdit.jsp?fd_id="+fd_id);
  81. };
  82. return {
  83. init : function() {
  84. $('#save').bind('click',function(){
  85. _this.save();
  86. });
  87. $("#saveAndAgain").bind("click",function(){
  88. _this.saveAndAgain();
  89. });
  90. $('#goback').bind('click',function(){
  91. $('#frmright',window.parent.document).attr('src',$.pathname()+"/page/business/exercise/examineManagement/questionBank.jsp");
  92. });
  93. $('#giveUp').bind('click',function(){
  94. $('#frmright',window.parent.document).attr('src',$.pathname()+"/page/business/exercise/examineManagement/questionBank.jsp");
  95. });
  96. }
  97. };
  98. }();
  99. $(function() {
  100. questionBankAddEdit.init();
  101. });
  102. function saveSubTableData(questionId,addType){
  103. //alert("questionId=="+questionId)
  104. var question_type = $("#QUESTION_TYPE_603").val();
  105. // if(question_type=="3"){//判断题,判断题不需要在副表保存题目
  106. // var options = $("input[name=OPTIONS]").val();
  107. // alert(options);
  108. // $("#OPTION_604").val(options);
  109. // $("#QUESTION_ID_604").val(questionId);
  110. // var option_content = "";
  111. // if($("input[name=OPTIONS][checked=checked]").index("input[name=OPTIONS]")==1){
  112. // option_content = "正确";
  113. // }else{
  114. // option_content = "错误";
  115. // }
  116. // $("#OPTION_CONTENT_604").val(option_content);
  117. // }else
  118. if(question_type=="4"){//情景选择题
  119. var option_num = $("#opt_input").val();
  120. var fd_ids_604 = $("#FD_OBJECTID604").val();
  121. fd_ids_604 = fd_ids_604.split(",");
  122. var arr = $("#FD_OBJECTID604").val().split(",");
  123. var sum = 0;
  124. for(var j =1;j<=option_num;j++){
  125. var $optionDom = $("input[name=OPTIONS_"+j+"]");
  126. for (var i = 0; i < $optionDom.length; i++) {//循环保存
  127. $("#OPTION_604").val($optionDom.eq(i).val());//存序号
  128. $("#604Class").val("604");
  129. $("#QUESTION_ID_604").val(questionId);
  130. var option_content = $optionDom.eq(i).parent().find(".answer_content").val();
  131. $("#OPTION_CONTENT_604").val(option_content);
  132. $("#OPTION_INDEX_604").val(j);
  133. var url = $.pathname() + '/ws/crud/CRUDService/create/';
  134. if(!(fd_id=="null"||fd_id=="")){
  135. var answer_id = $optionDom.eq(i).parent().find(".answer_id").val();//获取答案id
  136. $("#FD_OBJECTID604").val(answer_id);
  137. arr = removeArr(arr,answer_id);//将多余的答案移除
  138. if(answer_id!=""){
  139. url = $.pathname() +"/ws/crud/CRUDService/update/";
  140. }
  141. }
  142. /*var url = $.pathname() + '/ws/crud/CRUDService/create/';
  143. if(fd_ids_604[sum]!=undefined&&fd_ids_604[sum]!=""){
  144. url = $.pathname() +"/ws/crud/CRUDService/update/";
  145. }*/
  146. var formValue = $("#editFormSub").serialize();
  147. //alert("formValue_sub===="+JSON.stringify(formValue));
  148. /*$.request.add(url,formValue,function(data){
  149. closeProgress();
  150. });*/
  151. $.ajax({//保存题目主表数据
  152. url : url,
  153. data : formValue,
  154. type : 'post',
  155. timeout : 15000,
  156. dataType : 'json',
  157. async : false,
  158. success : function(data) {
  159. }
  160. });
  161. if(i==$optionDom.length-1 && j == option_num){
  162. closeProgress();
  163. top.Dialog.alert("保存成功!");
  164. if(addType=="again"){
  165. $('#frmright',window.parent.document).attr('src',$.pathname()+"/page/business/exercise/examineManagement/questionBankAddEdit.jsp?versionId="+versionId+"&fd_id=");
  166. }else{
  167. $('#frmright',window.parent.document).attr('src',$.pathname()+"/page/business/exercise/examineManagement/questionBank.jsp");
  168. }
  169. }
  170. sum++;
  171. }
  172. }
  173. //删除移除的答案
  174. if(!(fd_id=="null"||fd_id=="")){
  175. for(var i=0;i<arr.length;i++){
  176. var url = $.pathname() + '/ws/crud/CRUDService/delete/';
  177. var params = {
  178. objectIDs : arr[i],
  179. classid : 604
  180. };
  181. $.ajax({
  182. url : url,
  183. data : params,
  184. type : 'post',
  185. timeout : 15000,
  186. dataType : 'json',
  187. async : false,
  188. success : function(data) {
  189. }
  190. });
  191. }
  192. }
  193. }else{//选择题(单选or多选)
  194. var answer_type = $("#ANSWER_TYPE_603").val();
  195. var $optionDom = $("input[name=OPTIONS]");
  196. var fd_ids_604 = $("#FD_OBJECTID604").val();
  197. fd_ids_604 = fd_ids_604.split(",");
  198. var arr = fd_ids_604;
  199. for (var i = 0; i < $optionDom.length; i++) {//循环保存
  200. $("#OPTION_604").val($optionDom.eq(i).val());//存序号
  201. $("#604Class").val("604");
  202. $("#FD_OBJECTID604").val(fd_ids_604[i]);
  203. $("#QUESTION_ID_604").val(questionId);
  204. if(question_type=="3"){//判断题
  205. var content = $optionDom.eq(i).next().next().text();
  206. $("#OPTION_CONTENT_604").val(content);
  207. }else{
  208. var option_content = "";
  209. if(answer_type == 1){
  210. option_content = $optionDom.eq(i).parent().find(".answer_content").val();
  211. }else{
  212. option_content = $optionDom.eq(i).parent().find("#file_name").val();
  213. }
  214. $("#OPTION_CONTENT_604").val(option_content);
  215. }
  216. var url = $.pathname() + '/ws/crud/CRUDService/create/';
  217. if(fd_ids_604[i]!=undefined&&fd_ids_604[i]!=""){
  218. url = $.pathname() +"/ws/crud/CRUDService/update/";
  219. arr = removeArr(arr,fd_ids_604[i]);//将多余的答案移除
  220. //fd_ids_604.splice(i,1);
  221. }
  222. var formValue = $("#editFormSub").serialize();
  223. //alert("formValue_sub===="+JSON.stringify(formValue));
  224. /*$.request.add(url,formValue,function(data){//保存题目主表数据
  225. closeProgress();
  226. });*/
  227. $.ajax({//保存题目主表数据
  228. url : url,
  229. data : formValue,
  230. type : 'post',
  231. timeout : 15000,
  232. dataType : 'json',
  233. async : false,
  234. success : function(data) {
  235. }
  236. });
  237. if(i==$optionDom.length-1){
  238. top.Dialog.alert("保存成功!");
  239. if(addType=="again"){
  240. $('#frmright',window.parent.document).attr('src',$.pathname()+"/page/business/exercise/examineManagement/questionBankAddEdit.jsp?versionId="+versionId+"&fd_id=");
  241. }else{
  242. $('#frmright',window.parent.document).attr('src',$.pathname()+"/page/business/exercise/examineManagement/questionBank.jsp");
  243. }
  244. }
  245. }
  246. //删除移除的答案
  247. if(fd_id!=""){
  248. for(var i=0;i<arr.length;i++){
  249. var url = $.pathname() + '/ws/crud/CRUDService/delete/';
  250. var params = {
  251. objectIDs : arr[i],
  252. classid : 604
  253. };
  254. $.ajax({
  255. url : url,
  256. data : params,
  257. type : 'post',
  258. timeout : 15000,
  259. dataType : 'json',
  260. async : false,
  261. success : function(data) {
  262. }
  263. });
  264. }
  265. }
  266. }
  267. }
  268. //求单选or多选按钮的值,传radio 或 checkbox的名字作为参数
  269. function getRadioOrCheckboxValue(name){
  270. var checkValues = "";
  271. var $dom = $("input[name="+name+"]");
  272. for (var i = 0; i < $dom.length; i++) {
  273. //alert($dom.eq(i).attr("checked"));
  274. if($dom.eq(i).attr("checked")=="checked"){
  275. checkValues += $dom.eq(i).val()+",";
  276. }
  277. }
  278. checkValues = checkValues.substring(0, checkValues.length-1);
  279. //alert(checkValues);
  280. return checkValues;
  281. }
  282. //检查是否选中
  283. function validateCheck(name){
  284. var flag = false;
  285. var $dom = $("input[name="+name+"]");
  286. for (var i = 0; i < $dom.length; i++) {
  287. if($dom.eq(i).is(':checked')){
  288. flag = true;
  289. }
  290. }
  291. return flag;
  292. }
  293. //检查是否上传图片
  294. function validateFile(){
  295. var flag = true;
  296. var $dom = $("input[name='OPTIONS']");
  297. for (var i = 0; i < $dom.length; i++) {
  298. if($dom.eq(i).parent().find("#file_name").val()==""){
  299. flag = false;
  300. }
  301. }
  302. return flag;
  303. }
  304. //情景选择题的答案
  305. function getAnswerValue(num,name){
  306. var str ="";
  307. for(var i=1;i<=num;i++){
  308. str += getRadioOrCheckboxValue(name+i)+"|";
  309. }
  310. return str = str.substring(0, str.length-1);
  311. }
  312. //判断单项分值是否为空
  313. function checkScoreOption(){
  314. var flag = false;
  315. var val = $("input[name="+name+"]").val();
  316. if(val == ""){
  317. flag = true;
  318. }
  319. return flag;
  320. }
  321. //判断单项分值与总分值
  322. function checkTotalOption(option_num){
  323. var flag = false;
  324. var single = 0;
  325. for(var i=1;i<=option_num;i++){
  326. var val = $("input[name='score_option_"+i+"']").val();
  327. single += parseInt(val);
  328. }
  329. var total = $("#QUESTION_SCORE_603").val();
  330. if(single == total){
  331. flag = true;
  332. }
  333. return flag;
  334. }
  335. //情景选择题分值 如:10|4,3,3 总分值与各单项分值
  336. function getScore(option_num){//单项个数
  337. var score = $("#QUESTION_SCORE_603").val();
  338. var str = score+"|";
  339. for(var i=1;i<=option_num;i++){
  340. var val = $("input[name='score_option_"+i+"']").val();
  341. str += val+",";
  342. }
  343. str = str.substring(0, str.length-1);
  344. return str;
  345. }
  346. function removeArr(arr,content){
  347. if(content==""){
  348. return arr;
  349. }
  350. for(var i=0;i<arr.length;i++){
  351. if(arr[i]==content){
  352. arr.splice(i,1);
  353. }
  354. }
  355. return arr;
  356. }