Skip to content

Commit

Permalink
Merge pull request #2724 from QuizandSurveyMaster/dev-zubair
Browse files Browse the repository at this point in the history
Dev zubair
  • Loading branch information
zubairraeen authored Nov 28, 2024
2 parents 055bdf0 + 18f17cb commit 545af9f
Showing 1 changed file with 35 additions and 35 deletions.
70 changes: 35 additions & 35 deletions js/qsm-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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();
Expand All @@ -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();
}
});
});
});
}
}
Expand Down Expand Up @@ -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();
Expand All @@ -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'),
Expand All @@ -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 = {
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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: {
Expand Down Expand Up @@ -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
}
});
});
});
});
}
},
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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:first-child")[0].textContent);
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,
Expand Down Expand Up @@ -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) {
Expand All @@ -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 = $('<span></span>')
.attr('class', 'qsm-unlink-the-question button button-danger')
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -4286,29 +4286,29 @@ 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');
let currentSrc = $img.attr('src');
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) {
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 545af9f

Please sign in to comment.