Skip to content

Commit

Permalink
Merge pull request #2434 from QuizandSurveyMaster/CU-867973bnm-bulk-d…
Browse files Browse the repository at this point in the history
…elete-questions

added option to delete bult question
  • Loading branch information
zubairraeen authored Jan 2, 2024
2 parents fffa0ca + 13b54b1 commit 9a53825
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 85 deletions.
22 changes: 16 additions & 6 deletions css/qsm-admin-question.css
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,14 @@
.page-header-buttons {
text-align: right;
}
.question, .question-bank-question {
.qsm-question-container, .question-bank-question {
box-sizing: border-box;
background: #ffffff;
border: 1px solid #dfd4d4;
border-radius: 3px;
padding: 6px 5px;
margin: 10px 20px 0;
margin: 10px 20px 0 35px;
position: relative;
}
.question a {
text-decoration: none;
Expand Down Expand Up @@ -175,7 +176,7 @@
color: #1f8cbe;
font-size: 16px;
font-weight: 500;
margin: 2px 0 2px 30px;
margin: 2px 0;
}
.question-content .form-actions {
display: inline-flex;
Expand All @@ -192,11 +193,12 @@
color: #939697;
font-weight: normal;
font-style: italic;
margin: 3px 0 3px 30px;
margin: 3px 0;
}
.qsm-admin-select-question-input {
position: absolute;
top: calc(50% - 3px);
left: -25px;
visibility: hidden;
}
.question:hover .qsm-admin-select-question-input,
Expand Down Expand Up @@ -481,7 +483,7 @@ a.import-button.button.disable_import::before {
padding: 15px 10px;
background-color: #fafafa;
border: 1px solid #cbcbcb;
margin: 0 20px 0;
margin: 0 20px 0 35px;
box-sizing: border-box;
border-top: medium none;
}
Expand Down Expand Up @@ -631,11 +633,19 @@ a#qsm-category-add-toggle {
}
.qsm-admin-bulk-actions{
margin-top: 10px;
text-align: right;
display: none;
}
input.qsm-admin-select-page-question {
margin-left: 74px;
margin-left: 10px;
margin-right: 10px;
display: inline-block;
}
.qsm-admin-select-page-question-label{
color: #a6abaf;
font-size: 16px;
display: none;
}
@media (min-width: 783px) and (max-width: 1199px) {
#poststuff #post-body.columns-2 #side-sortables {
min-width: unset;
Expand Down
4 changes: 3 additions & 1 deletion css/qsm-admin-rtl.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@
.overview-main-wrapper .overview-inner-wrap {margin-left: 2%;margin-right: 0;}
div.qsm_icon_wrap{left:0;right:auto;}
.text-right{text-align: left !important;}
.text-left{text-align: right !important;}
.text-left{text-align: right !important;}
.wp-core-ui .button-danger { color: #DC3232; border-color: #DC3232; }
.wp-core-ui .button-danger:hover { color: #ca1010; border-color: #ca1010; }
7 changes: 7 additions & 0 deletions css/qsm-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -3301,4 +3301,11 @@ input#preferred-date-format-custom {
.qsm-date-time-text {
min-width: 110px;
display: inline-block;
}
.wp-core-ui .button-danger {
color: #DC3232;
border-color: #DC3232;
}
.wp-core-ui .button-danger:hover {
color: #ca1010; border-color: #ca1010;
}
157 changes: 106 additions & 51 deletions js/qsm-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2739,51 +2739,33 @@ var import_button;
$('#delete-question-button').attr('data-question-iid', $(this).data('question-iid'));
});
// removes question from database
$('#delete-question-button').click(function (event) {
event.preventDefault();
var question_id = $(this).data('question-iid');
$.ajax({
url: ajaxurl,
method: 'POST',
data: {
'action': 'qsm_delete_question_from_database',
'question_id': question_id,
'nonce': qsmQuestionSettings.single_question_nonce
},
success: function (response) {
if (response.success) {
remove.parents('.question').remove();
QSMQuestion.countTotal();
$('.save-page-button').trigger('click');
} else {
QSMAdmin.displayAlert(response.data, 'error');
}
$(document).on('click', '.qsm-delete-question-button-btn', function () {
let question_id = $(this).attr('data-question-iid');
let checkedValues = "";
if ("selected-questions" == question_id || "all-questions" == question_id) {
if ("all-questions" == question_id) {
checkedValues = $('.qsm-admin-select-question-input')
.map(function () {
return $(this).val();
})
.get();
} else {
checkedValues = $('.qsm-admin-select-question-input:checked')
.map(function () {
return $(this).val();
})
.get();
}
let question_ids = checkedValues.join(',');
if (question_ids == undefined || question_ids == null || question_ids == '') {
return;
}
});
MicroModal.close('modal-7');
});
// removes bulk question from database
$(document).on('click', '#qsm-bulk-delete-question-submit', function (event) {
event.preventDefault();
jQuery('#qsm-bulk-delete-question-submit').attr('disabled', true);
let bulk_action = $("#bulk-delete-question-selector").val();
let checkedValues = $('.qsm-admin-select-question-input:checked')
.map(function () {
return $(this).val();
})
.get()
let question_id = checkedValues.join(',');
if (question_id == undefined || question_id == null || question_id == '') {
jQuery('#qsm-bulk-delete-question-submit').attr('disabled', false);
return;
}
if ('delete' === bulk_action) {
$.ajax({
url: ajaxurl,
method: 'POST',
data: {
'action': 'qsm_bulk_delete_question_from_database',
'question_id': question_id,
'question_id': question_ids,
'nonce': qsmQuestionSettings.single_question_nonce
},
success: function (response) {
Expand All @@ -2797,17 +2779,44 @@ var import_button;
} else {
QSMAdmin.displayAlert(response.data, 'error');
}
jQuery('#qsm-bulk-delete-question-submit').attr('disabled', false);
jQuery('.qsm-admin-bulk-actions').fadeOut();
}
});
}else if ('unlink' === bulk_action) {
checkedValues.forEach(function (questionId) {
$('.question[data-question-id="' + questionId + '"]').remove();
} else {
$.ajax({
url: ajaxurl,
method: 'POST',
data: {
'action': 'qsm_delete_question_from_database',
'question_id': question_id,
'nonce': qsmQuestionSettings.single_question_nonce
},
success: function (response) {
if (response.success) {
remove.parents('.question').remove();
QSMQuestion.countTotal();
$('.save-page-button').trigger('click');
} else {
QSMAdmin.displayAlert(response.data, 'error');
}
}
});
jQuery('.qsm-admin-select-page-question').prop('checked',false);
QSMQuestion.countTotal();
$('.save-page-button').trigger('click');
}
MicroModal.close('modal-7');
});
// delete bulk question from database
$(document).on('click', '#qsm-bulk-delete-question', function (event) {
event.preventDefault();
MicroModal.show('modal-7');
$('#unlink-question-button').attr('data-question-iid', 'selected-questions');
$('#delete-question-button').attr('data-question-iid', 'selected-questions');
});
// remove bulk question from quiz
$(document).on('click', '#qsm-bulk-delete-all-question', function (event) {
event.preventDefault();
MicroModal.show('modal-7');
$('#unlink-question-button').attr('data-question-iid', 'all-questions');
$('#delete-question-button').attr('data-question-iid', 'all-questions');
});

$(document).on('click', '.qsm-admin-select-page-question', function () {
Expand All @@ -2820,6 +2829,13 @@ var import_button;
let allCheckboxesChecked = checkboxesToToggle.length === checkboxesToToggle.filter(':checked').length;
$('.qsm-admin-select-page-question').prop('checked', allCheckboxesChecked);
}
let count = jQuery('.qsm-admin-select-question-input:checked').length;
jQuery('.qsm-selected-question-count').html(count);
if (count) {
jQuery('.qsm-admin-bulk-actions').fadeIn();
} else {
jQuery('.qsm-admin-bulk-actions').fadeOut();
}
});

$(document).on('click', '.qsm-admin-select-question-input', function () {
Expand All @@ -2829,15 +2845,54 @@ var import_button;
let allCheckboxesChecked = $(this).closest('.page').find('.qsm-admin-select-question-input:checked').length === $(this).closest('.page').find('.qsm-admin-select-question-input').length;
$(this).closest('.page').find('.qsm-admin-select-page-question').prop('checked', allCheckboxesChecked);
}
if ( $(this).closest('.page').find('.qsm-admin-select-question-input:checked').length ) {
$(this).closest('.page').find('.qsm-admin-select-page-question-label').fadeIn();
} else {
$(this).closest('.page').find('.qsm-admin-select-page-question-label').fadeOut();
}
let count = jQuery('.qsm-admin-select-question-input:checked').length;
jQuery('.qsm-selected-question-count').html(count);
if (count) {
jQuery('.qsm-admin-bulk-actions').fadeIn();
} else {
jQuery('.qsm-admin-bulk-actions').fadeOut();
}
});

// unlink question from a particular quiz.
$('#unlink-question-button').click(function (event) {
$(document).on('click', '.qsm-unlink-question-button-btn', function (event) {
event.preventDefault();
var question_id = $(this).data('question-iid');
remove.parents('.question').remove();
QSMQuestion.countTotal();
$('.save-page-button').trigger('click');
let question_id = $(this).attr('data-question-iid');
let checkedValues = "";
if ("selected-questions" == question_id || "all-questions" == question_id) {
if ("all-questions" == question_id) {
checkedValues = $('.qsm-admin-select-question-input')
.map(function () {
return $(this).val();
})
.get();
} else {
checkedValues = $('.qsm-admin-select-question-input:checked')
.map(function () {
return $(this).val();
})
.get();
}
let question_ids = checkedValues.join(',');
if (undefined != question_ids && null != question_ids && '' != question_ids) {
checkedValues.forEach(function (questionId) {
$('.question[data-question-id="' + questionId + '"]').remove();
});
QSMQuestion.countTotal();
$('.save-page-button').trigger('click');
jQuery('.qsm-admin-bulk-actions').fadeOut();
jQuery('.qsm-admin-select-page-question').prop('checked',false);
}
} else {
remove.parents('.question').remove();
QSMQuestion.countTotal();
$('.save-page-button').trigger('click');
}
MicroModal.close('modal-7');
});

Expand Down
Loading

0 comments on commit 9a53825

Please sign in to comment.