Skip to content

Commit

Permalink
Merge pull request #2655 from QuizandSurveyMaster/CU-85ztnrg6g-link-m…
Browse files Browse the repository at this point in the history
…ultiple-questions

Cu 85ztnrg6g link multiple questions
  • Loading branch information
zubairraeen authored Oct 4, 2024
2 parents a5eb742 + 705193b commit d752d13
Show file tree
Hide file tree
Showing 8 changed files with 524 additions and 56 deletions.
4 changes: 2 additions & 2 deletions css/qsm-admin-question.css
Original file line number Diff line number Diff line change
Expand Up @@ -453,11 +453,11 @@ input#image_size-width {
.change-answer-editor-label>#change-answer-editor {
width: auto;
}
a.import-button.button.disable_import {
a.import-button.button.disable_import, a.link-question.button.disable_import {
position: relative;
z-index: 0;
}
a.import-button.button.disable_import::before {
a.import-button.button.disable_import::before, a.link-question.button.disable_import::before {
content: '';
background: rgba(255, 255, 255, 0.5);
width: 100%;
Expand Down
87 changes: 87 additions & 0 deletions css/qsm-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,93 @@ td.scheduled_time_start {
background: #fff;
box-sizing: border-box;
}

#post-body-content .qsm-popup-upgrade-warning img {
width: auto;
height: 15px;
margin-right: 8px;
}

.qsm-linked-list-div-block {
padding: 4px;
margin: 5px 0;
margin-top: -20px;
width: max-content;
background-color: #ffe684;
border-radius: 2px;
}

span.qsm-linked-list-view-button {
cursor: pointer;
color: #135e96;
text-decoration: underline;
font-weight: 500;
}

span.qsm-linked-list-item {
margin: 0 0 5px 0;
padding: 5px;
background: #f0f0f1;
}

div.qsm-linked-list-inside span.qsm-unlink-the-question {
color: #DC3232;
font-weight: 500;
max-width: 60px;
cursor: pointer;
}

.qsm-linked-list-div-block p {
margin: 0;
font-size: 13px;
color: #856404;
}

.qsm-linked-list-container {
position: absolute;
}

.qsm-linked-list-div-block .qsm-linked-list-inside {
position: relative;
right: -155px;
top: 20px;
z-index: 999;
width: 350px;
padding: 10px;
box-sizing: border-box;
border-radius: 4px;
background: #ffffff;
border: 1px solid #dfd4d4;
box-shadow: 0 0 6px 2px #ddd;
display: grid;
grid-template-columns: 1fr;
}

.qsm-linked-list-div-block .qsm-linked-list-inside:before {
content: " ";
position: absolute;
top: -24px;
left: 28%;
margin-left: -12px;
border-width: 12px;
border-style: solid;
border-color: transparent transparent #ffffff transparent;
z-index: 1;
}

.qsm-linked-list-div-block .qsm-linked-list-inside:after {
content: " ";
position: absolute;
top: -26px;
left: 28%;
margin-left: -12px;
border-width: 12px;
border-style: solid;
border-color: transparent transparent #dfd4d4 transparent;
z-index: 0;
}


.qsm-text-main-wrap #postbox-container-1 {
position: relative;
background: #fff;
Expand Down
91 changes: 83 additions & 8 deletions js/qsm-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -1899,6 +1899,7 @@ var QSMContact;
*/
var QSMQuestion;
var import_button;
var qsm_link_button;
(function ($) {
if (jQuery('body').hasClass('admin_page_mlw_quiz_options')) {
if (window.location.href.indexOf('&tab') == -1 || window.location.href.indexOf('tab=questions') > 0) {
Expand Down Expand Up @@ -2041,19 +2042,22 @@ var import_button;
type: question.type,
question: questionText,
category: question.category,
quiz_name: question.quiz_name
quiz_name: question.quiz_name,
linked_question: question.linked_question.join(',')
}));
},
addQuestionFromQuestionBank: function (questionID) {
addQuestionFromQuestionBank: function (questionID, is_linking = 0) {
QSMAdmin.displayAlert(qsm_admin_messages.adding_question, 'info');
let isLinkingData = is_linking == 1 ? questionID : 0;
var model = new QSMQuestion.question({
id: questionID
id: questionID,
is_linking: isLinkingData
});
model.fetch({
headers: {
'X-WP-Nonce': qsmQuestionSettings.nonce
},
url: wpApiSettings.root + 'quiz-survey-master/v1/questions/' + questionID,
url: wpApiSettings.root + 'quiz-survey-master/v1/questions/' + questionID + '?is_linking=' + isLinkingData,
success: QSMQuestion.questionBankSuccess,
error: QSMAdmin.displayError
});
Expand Down Expand Up @@ -2240,11 +2244,23 @@ var import_button;
QSMQuestion.addQuestionToPage(model);
QSMQuestion.savePages();

$('.import-button').removeClass('disable_import');
$('.import-button, .link-question').removeClass('disable_import');
QSMQuestion.countTotal();
import_button.html('').html(qsm_admin_messages.add_question);
import_button.attr("onclick", "return confirm(" + qsm_admin_messages.confirm_message + "' '" + qsm_admin_messages.import_question_again + ")");
if(import_button){
import_button.html(qsm_admin_messages.add_question);
}
if(qsm_link_button) {
qsm_link_button.html(qsm_admin_messages.link_question);
}
if(import_button){
import_button.attr("onclick", "return confirm('" + qsm_admin_messages.confirm_message + " " + qsm_admin_messages.import_question_again + "');");
}
QSMQuestion.openEditPopup(model.id, $('.question[data-question-id=' + model.id + ']').find('.edit-question-button'));
console.log(qsm_link_button);
if(qsm_link_button == ''){
$(document).find('.qsm-linked-list-inside').hide().empty();
$(document).find('.qsm-linked-list-div-block').hide();
}
// $('#save-popup-button').trigger('click');
},
addNewQuestion: function (model) {
Expand Down Expand Up @@ -2780,6 +2796,31 @@ var import_button;
$('#image_size_area').show();
}

let link_quizzes_array = question.get('link_quizzes');

$('.qsm-linked-list-inside').hide().empty();
$('.qsm-linked-list-div-block').hide();
if (typeof link_quizzes_array == 'object' && link_quizzes_array != null && Object.keys(link_quizzes_array).length > 0) {
Object.values(link_quizzes_array).forEach(function(quizName) {
// Ensure each quizName is a valid non-empty string
if (quizName && typeof quizName == 'string' && quizName.trim().length > 0) {
let link = $('<span></span>')
.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')
.attr('data-question-id', questionID)
.text(qsm_admin_messages.unlink_question);
$('.qsm-linked-list-inside').append(unlink);
}
jQuery(document).trigger('qsm_open_edit_popup', [questionID, CurrentElement]);
},
openEditPagePopup: function (pageID) {
Expand Down Expand Up @@ -3256,16 +3297,50 @@ var import_button;

$(document).on('click', '.qsm-popup-bank .import-button', function (event) {
event.preventDefault();
$(this).text('').text(qsm_admin_messages.adding_question);
qsm_link_button = '';
$(this).text(qsm_admin_messages.adding_question);
import_button = $(this);
$('.import-button').addClass('disable_import');
QSMQuestion.addQuestionFromQuestionBank($(this).data('question-id'));
MicroModal.close('modal-2');
});


$(document).on('click', '.qsm-popup-bank .link-question', function (event) {
event.preventDefault();
$(this).text(qsm_admin_messages.linking_question);
qsm_link_button = $(this);
$('.link-question').addClass('disable_import');
// 1 for the linking the questions default is 0
QSMQuestion.addQuestionFromQuestionBank($(this).data('question-id'), 1);
MicroModal.close('modal-2');
});

jQuery(document).on('click', '.qsm-linked-list-div-block .qsm-linked-list-view-button', function () {
let $this = jQuery(this);
let $inside = $this.parents('.qsm-linked-list-div-block').find('.qsm-linked-list-inside');
$inside.toggle();
$inside.is(':visible') ? $this.text(qsmQuestionSettings.linked_close) : $this.text(qsmQuestionSettings.linked_view);
});

jQuery(document).on('click', '.qsm-linked-list-div-block .qsm-unlink-the-question', function () {
$.ajax({
url: ajaxurl,
method: 'POST',
data: {
action: 'qsm_unlink_question_from_list',
question_id: jQuery(this).data('question-id'),
nonce: qsmQuestionSettings.unlinkNonce
},
success: function (response) {
$(document).find('.qsm-linked-list-div-block').remove();
}
});
});
//Click on selected question button.
$('.qsm-popup-bank').on('click', '#qsm-import-selected-question', function (event) {
var $total_selction = $('#question-bank').find('[name="qsm-question-checkbox[]"]:checked').length;
qsm_link_button = '';
if ($total_selction === 0) {
alert(qsm_admin_messages.no_question_selected);
} else {
Expand Down
7 changes: 5 additions & 2 deletions mlw_quizmaster2.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,13 @@ public function qsm_admin_scripts_style( $hook ) {
'results_page_saved' => __('Results pages were saved!', 'quiz-master-next'),
'results_page_save_error' => __('There was an error when saving the results pages.', 'quiz-master-next'),
'all_categories' => __('All Categories', 'quiz-master-next'),
'add_question' => __('Add Question', 'quiz-master-next'),
'add_question' => __('Add', 'quiz-master-next'),
'question_created' => __('Question created!', 'quiz-master-next'),
'new_question' => __('Your new question!', 'quiz-master-next'),
'adding_question' => __('Adding question...', 'quiz-master-next'),
'unlink_question' => __('Unlink', 'quiz-master-next'),
'adding_question' => __('Adding...', 'quiz-master-next'),
'linking_question' => __('Linking...', 'quiz-master-next'),
'link_question' => __('Link', 'quiz-master-next'),
'creating_question' => __('Creating question...', 'quiz-master-next'),
'duplicating_question' => __('Duplicating question...', 'quiz-master-next'),
'saving_question' => __('Saving question...', 'quiz-master-next'),
Expand Down
Loading

0 comments on commit d752d13

Please sign in to comment.