Skip to content

Commit

Permalink
Fixed issue CR-1352: Saving subquestions and answers caused display e…
Browse files Browse the repository at this point in the history
…rrors (#3514)
  • Loading branch information
twilligls committed Nov 8, 2023
1 parent 24ffc5c commit 8e9d081
Showing 1 changed file with 34 additions and 23 deletions.
57 changes: 34 additions & 23 deletions assets/scripts/admin/questionEditor.js
Expand Up @@ -178,6 +178,29 @@ $(document).on('ready pjax:scriptcomplete', function () {
});
}

function bindSubQuestionEvents() {
$('.btnaddsubquestion').off('click.subquestions').on('click.subquestions', addSubquestionInput);
$('.btndelsubquestion').off('click.subquestions').on('click.subquestions', deleteSubquestionInput);
}

function bindAnswerEvents() {
$('.btnaddanswer').off('click.subquestions').on('click.subquestions', addAnswerOptionInput);
$('.btndelanswer').off('click.subquestions').on('click.subquestions', deleteAnswerOptionInput);
}

function toggleLanguageElements() {
// get selected lang from dropdown
let lang = $('.active .lang-switch-button').data('lang');
//fallback: display main language
if (lang === undefined) {
const languages = languageJson.langs.split(';');
lang = languages[0];
}
const langClass = `.lang-${lang}`;
$('.lang-hide').hide();
$(langClass).show();
}

/**
* @param {number} position
* @param {string} source Either 'subquestions' or 'answeroptions'
Expand Down Expand Up @@ -527,8 +550,7 @@ $(document).on('ready pjax:scriptcomplete', function () {
const target = e.target;
const data = $('#add-subquestion-input-javascript-datas').data();
const rebindClickHandler = () => {
$('.btnaddsubquestion').off('click.subquestions').on('click.subquestions', addSubquestionInput);
$('.btndelsubquestion').off('click.subquestions').on('click.subquestions', deleteSubquestionInput);
bindSubQuestionEvents()
};
addNewInputAux(target, data, rebindClickHandler);
}
Expand All @@ -544,8 +566,7 @@ $(document).on('ready pjax:scriptcomplete', function () {
const target = e.target;
const data = $('#add-answer-option-input-javascript-datas').data();
const rebindClickHandler = () => {
$('.btnaddanswer').off('click.subquestions').on('click.subquestions', addAnswerOptionInput);
$('.btndelanswer').off('click.subquestions').on('click.subquestions', deleteAnswerOptionInput);
bindAnswerEvents();
};
addNewInputAux(target, data, rebindClickHandler);
}
Expand Down Expand Up @@ -1165,15 +1186,9 @@ $(document).on('ready pjax:scriptcomplete', function () {
bindClickIfNotExpanded();

// Unbind and bind events.
$(`.btnaddanswer`).off('click.subquestions');
$(`.btndelanswer`).off('click.subquestions');
$(`.btnaddsubquestion`).off('click.subquestions');
$(`.btndelsubquestion`).off('click.subquestions');
$(`.answer`).off('focus');
$(`.btnaddanswer`).on('click.subquestions', addAnswerOptionInput);
$(`.btndelanswer`).on('click.subquestions', deleteAnswerOptionInput);
$(`.btnaddsubquestion`).on('click.subquestions', addSubquestionInput);
$(`.btndelsubquestion`).on('click.subquestions', deleteSubquestionInput);
bindSubQuestionEvents();
bindAnswerEvents();
},
);
}
Expand Down Expand Up @@ -1690,11 +1705,8 @@ $(document).on('ready pjax:scriptcomplete', function () {
const languages = languageJson.langs.split(';');
$('.lang-switch-button[data-lang="' + languages[0] + '"]').trigger('click');

// TODO: Duplication.
$('.btnaddsubquestion').on('click.subquestions', addSubquestionInput);
$('.btndelsubquestion').on('click.subquestions', deleteSubquestionInput);
$('.btnaddanswer').on('click.subquestions', addAnswerOptionInput);
$('.btndelanswer').on('click.subquestions', deleteAnswerOptionInput);
bindSubQuestionEvents();
bindAnswerEvents();
} catch (ex) {
$('#ls-loading').hide();
// TODO: How to show internal errors?
Expand Down Expand Up @@ -1874,9 +1886,10 @@ $(document).on('ready pjax:scriptcomplete', function () {
url: languageJson.lsextraoptionsurl,
success: (response /*: string */, textStatus /*: string */) => {
$('#extra-options-container').replaceWith( response );
$('.btnaddsubquestion').off('click.subquestions').on('click.subquestions', addSubquestionInput);
$('.btndelsubquestion').off('click.subquestions').on('click.subquestions', deleteSubquestionInput);
bindSubQuestionEvents();
bindAnswerEvents();
makeAnswersTableSortable();
toggleLanguageElements();
// Hide loading gif.
$('#ls-loading').hide();
},
Expand Down Expand Up @@ -2039,10 +2052,8 @@ $(document).on('ready pjax:scriptcomplete', function () {

makeAnswersTableSortable();

$('.btnaddsubquestion').off('click.subquestions').on('click.subquestions', addSubquestionInput);
$('.btndelsubquestion').off('click.subquestions').on('click.subquestions', deleteSubquestionInput);
$('.btnaddanswer').off('click.subquestions').on('click.subquestions', addAnswerOptionInput);
$('.btndelanswer').off('click.subquestions').on('click.subquestions', deleteAnswerOptionInput);
bindSubQuestionEvents();
bindAnswerEvents();

$('#labelsetbrowserModal').on('hidden.bs.modal.', labelSetDestruct);

Expand Down

0 comments on commit 8e9d081

Please sign in to comment.