Skip to content

Commit

Permalink
Merge pull request #2545 from QuizandSurveyMaster/db-permission-notif…
Browse files Browse the repository at this point in the history
…ication-retrieve-submission

Ajax, add date and ip column in failed submission admin dashboard table
  • Loading branch information
randhirexpresstech authored May 20, 2024
2 parents 53ccac8 + 861394b commit f84fb23
Show file tree
Hide file tree
Showing 4 changed files with 465 additions and 134 deletions.
8 changes: 8 additions & 0 deletions css/qsm-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -3436,4 +3436,12 @@ input#preferred-date-format-custom {
min-width: 520px;
background: #cccccc36;
border: 1px solid #ccc;
}

.qsm-pointer-events-none {
pointer-events: none;
}

.display-none-notice {
display: none;
}
119 changes: 119 additions & 0 deletions js/qsm-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3957,3 +3957,122 @@ var import_button;
qsmHandleOperatorChange('email-condition', 'condition-default-value');

}(jQuery));


/**
* QSM - failed submission data table action
*/
(function ($) {
function submit_failed_submission_action_notice( res ) {
if ( 'object' !== typeof res || null === res || undefined === res.message ) {
return false;
}
let noticeEl = $( '#qmn-failed-submission-table-message' );
if ( 0 < noticeEl.length ) {
let remove_notice_type_class = 'success' === res.status ? 'notice-error' : 'notice-success';
noticeEl.removeClass( remove_notice_type_class );
noticeEl.addClass( 'notice-'+res.status );
noticeEl.html(
'<p>'+res.message+'</p>'
);
noticeEl.show();
noticeEl.fadeOut( 9999 );
}
}

function submit_failed_submission_action_form( formData, ) {

// check for required data
if ( undefined === formData || null === formData || -1 == formData.quiz_action || 0 === formData.post_ids.length ) {
submit_failed_submission_action_notice( {
status:"error",
message:"Missing form action or data"
} );
return false;
}

// quiz action
formData.action = 'qsm_action_failed_submission_table';

// Disable conatiner for further any action
let containerDiv = $("#qmn-failed-submission-conatiner");
containerDiv.toggleClass('qsm-pointer-events-none');

// Actiion one by one
formData.post_ids.forEach( post_id => {
formData.post_id = post_id;
let action_link_wrap = $( '#action-link-'+post_id );
let action_link_html = action_link_wrap.html();
action_link_wrap.html( 'processing...');
$.ajax({
type: 'POST',
url: ajaxurl,
data: formData,
success: function (response) {
// notice.
submit_failed_submission_action_notice( response.data );

// enable click pointer
containerDiv.removeClass('qsm-pointer-events-none');

// add success icon
if ( response.success ) {
action_link_wrap.html( '<span class="dashicons dashicons-yes-alt"></span>' );
} else {
action_link_wrap.html( action_link_html );
}

// Remove row if trashed
if ( 'trash' === formData.quiz_action ) {
$( '#qsm-submission-row-'+post_id ).remove();
}

},
error: function ( jqXHR, textStatus, errorThrown ) {
// undo action link
action_link_wrap.html( action_link_html );

// enable click pointer
containerDiv.removeClass('qsm-pointer-events-none');

// error notice
submit_failed_submission_action_notice( {
status:"error",
message:errorThrown
} );
}
});
});

}

// Submit Form.
$( document ).on( 'submit', '#failed-submission-action-form', function( e ) {
e.preventDefault();
let formData = {
qmnnonce: $('#failed-submission-action-form input[name="qmnnonce"]').val(),
post_ids: [],
quiz_action: $('#failed-submission-action-form #bulk-action-selector-top').val()
};
// Select all checkboxes with the name attribute 'post_id[]'
let checkedCheckboxes = $('#failed-submission-action-form input[type="checkbox"][name="post_id[]"]:checked');

// Iterate over each checked checkbox
checkedCheckboxes.each(function() {
formData.post_ids.push( $(this).val() );
});

submit_failed_submission_action_form( formData );
} );

// On click retrieve link
$( document ).on( 'click', '.qmn-retrieve-failed-submission-link', function( e ) {
e.preventDefault();

submit_failed_submission_action_form( {
qmnnonce: $('#failed-submission-action-form input[name="qmnnonce"]').val(),
post_ids: [ $(this).attr('post-id') ],
quiz_action:'retrieve'
} );
} );
}(jQuery));
Loading

0 comments on commit f84fb23

Please sign in to comment.