v1.js 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * 修改引用题目。
  3. * Change quote title.
  4. *
  5. * @access public
  6. * @return void
  7. */
  8. window.changeQuoteTitle = function()
  9. {
  10. let fields = []; // 所有的多列填空题的配置项
  11. let requiredFields = []; // 多列填空题必填的标题id
  12. let citationItems = []; // 选择列picker组件的下拉项
  13. let isMulticolumn = false;
  14. let multicolumnStep = false
  15. const quoteQuestions = $('.options-quote-title').data('quoteQuestions');
  16. const quoteTitle = $('input[name="options[quoteTitle]"]').val();
  17. const selectColumn = $('.options-quote-title').data('selectColumn');
  18. const citation = $('.quote-citation').data('citation');
  19. $.each(quoteQuestions, function(index, item) {
  20. const options = JSON.parse(item.options);
  21. if(quoteTitle && item.id == quoteTitle && options.questionType === 'multicolumn')
  22. {
  23. multicolumnStep = true;
  24. requiredFields = options.requiredCols;
  25. fields = options.fields;
  26. }
  27. });
  28. /* 渲染选择列的下拉项。Renders a drop-down item for a select column.*/
  29. $.each(requiredFields, function(index, key) {
  30. /* 必填列的值是多列填空fields数组的key。The value of in the required column is the key for the multi column fill in the blank fields array. */
  31. const keyValue = parseInt(key);
  32. citationItems.push({key: keyValue, value:keyValue, text: fields[keyValue - 1]});
  33. })
  34. $('.quote-citation').toggleClass('gap-4', multicolumnStep);
  35. $('.select-column').toggleClass('hidden', !multicolumnStep);
  36. $('.citation').toggleClass('hidden', multicolumnStep);
  37. $('.multicolumn-citation').toggleClass('hidden', !multicolumnStep);
  38. if(multicolumnStep)
  39. {
  40. /* 引用题目为多列填空题的时候,重置选择列的下拉选项和默认值, 修改引用方式为:引用某行输入项。 */
  41. /* 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. */
  42. $('.select-column .picker-box').zui('picker').render({items: citationItems});
  43. $('.select-column .picker-box').zui('picker').$.setValue(selectColumn || citationItems[0]);
  44. $('.multicolumn-citation input[name="options[citation]"]').prop('checked', true);
  45. }
  46. else
  47. {
  48. /* 引用题目类型为多选或者单选题是,清空选择列的下拉选项和默认值,修改默认引用方式为:引用题的选中项。 */
  49. /* 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. */
  50. const defaultCitation = typeof citation != 'undefined' && citation < 3 ? citation : 1;
  51. $('.select-column .picker-box').zui('picker').render({items: []});
  52. $('.select-column .picker-box').zui('picker').$.setValue('');
  53. $('.citation input[id="options[citation]' + defaultCitation + '"]').prop('checked', true);
  54. }
  55. }
  56. /**
  57. * 修改选项配置。
  58. * Change option configuration.
  59. *
  60. * @param target
  61. * @access public
  62. * @return void
  63. */
  64. window.changeCheckboxSetOption = function(target)
  65. {
  66. const maxCountPlaceholder = $('.step-required').data('maxCountPlaceholder');
  67. const inputContent = $('.step-required').data('inputContent');
  68. $('.think-options-field').toggleClass('hidden', target.value == 1);
  69. $('.think-quote').toggleClass('hidden', target.value == 0);
  70. if(target.value == 1)
  71. {
  72. $('.min-count input').val(1).attr('disabled', 'disabled');
  73. $('.max-count input').val('').attr('placeholder', maxCountPlaceholder).attr('disabled', 'disabled');
  74. }
  75. else
  76. {
  77. $('.min-count input').val('').removeAttr('disabled');
  78. $('.max-count input').attr('placeholder', inputContent).removeAttr('disabled');
  79. }
  80. $('.text-danger').remove();
  81. $('.has-error').removeClass('has-error');
  82. }