From b365b604f71c45e9c077913da92407c3b5d256d7 Mon Sep 17 00:00:00 2001 From: Mohammad Zubair Ali Date: Thu, 28 Nov 2024 11:02:13 +0530 Subject: [PATCH 1/2] fixed category js issue --- js/qsm-admin.js | 60 ++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/js/qsm-admin.js b/js/qsm-admin.js index e0df57c7..e89d5f70 100644 --- a/js/qsm-admin.js +++ b/js/qsm-admin.js @@ -1428,11 +1428,11 @@ function qsm_is_substring_in_array( text, array ) { editor.selection.setContent(contentToInsert); showAutocomplete(editor, true); }); - + $(document).off('input', '.qsm-autocomplete-search-input').on('input', '.qsm-autocomplete-search-input', function () { let query = $(this).val().toLowerCase(); // Get the current input value and convert to lowercase let hasResults = false; - + $('.qsm-autocomplete-item').each(function () { let title = $(this).attr('variable').toLowerCase(); // Get the title attribute of the current item if (title.includes(query)) { @@ -1442,10 +1442,10 @@ function qsm_is_substring_in_array( text, array ) { $(this).hide(); // Hide items that don't match } }); - + // Check for the "no items" message let noItemElement = $(this).parents('.qsm-autocomplete').find('.qsm-autocomplete-no-item'); - + if (hasResults) { noItemElement.remove(); // Remove the "no items" message if results are found $(this).parents('.qsm-autocomplete').find('.qsm-autocomplete-item-group').show(); @@ -1456,7 +1456,7 @@ function qsm_is_substring_in_array( text, array ) { $(this).parents('.qsm-autocomplete').append(item_group); $(this).parents('.qsm-autocomplete').find('.qsm-autocomplete-item-group').hide(); } - }); + }); }); } } @@ -1989,7 +1989,7 @@ var QSM_Quiz_Broadcast_Channel; QSM_Quiz_Broadcast_Channel = { channel: new BroadcastChannel('qsm_quiz_data_channel'), questionData: [], // Initialize as an array - + // Initialize the event listeners and set up channel init: function () { this.setupChannelListener(); @@ -2010,7 +2010,7 @@ var QSM_Quiz_Broadcast_Channel; insertQuestionToChannel: function (question) { let linkQuizzesArray = Object.values(question.get('link_quizzes')); - + let sendDataObject = { [question.id]: { merged_question: question.get('merged_question'), @@ -2019,7 +2019,7 @@ var QSM_Quiz_Broadcast_Channel; }; this.questionData.push(sendDataObject); }, - + // Function to send the linked question data to other tabs sendQuestionData: function (questionID, mergedQuestion, linkedQuizzes = []) { let sendDataObject = { @@ -2033,7 +2033,7 @@ var QSM_Quiz_Broadcast_Channel; this.questionData.push(sendDataObject); this.channel.postMessage(sendDataObject); }, - + updateQuestionData: function (data){ const receivedData = data; for (let questonId in receivedData) { @@ -2098,7 +2098,7 @@ var QSM_Quiz_Broadcast_Channel; model.set('merged_question', ''); model.set('link_quizzes', []); }, - + afterUpdateUnlinkedQuestion: function (data) { const receivedData = data; for (let questonId in receivedData) { @@ -2114,14 +2114,14 @@ var QSM_Quiz_Broadcast_Channel; let currentInQuizQuestion = QSMQuestion.questions.get(key); currentInQuizQuestion.set('merged_question', mergedQuestions); currentInQuizQuestion.set('link_quizzes', item[key].link_quizzes.filter(quiz => quiz != singleQuizName)); - } + } } }); }); } }, - }; - + }; + QSMQuestion = { question: Backbone.Model.extend({ defaults: { @@ -2250,19 +2250,19 @@ var QSM_Quiz_Broadcast_Channel; if (QSMQuestion.questions.some(q => q.get('id') == questionId)) { let $linkButton = $(this).find('.link-question'); if ($linkButton.length) { - $linkButton.prop('disabled', true).addClass('disabled'); + $linkButton.prop('disabled', true).addClass('disabled'); } } QSMQuestion.questions.each(function (question) { let merged_questions = question.get('merged_question'); let questionsArray = merged_questions ? merged_questions.split(',').map(q => q.trim()) : []; - questionsArray.forEach(function (id) { + questionsArray.forEach(function (id) { let parentElement = $('.question-bank-question[data-question-id="' + id + '"]'); if (parentElement.length) { parentElement.remove(); // Remove the element if it exists } }); - }); + }); }); } }, @@ -2489,7 +2489,7 @@ var QSM_Quiz_Broadcast_Channel; for (const record of qsm_admin_messages.qsmQuizzesObject) { if (record.quiz_id == quizId) { quizName = record.quiz_name; break; } - } + } const linkQuizzes = [...model.get('link_quizzes')]; // Created a shallow copy of the array if (quizName !== '') { linkQuizzes.push(quizName); @@ -2773,7 +2773,7 @@ var QSM_Quiz_Broadcast_Channel; //No Action Require } else { $.each(multicategories, function (i, val) { - category.push($(".qsm-popup__content #qsm_category-" + val + " label:first-child")[0].textContent); + category.push($(".qsm-popup__content #qsm_category-" + val + " label").text()); }); category = category.filter(item => item); } @@ -3066,7 +3066,7 @@ var QSM_Quiz_Broadcast_Channel; } let link_quizzes_object = question.get('link_quizzes'); - + $('.qsm-linked-list-inside').hide().empty(); $('.qsm-linked-list-div-block').hide(); if (typeof link_quizzes_object == 'object' && link_quizzes_object != null && Object.keys(link_quizzes_object).length > 0) { @@ -3077,12 +3077,12 @@ var QSM_Quiz_Broadcast_Channel; .attr('class', 'qsm-linked-list-item') .attr('title', quizName) .text(quizName.length > 25 ? quizName.substring(0, 25) + '...' : quizName); - + $('.qsm-linked-list-div-block').show(); $('.qsm-linked-list-inside').append(link); } }); - + // Add an "Unlink" link at the end let unlink = $('') .attr('class', 'qsm-unlink-the-question button button-danger') @@ -3586,7 +3586,7 @@ var QSM_Quiz_Broadcast_Channel; MicroModal.close('modal-2'); }); - + $(document).on('click', '.qsm-popup-bank .link-question', function (event) { event.preventDefault(); $(this).text(qsm_admin_messages.linking_question); @@ -3768,7 +3768,7 @@ var QSM_Quiz_Broadcast_Channel; if (qsmQuestionSettings.qsm_user_ve === 'true') { QSMQuestion.prepareEditor(); } - + // Initialize the QSM_Quiz_Broadcast_Channel QSM_Quiz_Broadcast_Channel.init(); QSMQuestion.loadQuestions(); @@ -4286,11 +4286,11 @@ var QSM_Quiz_Broadcast_Channel; console.log($parent); $(this).closest('.results-page-condition').remove(); QSMAdminResults.updateResultConditonCount($parent); - }); + }); }); } } - + jQuery(document).on('click', '.qsm-toggle-result-page-button, .qsm-toggle-email-template-button', function () { jQuery(this).closest("header").next("main").slideToggle(); let $img = jQuery(this).find('img'); @@ -4298,17 +4298,17 @@ var QSM_Quiz_Broadcast_Channel; let arrowUpImage = qsm_admin_messages.arrow_up_image; let arrowDownImage = qsm_admin_messages.arrow_down_image; - // Toggle the image + // Toggle the image if (currentSrc === arrowUpImage) { $img.attr('src', arrowDownImage); } else { $img.attr('src', arrowUpImage); } - }); + }); jQuery(document).on('click', '.qsm-settings-box-result-button', function () { jQuery('.qsm-settings-box-details').not(jQuery(this).parents('.qsm-template-btn-group').find('.qsm-settings-box-details')).hide(); jQuery(this).parents('.qsm-template-btn-group').find('.qsm-settings-box-details').toggle(); - }); + }); jQuery(document).on('click', function (e) { // Check if the click was outside .qsm-template-btn-group if (!jQuery(e.target).closest('.qsm-template-btn-group').length) { @@ -4585,14 +4585,14 @@ jQuery(document).ready(function() { if (confirm(qsm_result_page.delete_confirm)) { jQuery('form[name="bulk_delete_form"]').submit(); } - } + } // Handle permanent delete action else if (action === 'bulk_permanent_delete') { if (confirm(qsm_result_page.delete_confirm)) { jQuery('#bulk_permanent_delete').val('1'); jQuery('form[name="bulk_delete_form"]').submit(); } - } + } else { alert(qsm_result_page.delete_alert); } From 18f17cbc0ed5ad73ed2182f31a2a8060dbacfbae Mon Sep 17 00:00:00 2001 From: Mohammad Zubair Ali Date: Thu, 28 Nov 2024 11:25:01 +0530 Subject: [PATCH 2/2] fixed category js issue --- js/qsm-admin.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/js/qsm-admin.js b/js/qsm-admin.js index e89d5f70..437eff05 100644 --- a/js/qsm-admin.js +++ b/js/qsm-admin.js @@ -2769,13 +2769,13 @@ var QSM_Quiz_Broadcast_Channel; } var category = []; var multicategories = model.get('multicategories'); - if (multicategories === null || typeof multicategories === "undefined") { - //No Action Require - } else { - $.each(multicategories, function (i, val) { - category.push($(".qsm-popup__content #qsm_category-" + val + " label").text()); + if (multicategories) { + multicategories.forEach(val => { + const categoryLabel = $(".qsm-popup__content #in-qsm_category-" + val + "-1 > label").text(); + if (categoryLabel) { + category.push(categoryLabel); + } }); - category = category.filter(item => item); } $('.question[data-question-id=' + model.id + ']').replaceWith(template({ id: model.id,