Skip to content

Commit

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

Fixed issue with importing quetoins
  • Loading branch information
zubairraeen authored Oct 7, 2024
2 parents 8c92590 + 6c727e7 commit 55e522b
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 510 deletions.
85 changes: 0 additions & 85 deletions css/qsm-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -1459,91 +1459,6 @@ td.scheduled_time_start {
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;
Expand Down
79 changes: 4 additions & 75 deletions js/qsm-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -1899,7 +1899,6 @@ 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 @@ -2042,22 +2041,19 @@ var qsm_link_button;
type: question.type,
question: questionText,
category: question.category,
quiz_name: question.quiz_name,
linked_question: question.linked_question.join(',')
quiz_name: question.quiz_name
}));
},
addQuestionFromQuestionBank: function (questionID, is_linking = 0) {
addQuestionFromQuestionBank: function (questionID) {
QSMAdmin.displayAlert(qsm_admin_messages.adding_question, 'info');
let isLinkingData = is_linking == 1 ? questionID : 0;
var model = new QSMQuestion.question({
id: questionID,
is_linking: isLinkingData
id: questionID
});
model.fetch({
headers: {
'X-WP-Nonce': qsmQuestionSettings.nonce
},
url: wpApiSettings.root + 'quiz-survey-master/v1/questions/' + questionID + '?is_linking=' + isLinkingData,
url: wpApiSettings.root + 'quiz-survey-master/v1/questions/' + questionID,
success: QSMQuestion.questionBankSuccess,
error: QSMAdmin.displayError
});
Expand Down Expand Up @@ -2249,18 +2245,10 @@ var qsm_link_button;
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 @@ -2796,31 +2784,6 @@ var qsm_link_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 @@ -3297,50 +3260,16 @@ var qsm_link_button;

$(document).on('click', '.qsm-popup-bank .import-button', function (event) {
event.preventDefault();
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
5 changes: 0 additions & 5 deletions mlw_quizmaster2.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,13 +525,8 @@ 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', 'quiz-master-next'),
'question_created' => __('Question created!', 'quiz-master-next'),
'new_question' => __('Your new 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 55e522b

Please sign in to comment.