admin.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*!
  2. * Studiou WC Mail Queue — admin script
  3. *
  4. * Copyright (C) 2026 QUADARAX. All rights reserved.
  5. * Author: Dalibor Votruba <dvotruba@quadarax.com>
  6. * License: GPL-2.0-or-later
  7. */
  8. ( function ( $ ) {
  9. 'use strict';
  10. console.log( 'STUDIOU WC MAIL: Admin script loaded v1.0.0' );
  11. function safeInit( name, fn ) {
  12. try {
  13. fn();
  14. } catch ( e ) {
  15. console.error( 'STUDIOU WC MAIL: init failed for ' + name, e );
  16. }
  17. }
  18. $( function () {
  19. safeInit( 'checkAll', function () {
  20. $( '#studiou-wcmq-check-all' ).on( 'change', function () {
  21. $( '.studiou-wcmq-queue-form input[name="rows[]"]' ).prop( 'checked', this.checked );
  22. } );
  23. } );
  24. safeInit( 'bulkConfirm', function () {
  25. $( '.studiou-wcmq-queue-form' ).on( 'submit', function ( e ) {
  26. var action = $( this ).find( 'select[name="wcmq_action"]' ).val();
  27. var checked = $( this ).find( 'input[name="rows[]"]:checked' ).length;
  28. if ( ! action || ! checked ) {
  29. e.preventDefault();
  30. return;
  31. }
  32. if ( 'delete' === action && ! window.confirm( studiouWcmq.confirmDelete ) ) {
  33. e.preventDefault();
  34. return;
  35. }
  36. // Retry re-delivers mail. It is destructive in the way that matters.
  37. if ( 'retry' === action && ! window.confirm( studiouWcmq.confirmRetry ) ) {
  38. e.preventDefault();
  39. }
  40. } );
  41. } );
  42. safeInit( 'clearLogConfirm', function () {
  43. $( '.studiou-wcmq-clear-log-form' ).on( 'submit', function ( e ) {
  44. if ( ! window.confirm( studiouWcmq.confirmClearLog ) ) {
  45. e.preventDefault();
  46. }
  47. } );
  48. } );
  49. } );
  50. }( jQuery ) );