v1.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. localStorage.removeItem('requiredCols');
  2. /**
  3. * 处理输入框值变化。
  4. * Handling input box value changes.
  5. *
  6. * @access public
  7. * @return void
  8. */
  9. window.changeRows = function()
  10. {
  11. const value = $(this).val();
  12. const intValue = value < 1 ? 1 : parseInt(value, 10);
  13. $(this).val(intValue);
  14. }
  15. window.renderRowData = function()
  16. {
  17. const modeClass = $('.think-form-batch').data('modeClass');
  18. if(modeClass != undefined)
  19. {
  20. $(modeClass + ' .think-form-batch td[data-name="ACTIONS"] .btn[data-type="add"]').prop({
  21. disabled: ($(modeClass + ' .think-form-batch tbody tr').length >= canAddRowsOfMulticol || disabled),
  22. title: $(modeClass + ' .think-form-batch tbody tr').length >= canAddRowsOfMulticol ? addRowsTips.replace('%s', canAddRowsOfMulticol) : addLang,
  23. });
  24. $(modeClass + ' .think-form-batch td[data-name="ACTIONS"] .btn[data-type="delete"]').prop({
  25. disabled: disabled,
  26. })
  27. }
  28. }
  29. $(document).on('click', 'td[data-name="ACTIONS"] .btn', function()
  30. {
  31. renderRowData();
  32. if($(this).data('type') == 'add') $(this).closest('tr').next().find('td:first-child .form-control')[0].focus();
  33. });
  34. /**
  35. * 做题时有错误提示的情况下有输入事件先清空错误提示。
  36. * Clear the error prompt when there is an input event in case of an error prompt during problem solving..
  37. *
  38. * @access public
  39. * @return void
  40. */
  41. $(document).on('input', '.m-thinkrun-answer .form-batch-input', function()
  42. {
  43. $('.form .form-batch-input.has-error').each(function()
  44. {
  45. $(this).removeClass('has-error');
  46. $('.form-tip.ajax-form-tip').remove();
  47. })
  48. });
  49. /**
  50. * 处理必填列变化。
  51. * Handle changes to required columns.
  52. *
  53. * @access public
  54. * @return void
  55. */
  56. window.changeRequiredCols = function()
  57. {
  58. const changedCols = $('.required-options .picker-box').zui('picker').$.value;
  59. const quotedQuestions = $('.required-options').data().quotedQuestions;
  60. const localRequiredCols = localStorage.getItem('requiredCols') ? localStorage.getItem('requiredCols').split(',') : null;
  61. const requiredCols = localRequiredCols ? localRequiredCols : $('.required-options').data().requiredCols;
  62. const changedColsList = changedCols.split(',');
  63. const diffCols = requiredCols ? requiredCols.filter(item => !changedColsList.includes(item)) : [];
  64. let selectColumn = [];
  65. let isQuoted = false;
  66. let quotedIndex = '';
  67. /* 判断删除的比填列是不是被其他问题引用的列。 Determine whether the deleted column is a column referenced by other issues.*/
  68. quotedQuestions.forEach(function(item)
  69. {
  70. const itemOptions = JSON.parse(item.options);
  71. selectColumn.push(itemOptions.selectColumn);
  72. if(diffCols.length > 0 && itemOptions.selectColumn == diffCols[0])
  73. {
  74. quotedIndex = quotedIndex + (!isQuoted ? '' : '、') + tipQuestion.replace(/%s/g, item.index) ;
  75. isQuoted = true;
  76. }
  77. });
  78. /* 如果删除的比填列是被其他问题引用的列则不能删除,并弹出弹窗提示;如果不是被其他问题引用的列则成功删除,并且储存删除后的值。*/
  79. /* If the deleted column is a column referenced by other issues, it cannot be deleted and a pop-up prompt will appear; If the column is not referenced by other issues, it will be successfully deleted and the deleted value will be saved. */
  80. if(isQuoted)
  81. {
  82. $('.required-options .picker-box').zui('picker').$.setValue(requiredCols);
  83. zui.Modal.alert({message: requiredColTip.replace(/%s/g, quotedIndex), icon: 'icon-exclamation-sign', iconClass: 'warning-pale rounded-full icon-2x', size: 'sm'});
  84. }
  85. if(!isQuoted) localStorage.setItem('requiredCols', changedCols);
  86. }
  87. /**
  88. * 修改引用题目。
  89. * Change quote title.
  90. *
  91. * @access public
  92. * @return void
  93. */
  94. window.changeQuoteTitle = function()
  95. {
  96. let fields = []; // 所有的多列填空题的配置项
  97. let requiredFields = []; // 多列填空题必填的标题id
  98. let citationItems = []; // 选择列picker组件的下拉项
  99. let isMulticolumn = false;
  100. let multicolumnStep = false
  101. const quoteQuestions = $('.options-quote-title').data('quoteQuestions');
  102. const quoteTitle = $('input[name="options[quoteTitle]"]').val();
  103. const selectColumn = $('.options-quote-title').data('selectColumn');
  104. const citation = $('.quote-citation').data('citation');
  105. $.each(quoteQuestions, function(index, item) {
  106. const options = JSON.parse(item.options);
  107. if(quoteTitle && item.id == quoteTitle && options.questionType === 'multicolumn')
  108. {
  109. multicolumnStep = true;
  110. requiredFields = options.requiredCols;
  111. fields = options.fields;
  112. }
  113. });
  114. /* 渲染选择列的下拉项。Renders a drop-down item for a select column.*/
  115. $.each(requiredFields, function(index, key) {
  116. /* 必填列的值是多列填空fields数组的key。The value of in the required column is the key for the multi column fill in the blank fields array. */
  117. const keyValue = parseInt(key);
  118. citationItems.push({key: keyValue, value:keyValue, text: fields[keyValue - 1]});
  119. })
  120. $('.quote-citation').toggleClass('gap-4', multicolumnStep);
  121. $('.select-column').toggleClass('hidden', !multicolumnStep);
  122. $('.citation').toggleClass('hidden', multicolumnStep);
  123. $('.multicolumn-citation').toggleClass('hidden', !multicolumnStep);
  124. if(multicolumnStep)
  125. {
  126. /* 引用题目为多列填空题的时候,重置选择列的下拉选项和默认值, 修改引用方式为:引用某行输入项。 */
  127. /* When the reference question is a multi-column fill-in-the-blank question, reset the drop-down options and default values of the selected column, and change the reference method to: reference an input item in a row. */
  128. $('.select-column .picker-box').zui('picker').render({items: citationItems});
  129. $('.select-column .picker-box').zui('picker').$.setValue(selectColumn || citationItems[0]);
  130. $('.multicolumn-citation input[name="options[citation]"]').prop('checked', true);
  131. }
  132. else
  133. {
  134. /* 引用题目类型为多选或者单选题是,清空选择列的下拉选项和默认值,修改默认引用方式为:引用题的选中项。 */
  135. /* If the reference question type is multiple choice or single choice, clear the drop-down options and default values in the selection column, and change the default reference method to: reference the selected item in the question. */
  136. const defaultCitation = typeof citation != 'undefined' && citation < 3 ? citation : 1;
  137. $('.select-column .picker-box').zui('picker').render({items: []});
  138. $('.select-column .picker-box').zui('picker').$.setValue('');
  139. $('.citation input[id="options[citation]' + defaultCitation + '"]').prop('checked', true);
  140. }
  141. }
  142. /**
  143. * 隐藏必填列。
  144. * Hide required columns..
  145. *
  146. * @access public
  147. * @return void
  148. */
  149. window.hiddenRequiredCols = function()
  150. {
  151. const requiredValue = $('input[name="options[required]"]:checked').val();
  152. const setOptionsValue = $('input[name="options[setOption]"]:checked').val();
  153. $('.required-options').toggleClass('hidden', setOptionsValue == '1' || (setOptionsValue == '0' && requiredValue == '0'))
  154. }
  155. /**
  156. * 修改选项配置。
  157. * Change option configuration.
  158. *
  159. * @param target
  160. * @access public
  161. * @return void
  162. */
  163. window.changeMulticolumnSetOption = function(target)
  164. {
  165. $('.think-options-field').toggleClass('hidden', target.value == 1);
  166. $('.think-quote').toggleClass('hidden', target.value == 0);
  167. hiddenRequiredCols();
  168. $('.text-danger').remove();
  169. $('.has-error').removeClass('has-error');
  170. $('.required-tip button').toggleClass('hidden', target.value == 0);
  171. }