From 9ad322cfb1a20da8e2e82a8276d86228d9041d0f Mon Sep 17 00:00:00 2001 From: Paulo Pinto Date: Thu, 15 Feb 2024 14:05:27 +0000 Subject: [PATCH 01/22] Lint my events template --- templates/events-user-created.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/events-user-created.php b/templates/events-user-created.php index fbf83e89..c945d322 100644 --- a/templates/events-user-created.php +++ b/templates/events-user-created.php @@ -31,7 +31,7 @@ -

+

From 8c8d0efea8117d37b572c963f33784e821ab4ab3 Mon Sep 17 00:00:00 2001 From: Paulo Pinto Date: Thu, 15 Feb 2024 15:29:08 +0000 Subject: [PATCH 02/22] Lint js --- phpcs.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phpcs.xml b/phpcs.xml index f4a862c2..abcbcddc 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -3,8 +3,9 @@ Coding standards - + + ./assets/ ./includes/ ./templates/ ./tests/ From b7f64a62415b5e0a7eda219acd5d8106f439e21c Mon Sep 17 00:00:00 2001 From: Paulo Pinto Date: Thu, 15 Feb 2024 15:32:40 +0000 Subject: [PATCH 03/22] Indent with tabs --- assets/js/translation-events.js | 196 ++++++++++++++++---------------- 1 file changed, 98 insertions(+), 98 deletions(-) diff --git a/assets/js/translation-events.js b/assets/js/translation-events.js index 28b7bd4b..dcb2281f 100644 --- a/assets/js/translation-events.js +++ b/assets/js/translation-events.js @@ -1,113 +1,113 @@ ( function( $, $gp ) { jQuery(document).ready(function($) { - $gp.notices.init(); - if ( $('#event-timezone').length && ! $('#event-timezone').val() ) { - selectUserTimezone(); - } - validateEventDates(); - convertToUserLocalTime(); + $gp.notices.init(); + if ( $('#event-timezone').length && ! $('#event-timezone').val() ) { + selectUserTimezone(); + } + validateEventDates(); + convertToUserLocalTime(); - $('.submit-event').on('click', function(e) { - e.preventDefault(); - if ( $('#event-end').val() <= $('#event-start').val() ) { - $gp.notices.error( 'Event end date and time must be later than event start date and time.' ); - return; - } - var btnClicked = $(this).data('event-status'); - if ( btnClicked == 'publish' && '' == $('#event-id').val() ) { - var submitPrompt = 'Are you sure you want to publish this event?'; - if ( ! confirm( submitPrompt ) ) { - return; - } - } - $('#event-form-action').val( btnClicked ); - var $form = $('.translation-event-form'); - var $is_creation = $('#form-name').val() == 'create_event' ? true : false; - - $.ajax({ - type: 'POST', - url: $translation_event.url, - data:$form.serialize(), - success: function(response) { - if ( response.data.eventId ) { - history.replaceState('','', response.data.eventEditUrl) - $('#form-name').val('edit_event'); - $('.event-page-title').text('Edit Event'); - $('#event-id').val(response.data.eventId); - if( btnClicked == 'publish' ) { - $('button[data-event-status="draft"]').hide(); - $('button[data-event-status="publish"]').text('Update Event'); - } - if( btnClicked == 'draft' ) { - $('button[data-event-status="draft"]').text('Update Draft'); - } - $('#event-url').removeClass('hide-event-url').find('a').attr('href', response.data.eventUrl).text(response.data.eventUrl); - if ( $is_creation ) { - $('#delete-button').toggle(); - } - $gp.notices.success(response.data.message); - } - }, - error: function(error) { - $gp.notices.error(response.data.message); - } - }); - }); - - $('.delete-event').on('click', function(e) { - e.preventDefault(); - if ( ! confirm( 'Are you sure you want to delete this event?' ) ) { + $('.submit-event').on('click', function(e) { + e.preventDefault(); + if ( $('#event-end').val() <= $('#event-start').val() ) { + $gp.notices.error( 'Event end date and time must be later than event start date and time.' ); + return; + } + var btnClicked = $(this).data('event-status'); + if ( btnClicked == 'publish' && '' == $('#event-id').val() ) { + var submitPrompt = 'Are you sure you want to publish this event?'; + if ( ! confirm( submitPrompt ) ) { return; } - var $form = $('.translation-event-form'); - $('#form-name').val('delete_event'); - $('#event-form-action').val( 'delete' ); - $.ajax({ - type: 'POST', - url: $translation_event.url, - data:$form.serialize(), - success: function(response) { + } + $('#event-form-action').val( btnClicked ); + var $form = $('.translation-event-form'); + var $is_creation = $('#form-name').val() == 'create_event' ? true : false; + + $.ajax({ + type: 'POST', + url: $translation_event.url, + data:$form.serialize(), + success: function(response) { + if ( response.data.eventId ) { + history.replaceState('','', response.data.eventEditUrl) + $('#form-name').val('edit_event'); + $('.event-page-title').text('Edit Event'); + $('#event-id').val(response.data.eventId); + if( btnClicked == 'publish' ) { + $('button[data-event-status="draft"]').hide(); + $('button[data-event-status="publish"]').text('Update Event'); + } + if( btnClicked == 'draft' ) { + $('button[data-event-status="draft"]').text('Update Draft'); + } + $('#event-url').removeClass('hide-event-url').find('a').attr('href', response.data.eventUrl).text(response.data.eventUrl); + if ( $is_creation ) { + $('#delete-button').toggle(); + } + $gp.notices.success(response.data.message); + } + }, + error: function(error) { + $gp.notices.error(response.data.message); + } + }); + }); + + $('.delete-event').on('click', function(e) { + e.preventDefault(); + if ( ! confirm( 'Are you sure you want to delete this event?' ) ) { + return; + } + var $form = $('.translation-event-form'); + $('#form-name').val('delete_event'); + $('#event-form-action').val('delete'); + $.ajax({ + type: 'POST', + url: $translation_event.url, + data:$form.serialize(), + success: function(response) { window.location = response.data.eventDeleteUrl; - }, - error: function(error) { - $gp.notices.error(response.data.message); - }, - }); + }, + error: function(error) { + $gp.notices.error(response.data.message); + }, }); + }); function validateEventDates() { - var startDateTimeInput = $('#event-start'); - var endDateTimeInput = $('#event-end'); - if ( ! startDateTimeInput.length || ! endDateTimeInput.length ) { - return; - } + var startDateTimeInput = $('#event-start'); + var endDateTimeInput = $('#event-end'); + if ( ! startDateTimeInput.length || ! endDateTimeInput.length ) { + return; + } - startDateTimeInput.add(endDateTimeInput).on('input', function () { - endDateTimeInput.prop('min', startDateTimeInput.val()); - if (endDateTimeInput.val() < startDateTimeInput.val()) { - endDateTimeInput.val(startDateTimeInput.val()); - } - }); - } - function selectUserTimezone() { - document.querySelector(`#event-timezone option[value="${Intl.DateTimeFormat().resolvedOptions().timeZone}"]`).selected = true - } + startDateTimeInput.add(endDateTimeInput).on('input', function () { + endDateTimeInput.prop('min', startDateTimeInput.val()); + if (endDateTimeInput.val() < startDateTimeInput.val()) { + endDateTimeInput.val(startDateTimeInput.val()); + } + }); + } + function selectUserTimezone() { + document.querySelector(`#event-timezone option[value="${Intl.DateTimeFormat().resolvedOptions().timeZone}"]`).selected = true + } - function convertToUserLocalTime() { - var timeElements = document.querySelectorAll('time.event-utc-time'); - if ( timeElements.length === 0 ) { - return; - } - timeElements.forEach(function(timeEl) { - var eventDateObj = new Date( timeEl.getAttribute('datetime') ); - var userTimezoneOffset = new Date().getTimezoneOffset(); - var userTimezoneOffsetMs = userTimezoneOffset * 60 * 1000; - var userLocalDateTime = new Date(eventDateObj.getTime() - userTimezoneOffsetMs); + function convertToUserLocalTime() { + var timeElements = document.querySelectorAll('time.event-utc-time'); + if ( timeElements.length === 0 ) { + return; + } + timeElements.forEach(function(timeEl) { + var eventDateObj = new Date( timeEl.getAttribute('datetime') ); + var userTimezoneOffset = new Date().getTimezoneOffset(); + var userTimezoneOffsetMs = userTimezoneOffset * 60 * 1000; + var userLocalDateTime = new Date(eventDateObj.getTime() - userTimezoneOffsetMs); - var options = { weekday: 'short', year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric', hour12: true, timeZoneName: 'short' }; + var options = { weekday: 'short', year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric', hour12: true, timeZoneName: 'short' }; - timeEl.textContent = userLocalDateTime.toLocaleString('en-US', options); - }); - } + timeEl.textContent = userLocalDateTime.toLocaleString('en-US', options); + }); + } }); }( jQuery, $gp ) From 2bf46d27e26e5139efbfd784a977f53fff5e4055 Mon Sep 17 00:00:00 2001 From: Paulo Pinto Date: Thu, 15 Feb 2024 15:34:13 +0000 Subject: [PATCH 04/22] Indent one level up --- assets/js/translation-events.js | 192 ++++++++++++++++---------------- 1 file changed, 96 insertions(+), 96 deletions(-) diff --git a/assets/js/translation-events.js b/assets/js/translation-events.js index dcb2281f..e7b4e374 100644 --- a/assets/js/translation-events.js +++ b/assets/js/translation-events.js @@ -1,114 +1,114 @@ ( function( $, $gp ) { -jQuery(document).ready(function($) { - $gp.notices.init(); - if ( $('#event-timezone').length && ! $('#event-timezone').val() ) { - selectUserTimezone(); - } - validateEventDates(); - convertToUserLocalTime(); - - $('.submit-event').on('click', function(e) { - e.preventDefault(); - if ( $('#event-end').val() <= $('#event-start').val() ) { - $gp.notices.error( 'Event end date and time must be later than event start date and time.' ); - return; + jQuery(document).ready(function($) { + $gp.notices.init(); + if ( $('#event-timezone').length && ! $('#event-timezone').val() ) { + selectUserTimezone(); } - var btnClicked = $(this).data('event-status'); - if ( btnClicked == 'publish' && '' == $('#event-id').val() ) { - var submitPrompt = 'Are you sure you want to publish this event?'; - if ( ! confirm( submitPrompt ) ) { + validateEventDates(); + convertToUserLocalTime(); + + $('.submit-event').on('click', function(e) { + e.preventDefault(); + if ( $('#event-end').val() <= $('#event-start').val() ) { + $gp.notices.error( 'Event end date and time must be later than event start date and time.' ); return; } - } - $('#event-form-action').val( btnClicked ); - var $form = $('.translation-event-form'); - var $is_creation = $('#form-name').val() == 'create_event' ? true : false; + var btnClicked = $(this).data('event-status'); + if ( btnClicked == 'publish' && '' == $('#event-id').val() ) { + var submitPrompt = 'Are you sure you want to publish this event?'; + if ( ! confirm( submitPrompt ) ) { + return; + } + } + $('#event-form-action').val( btnClicked ); + var $form = $('.translation-event-form'); + var $is_creation = $('#form-name').val() == 'create_event' ? true : false; - $.ajax({ - type: 'POST', - url: $translation_event.url, - data:$form.serialize(), - success: function(response) { - if ( response.data.eventId ) { - history.replaceState('','', response.data.eventEditUrl) - $('#form-name').val('edit_event'); - $('.event-page-title').text('Edit Event'); - $('#event-id').val(response.data.eventId); - if( btnClicked == 'publish' ) { - $('button[data-event-status="draft"]').hide(); - $('button[data-event-status="publish"]').text('Update Event'); - } - if( btnClicked == 'draft' ) { - $('button[data-event-status="draft"]').text('Update Draft'); - } - $('#event-url').removeClass('hide-event-url').find('a').attr('href', response.data.eventUrl).text(response.data.eventUrl); - if ( $is_creation ) { - $('#delete-button').toggle(); + $.ajax({ + type: 'POST', + url: $translation_event.url, + data:$form.serialize(), + success: function(response) { + if ( response.data.eventId ) { + history.replaceState('','', response.data.eventEditUrl) + $('#form-name').val('edit_event'); + $('.event-page-title').text('Edit Event'); + $('#event-id').val(response.data.eventId); + if( btnClicked == 'publish' ) { + $('button[data-event-status="draft"]').hide(); + $('button[data-event-status="publish"]').text('Update Event'); + } + if( btnClicked == 'draft' ) { + $('button[data-event-status="draft"]').text('Update Draft'); + } + $('#event-url').removeClass('hide-event-url').find('a').attr('href', response.data.eventUrl).text(response.data.eventUrl); + if ( $is_creation ) { + $('#delete-button').toggle(); + } + $gp.notices.success(response.data.message); } - $gp.notices.success(response.data.message); + }, + error: function(error) { + $gp.notices.error(response.data.message); } - }, - error: function(error) { - $gp.notices.error(response.data.message); - } + }); }); - }); - $('.delete-event').on('click', function(e) { - e.preventDefault(); - if ( ! confirm( 'Are you sure you want to delete this event?' ) ) { - return; - } - var $form = $('.translation-event-form'); - $('#form-name').val('delete_event'); - $('#event-form-action').val('delete'); - $.ajax({ - type: 'POST', - url: $translation_event.url, - data:$form.serialize(), - success: function(response) { + $('.delete-event').on('click', function(e) { + e.preventDefault(); + if ( ! confirm( 'Are you sure you want to delete this event?' ) ) { + return; + } + var $form = $('.translation-event-form'); + $('#form-name').val('delete_event'); + $('#event-form-action').val('delete'); + $.ajax({ + type: 'POST', + url: $translation_event.url, + data:$form.serialize(), + success: function(response) { window.location = response.data.eventDeleteUrl; - }, - error: function(error) { - $gp.notices.error(response.data.message); - }, + }, + error: function(error) { + $gp.notices.error(response.data.message); + }, + }); }); - }); - function validateEventDates() { - var startDateTimeInput = $('#event-start'); - var endDateTimeInput = $('#event-end'); - if ( ! startDateTimeInput.length || ! endDateTimeInput.length ) { - return; - } - - startDateTimeInput.add(endDateTimeInput).on('input', function () { - endDateTimeInput.prop('min', startDateTimeInput.val()); - if (endDateTimeInput.val() < startDateTimeInput.val()) { - endDateTimeInput.val(startDateTimeInput.val()); + function validateEventDates() { + var startDateTimeInput = $('#event-start'); + var endDateTimeInput = $('#event-end'); + if ( ! startDateTimeInput.length || ! endDateTimeInput.length ) { + return; } - }); - } - function selectUserTimezone() { - document.querySelector(`#event-timezone option[value="${Intl.DateTimeFormat().resolvedOptions().timeZone}"]`).selected = true - } - function convertToUserLocalTime() { - var timeElements = document.querySelectorAll('time.event-utc-time'); - if ( timeElements.length === 0 ) { - return; + startDateTimeInput.add(endDateTimeInput).on('input', function () { + endDateTimeInput.prop('min', startDateTimeInput.val()); + if (endDateTimeInput.val() < startDateTimeInput.val()) { + endDateTimeInput.val(startDateTimeInput.val()); + } + }); + } + function selectUserTimezone() { + document.querySelector(`#event-timezone option[value="${Intl.DateTimeFormat().resolvedOptions().timeZone}"]`).selected = true } - timeElements.forEach(function(timeEl) { - var eventDateObj = new Date( timeEl.getAttribute('datetime') ); - var userTimezoneOffset = new Date().getTimezoneOffset(); - var userTimezoneOffsetMs = userTimezoneOffset * 60 * 1000; - var userLocalDateTime = new Date(eventDateObj.getTime() - userTimezoneOffsetMs); - var options = { weekday: 'short', year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric', hour12: true, timeZoneName: 'short' }; + function convertToUserLocalTime() { + var timeElements = document.querySelectorAll('time.event-utc-time'); + if ( timeElements.length === 0 ) { + return; + } + timeElements.forEach(function(timeEl) { + var eventDateObj = new Date( timeEl.getAttribute('datetime') ); + var userTimezoneOffset = new Date().getTimezoneOffset(); + var userTimezoneOffsetMs = userTimezoneOffset * 60 * 1000; + var userLocalDateTime = new Date(eventDateObj.getTime() - userTimezoneOffsetMs); - timeEl.textContent = userLocalDateTime.toLocaleString('en-US', options); - }); - } + var options = { weekday: 'short', year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric', hour12: true, timeZoneName: 'short' }; -}); -}( jQuery, $gp ) + timeEl.textContent = userLocalDateTime.toLocaleString('en-US', options); + }); + } + + }); + }( jQuery, $gp ) ); From 70f655c1c7f06f26c63c7e7887b026a67afd192a Mon Sep 17 00:00:00 2001 From: Paulo Pinto Date: Thu, 15 Feb 2024 15:40:51 +0000 Subject: [PATCH 05/22] Fix indentation --- assets/js/translation-events.js | 206 ++++++++++++++++---------------- 1 file changed, 104 insertions(+), 102 deletions(-) diff --git a/assets/js/translation-events.js b/assets/js/translation-events.js index e7b4e374..b74c3226 100644 --- a/assets/js/translation-events.js +++ b/assets/js/translation-events.js @@ -1,114 +1,116 @@ -( function( $, $gp ) { - jQuery(document).ready(function($) { - $gp.notices.init(); - if ( $('#event-timezone').length && ! $('#event-timezone').val() ) { - selectUserTimezone(); - } - validateEventDates(); - convertToUserLocalTime(); - - $('.submit-event').on('click', function(e) { - e.preventDefault(); - if ( $('#event-end').val() <= $('#event-start').val() ) { - $gp.notices.error( 'Event end date and time must be later than event start date and time.' ); - return; - } - var btnClicked = $(this).data('event-status'); - if ( btnClicked == 'publish' && '' == $('#event-id').val() ) { - var submitPrompt = 'Are you sure you want to publish this event?'; - if ( ! confirm( submitPrompt ) ) { - return; +( + function( $, $gp ) { + jQuery(document).ready( + function($) { + $gp.notices.init(); + if ( $('#event-timezone').length && ! $('#event-timezone').val() ) { + selectUserTimezone(); } - } - $('#event-form-action').val( btnClicked ); - var $form = $('.translation-event-form'); - var $is_creation = $('#form-name').val() == 'create_event' ? true : false; + validateEventDates(); + convertToUserLocalTime(); - $.ajax({ - type: 'POST', - url: $translation_event.url, - data:$form.serialize(), - success: function(response) { - if ( response.data.eventId ) { - history.replaceState('','', response.data.eventEditUrl) - $('#form-name').val('edit_event'); - $('.event-page-title').text('Edit Event'); - $('#event-id').val(response.data.eventId); - if( btnClicked == 'publish' ) { - $('button[data-event-status="draft"]').hide(); - $('button[data-event-status="publish"]').text('Update Event'); - } - if( btnClicked == 'draft' ) { - $('button[data-event-status="draft"]').text('Update Draft'); - } - $('#event-url').removeClass('hide-event-url').find('a').attr('href', response.data.eventUrl).text(response.data.eventUrl); - if ( $is_creation ) { - $('#delete-button').toggle(); + $('.submit-event').on('click', function(e) { + e.preventDefault(); + if ( $('#event-end').val() <= $('#event-start').val() ) { + $gp.notices.error( 'Event end date and time must be later than event start date and time.' ); + return; + } + var btnClicked = $(this).data('event-status'); + if ( btnClicked == 'publish' && '' == $('#event-id').val() ) { + var submitPrompt = 'Are you sure you want to publish this event?'; + if ( ! confirm( submitPrompt ) ) { + return; } - $gp.notices.success(response.data.message); } - }, - error: function(error) { - $gp.notices.error(response.data.message); - } - }); - }); + $('#event-form-action').val( btnClicked ); + var $form = $('.translation-event-form'); + var $is_creation = $('#form-name').val() == 'create_event' ? true : false; - $('.delete-event').on('click', function(e) { - e.preventDefault(); - if ( ! confirm( 'Are you sure you want to delete this event?' ) ) { - return; - } - var $form = $('.translation-event-form'); - $('#form-name').val('delete_event'); - $('#event-form-action').val('delete'); - $.ajax({ - type: 'POST', - url: $translation_event.url, - data:$form.serialize(), - success: function(response) { - window.location = response.data.eventDeleteUrl; - }, - error: function(error) { - $gp.notices.error(response.data.message); - }, - }); - }); - function validateEventDates() { - var startDateTimeInput = $('#event-start'); - var endDateTimeInput = $('#event-end'); - if ( ! startDateTimeInput.length || ! endDateTimeInput.length ) { - return; - } + $.ajax({ + type: 'POST', + url: $translation_event.url, + data:$form.serialize(), + success: function(response) { + if ( response.data.eventId ) { + history.replaceState('','', response.data.eventEditUrl) + $('#form-name').val('edit_event'); + $('.event-page-title').text('Edit Event'); + $('#event-id').val(response.data.eventId); + if( btnClicked == 'publish' ) { + $('button[data-event-status="draft"]').hide(); + $('button[data-event-status="publish"]').text('Update Event'); + } + if( btnClicked == 'draft' ) { + $('button[data-event-status="draft"]').text('Update Draft'); + } + $('#event-url').removeClass('hide-event-url').find('a').attr('href', response.data.eventUrl).text(response.data.eventUrl); + if ( $is_creation ) { + $('#delete-button').toggle(); + } + $gp.notices.success(response.data.message); + } + }, + error: function(error) { + $gp.notices.error(response.data.message); + } + }); + }); - startDateTimeInput.add(endDateTimeInput).on('input', function () { - endDateTimeInput.prop('min', startDateTimeInput.val()); - if (endDateTimeInput.val() < startDateTimeInput.val()) { - endDateTimeInput.val(startDateTimeInput.val()); - } - }); - } - function selectUserTimezone() { - document.querySelector(`#event-timezone option[value="${Intl.DateTimeFormat().resolvedOptions().timeZone}"]`).selected = true - } + $('.delete-event').on('click', function(e) { + e.preventDefault(); + if ( ! confirm( 'Are you sure you want to delete this event?' ) ) { + return; + } + var $form = $('.translation-event-form'); + $('#form-name').val('delete_event'); + $('#event-form-action').val('delete'); + $.ajax({ + type: 'POST', + url: $translation_event.url, + data:$form.serialize(), + success: function(response) { + window.location = response.data.eventDeleteUrl; + }, + error: function(error) { + $gp.notices.error(response.data.message); + }, + }); + }); + function validateEventDates() { + var startDateTimeInput = $('#event-start'); + var endDateTimeInput = $('#event-end'); + if ( ! startDateTimeInput.length || ! endDateTimeInput.length ) { + return; + } - function convertToUserLocalTime() { - var timeElements = document.querySelectorAll('time.event-utc-time'); - if ( timeElements.length === 0 ) { - return; - } - timeElements.forEach(function(timeEl) { - var eventDateObj = new Date( timeEl.getAttribute('datetime') ); - var userTimezoneOffset = new Date().getTimezoneOffset(); - var userTimezoneOffsetMs = userTimezoneOffset * 60 * 1000; - var userLocalDateTime = new Date(eventDateObj.getTime() - userTimezoneOffsetMs); + startDateTimeInput.add(endDateTimeInput).on('input', function () { + endDateTimeInput.prop('min', startDateTimeInput.val()); + if (endDateTimeInput.val() < startDateTimeInput.val()) { + endDateTimeInput.val(startDateTimeInput.val()); + } + }); + } + function selectUserTimezone() { + document.querySelector(`#event-timezone option[value="${Intl.DateTimeFormat().resolvedOptions().timeZone}"]`).selected = true + } - var options = { weekday: 'short', year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric', hour12: true, timeZoneName: 'short' }; + function convertToUserLocalTime() { + var timeElements = document.querySelectorAll('time.event-utc-time'); + if ( timeElements.length === 0 ) { + return; + } + timeElements.forEach(function(timeEl) { + var eventDateObj = new Date( timeEl.getAttribute('datetime') ); + var userTimezoneOffset = new Date().getTimezoneOffset(); + var userTimezoneOffsetMs = userTimezoneOffset * 60 * 1000; + var userLocalDateTime = new Date(eventDateObj.getTime() - userTimezoneOffsetMs); - timeEl.textContent = userLocalDateTime.toLocaleString('en-US', options); - }); - } + var options = { weekday: 'short', year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric', hour12: true, timeZoneName: 'short' }; - }); + timeEl.textContent = userLocalDateTime.toLocaleString('en-US', options); + }); + } + } + ); }( jQuery, $gp ) ); From c8be3f4e951431ec4838984c08b1132cb5478da5 Mon Sep 17 00:00:00 2001 From: Paulo Pinto Date: Thu, 15 Feb 2024 15:44:14 +0000 Subject: [PATCH 06/22] Lint js --- assets/js/translation-events.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/assets/js/translation-events.js b/assets/js/translation-events.js index b74c3226..6aa8768d 100644 --- a/assets/js/translation-events.js +++ b/assets/js/translation-events.js @@ -1,9 +1,9 @@ ( - function( $, $gp ) { - jQuery(document).ready( - function($) { + function ( $, $gp ) { + jQuery( document ).ready( + function ( $ ) { $gp.notices.init(); - if ( $('#event-timezone').length && ! $('#event-timezone').val() ) { + if ( $( '#event-timezone' ).length && ! $( '#event-timezone' ).val() ) { selectUserTimezone(); } validateEventDates(); From c512a0903409c7ac4fa46318c883dadaa57f0213 Mon Sep 17 00:00:00 2001 From: Paulo Pinto Date: Thu, 15 Feb 2024 15:47:46 +0000 Subject: [PATCH 07/22] Correctly indent handler --- assets/js/translation-events.js | 85 +++++++++++++++++---------------- 1 file changed, 44 insertions(+), 41 deletions(-) diff --git a/assets/js/translation-events.js b/assets/js/translation-events.js index 6aa8768d..26d2dac2 100644 --- a/assets/js/translation-events.js +++ b/assets/js/translation-events.js @@ -9,52 +9,55 @@ validateEventDates(); convertToUserLocalTime(); - $('.submit-event').on('click', function(e) { - e.preventDefault(); - if ( $('#event-end').val() <= $('#event-start').val() ) { - $gp.notices.error( 'Event end date and time must be later than event start date and time.' ); - return; - } - var btnClicked = $(this).data('event-status'); - if ( btnClicked == 'publish' && '' == $('#event-id').val() ) { - var submitPrompt = 'Are you sure you want to publish this event?'; - if ( ! confirm( submitPrompt ) ) { + $('.submit-event').on( + 'click', + function(e) { + e.preventDefault(); + if ( $('#event-end').val() <= $('#event-start').val() ) { + $gp.notices.error( 'Event end date and time must be later than event start date and time.' ); return; } - } - $('#event-form-action').val( btnClicked ); - var $form = $('.translation-event-form'); - var $is_creation = $('#form-name').val() == 'create_event' ? true : false; + var btnClicked = $(this).data('event-status'); + if ( btnClicked == 'publish' && '' == $('#event-id').val() ) { + var submitPrompt = 'Are you sure you want to publish this event?'; + if ( ! confirm( submitPrompt ) ) { + return; + } + } + $('#event-form-action').val( btnClicked ); + var $form = $('.translation-event-form'); + var $is_creation = $('#form-name').val() == 'create_event' ? true : false; - $.ajax({ - type: 'POST', - url: $translation_event.url, - data:$form.serialize(), - success: function(response) { - if ( response.data.eventId ) { - history.replaceState('','', response.data.eventEditUrl) - $('#form-name').val('edit_event'); - $('.event-page-title').text('Edit Event'); - $('#event-id').val(response.data.eventId); - if( btnClicked == 'publish' ) { - $('button[data-event-status="draft"]').hide(); - $('button[data-event-status="publish"]').text('Update Event'); - } - if( btnClicked == 'draft' ) { - $('button[data-event-status="draft"]').text('Update Draft'); - } - $('#event-url').removeClass('hide-event-url').find('a').attr('href', response.data.eventUrl).text(response.data.eventUrl); - if ( $is_creation ) { - $('#delete-button').toggle(); + $.ajax({ + type: 'POST', + url: $translation_event.url, + data:$form.serialize(), + success: function(response) { + if ( response.data.eventId ) { + history.replaceState('','', response.data.eventEditUrl) + $('#form-name').val('edit_event'); + $('.event-page-title').text('Edit Event'); + $('#event-id').val(response.data.eventId); + if( btnClicked == 'publish' ) { + $('button[data-event-status="draft"]').hide(); + $('button[data-event-status="publish"]').text('Update Event'); + } + if( btnClicked == 'draft' ) { + $('button[data-event-status="draft"]').text('Update Draft'); + } + $('#event-url').removeClass('hide-event-url').find('a').attr('href', response.data.eventUrl).text(response.data.eventUrl); + if ( $is_creation ) { + $('#delete-button').toggle(); + } + $gp.notices.success(response.data.message); } - $gp.notices.success(response.data.message); + }, + error: function(error) { + $gp.notices.error(response.data.message); } - }, - error: function(error) { - $gp.notices.error(response.data.message); - } - }); - }); + }); + } + ); $('.delete-event').on('click', function(e) { e.preventDefault(); From 1e2ad68aced67ac01a1539662b858b6ec9b98b7a Mon Sep 17 00:00:00 2001 From: Paulo Pinto Date: Thu, 15 Feb 2024 15:49:51 +0000 Subject: [PATCH 08/22] Lint js --- assets/js/translation-events.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/assets/js/translation-events.js b/assets/js/translation-events.js index 26d2dac2..182d01ed 100644 --- a/assets/js/translation-events.js +++ b/assets/js/translation-events.js @@ -9,24 +9,24 @@ validateEventDates(); convertToUserLocalTime(); - $('.submit-event').on( + $( '.submit-event' ).on( 'click', - function(e) { + function ( e ) { e.preventDefault(); - if ( $('#event-end').val() <= $('#event-start').val() ) { + if ( $( '#event-end' ).val() <= $( '#event-start' ).val() ) { $gp.notices.error( 'Event end date and time must be later than event start date and time.' ); return; } - var btnClicked = $(this).data('event-status'); - if ( btnClicked == 'publish' && '' == $('#event-id').val() ) { + var btnClicked = $( this ).data( 'event-status' ); + if ( btnClicked == 'publish' && '' == $( '#event-id' ).val() ) { var submitPrompt = 'Are you sure you want to publish this event?'; if ( ! confirm( submitPrompt ) ) { return; } } - $('#event-form-action').val( btnClicked ); - var $form = $('.translation-event-form'); - var $is_creation = $('#form-name').val() == 'create_event' ? true : false; + $( '#event-form-action' ).val( btnClicked ); + var $form = $( '.translation-event-form' ); + var $is_creation = $( '#form-name' ).val() == 'create_event' ? true : false; $.ajax({ type: 'POST', From dbf0590ce0255cfc02827c92d89016b12adbdc78 Mon Sep 17 00:00:00 2001 From: Paulo Pinto Date: Thu, 15 Feb 2024 15:50:21 +0000 Subject: [PATCH 09/22] Correctly indent function call --- assets/js/translation-events.js | 52 +++++++++++++++++---------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/assets/js/translation-events.js b/assets/js/translation-events.js index 182d01ed..6693979a 100644 --- a/assets/js/translation-events.js +++ b/assets/js/translation-events.js @@ -28,34 +28,36 @@ var $form = $( '.translation-event-form' ); var $is_creation = $( '#form-name' ).val() == 'create_event' ? true : false; - $.ajax({ - type: 'POST', - url: $translation_event.url, - data:$form.serialize(), - success: function(response) { - if ( response.data.eventId ) { - history.replaceState('','', response.data.eventEditUrl) - $('#form-name').val('edit_event'); - $('.event-page-title').text('Edit Event'); - $('#event-id').val(response.data.eventId); - if( btnClicked == 'publish' ) { - $('button[data-event-status="draft"]').hide(); - $('button[data-event-status="publish"]').text('Update Event'); + $.ajax( + { + type: 'POST', + url: $translation_event.url, + data:$form.serialize(), + success: function(response) { + if ( response.data.eventId ) { + history.replaceState('','', response.data.eventEditUrl) + $('#form-name').val('edit_event'); + $('.event-page-title').text('Edit Event'); + $('#event-id').val(response.data.eventId); + if( btnClicked == 'publish' ) { + $('button[data-event-status="draft"]').hide(); + $('button[data-event-status="publish"]').text('Update Event'); + } + if( btnClicked == 'draft' ) { + $('button[data-event-status="draft"]').text('Update Draft'); + } + $('#event-url').removeClass('hide-event-url').find('a').attr('href', response.data.eventUrl).text(response.data.eventUrl); + if ( $is_creation ) { + $('#delete-button').toggle(); + } + $gp.notices.success(response.data.message); } - if( btnClicked == 'draft' ) { - $('button[data-event-status="draft"]').text('Update Draft'); - } - $('#event-url').removeClass('hide-event-url').find('a').attr('href', response.data.eventUrl).text(response.data.eventUrl); - if ( $is_creation ) { - $('#delete-button').toggle(); - } - $gp.notices.success(response.data.message); + }, + error: function(error) { + $gp.notices.error(response.data.message); } - }, - error: function(error) { - $gp.notices.error(response.data.message); } - }); + ); } ); From 1b0d8fa06cf50d8d810c42b20729960ae9b7da4b Mon Sep 17 00:00:00 2001 From: Paulo Pinto Date: Thu, 15 Feb 2024 15:54:33 +0000 Subject: [PATCH 10/22] Lint js --- assets/js/translation-events.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/assets/js/translation-events.js b/assets/js/translation-events.js index 6693979a..fb461f27 100644 --- a/assets/js/translation-events.js +++ b/assets/js/translation-events.js @@ -35,7 +35,7 @@ data:$form.serialize(), success: function(response) { if ( response.data.eventId ) { - history.replaceState('','', response.data.eventEditUrl) + history.replaceState( '', '', response.data.eventEditUrl ); $('#form-name').val('edit_event'); $('.event-page-title').text('Edit Event'); $('#event-id').val(response.data.eventId); @@ -110,7 +110,16 @@ var userTimezoneOffsetMs = userTimezoneOffset * 60 * 1000; var userLocalDateTime = new Date(eventDateObj.getTime() - userTimezoneOffsetMs); - var options = { weekday: 'short', year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric', hour12: true, timeZoneName: 'short' }; + var options = { + weekday: 'short', + year: 'numeric', + month: 'long', + day: 'numeric', + hour: 'numeric', + minute: 'numeric', + hour12: true, + timeZoneName: 'short' + }; timeEl.textContent = userLocalDateTime.toLocaleString('en-US', options); }); From 0eb9b66caee45ff9722c9ff05cf6d2125028fbee Mon Sep 17 00:00:00 2001 From: Paulo Pinto Date: Thu, 15 Feb 2024 15:55:38 +0000 Subject: [PATCH 11/22] Use strict comparison --- assets/js/translation-events.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/assets/js/translation-events.js b/assets/js/translation-events.js index fb461f27..7f011239 100644 --- a/assets/js/translation-events.js +++ b/assets/js/translation-events.js @@ -18,7 +18,7 @@ return; } var btnClicked = $( this ).data( 'event-status' ); - if ( btnClicked == 'publish' && '' == $( '#event-id' ).val() ) { + if ( btnClicked === 'publish' && '' === $( '#event-id' ).val() ) { var submitPrompt = 'Are you sure you want to publish this event?'; if ( ! confirm( submitPrompt ) ) { return; @@ -26,7 +26,7 @@ } $( '#event-form-action' ).val( btnClicked ); var $form = $( '.translation-event-form' ); - var $is_creation = $( '#form-name' ).val() == 'create_event' ? true : false; + var $is_creation = $('#form-name').val() === 'create_event'; $.ajax( { @@ -39,11 +39,11 @@ $('#form-name').val('edit_event'); $('.event-page-title').text('Edit Event'); $('#event-id').val(response.data.eventId); - if( btnClicked == 'publish' ) { + if( btnClicked === 'publish' ) { $('button[data-event-status="draft"]').hide(); $('button[data-event-status="publish"]').text('Update Event'); } - if( btnClicked == 'draft' ) { + if( btnClicked === 'draft' ) { $('button[data-event-status="draft"]').text('Update Draft'); } $('#event-url').removeClass('hide-event-url').find('a').attr('href', response.data.eventUrl).text(response.data.eventUrl); From fb7595748fee6c3d12eb0e204ffbb4d8ee0139dd Mon Sep 17 00:00:00 2001 From: Paulo Pinto Date: Thu, 15 Feb 2024 15:56:35 +0000 Subject: [PATCH 12/22] Correctly indent inline functions --- assets/js/translation-events.js | 49 ++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/assets/js/translation-events.js b/assets/js/translation-events.js index 7f011239..a4297842 100644 --- a/assets/js/translation-events.js +++ b/assets/js/translation-events.js @@ -88,12 +88,15 @@ return; } - startDateTimeInput.add(endDateTimeInput).on('input', function () { - endDateTimeInput.prop('min', startDateTimeInput.val()); - if (endDateTimeInput.val() < startDateTimeInput.val()) { - endDateTimeInput.val(startDateTimeInput.val()); + startDateTimeInput.add( endDateTimeInput ).on( + 'input', + function () { + endDateTimeInput.prop('min', startDateTimeInput.val()); + if (endDateTimeInput.val() < startDateTimeInput.val()) { + endDateTimeInput.val(startDateTimeInput.val()); + } } - }); + ); } function selectUserTimezone() { document.querySelector(`#event-timezone option[value="${Intl.DateTimeFormat().resolvedOptions().timeZone}"]`).selected = true @@ -104,25 +107,27 @@ if ( timeElements.length === 0 ) { return; } - timeElements.forEach(function(timeEl) { - var eventDateObj = new Date( timeEl.getAttribute('datetime') ); - var userTimezoneOffset = new Date().getTimezoneOffset(); - var userTimezoneOffsetMs = userTimezoneOffset * 60 * 1000; - var userLocalDateTime = new Date(eventDateObj.getTime() - userTimezoneOffsetMs); + timeElements.forEach( + function ( timeEl ) { + var eventDateObj = new Date( timeEl.getAttribute('datetime') ); + var userTimezoneOffset = new Date().getTimezoneOffset(); + var userTimezoneOffsetMs = userTimezoneOffset * 60 * 1000; + var userLocalDateTime = new Date(eventDateObj.getTime() - userTimezoneOffsetMs); - var options = { - weekday: 'short', - year: 'numeric', - month: 'long', - day: 'numeric', - hour: 'numeric', - minute: 'numeric', - hour12: true, - timeZoneName: 'short' - }; + var options = { + weekday: 'short', + year: 'numeric', + month: 'long', + day: 'numeric', + hour: 'numeric', + minute: 'numeric', + hour12: true, + timeZoneName: 'short' + }; - timeEl.textContent = userLocalDateTime.toLocaleString('en-US', options); - }); + timeEl.textContent = userLocalDateTime.toLocaleString('en-US', options); + } + ); } } ); From 9db2375b71d9fa622eb9435c761383737065d87b Mon Sep 17 00:00:00 2001 From: Paulo Pinto Date: Thu, 15 Feb 2024 15:58:07 +0000 Subject: [PATCH 13/22] Extract value to variable --- assets/js/translation-events.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/assets/js/translation-events.js b/assets/js/translation-events.js index a4297842..a2f2d7f3 100644 --- a/assets/js/translation-events.js +++ b/assets/js/translation-events.js @@ -99,7 +99,8 @@ ); } function selectUserTimezone() { - document.querySelector(`#event-timezone option[value="${Intl.DateTimeFormat().resolvedOptions().timeZone}"]`).selected = true + const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone; + document.querySelector( `#event-timezone option[value="${timezone}"]` ).selected = true } function convertToUserLocalTime() { From 61effc61d16c11536454094f932301d325d6cffc Mon Sep 17 00:00:00 2001 From: Paulo Pinto Date: Thu, 15 Feb 2024 15:59:36 +0000 Subject: [PATCH 14/22] Disable erroneous rules --- assets/js/translation-events.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/assets/js/translation-events.js b/assets/js/translation-events.js index a2f2d7f3..2d8ea097 100644 --- a/assets/js/translation-events.js +++ b/assets/js/translation-events.js @@ -100,7 +100,10 @@ } function selectUserTimezone() { const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone; + // phpcs:disable WordPress.WhiteSpace.OperatorSpacing.NoSpaceBefore + // phpcs:disable WordPress.WhiteSpace.OperatorSpacing.NoSpaceAfter document.querySelector( `#event-timezone option[value="${timezone}"]` ).selected = true + // phpcs:enable } function convertToUserLocalTime() { From 162cde7ef3eece116df10b9e763870f5c266ee14 Mon Sep 17 00:00:00 2001 From: Paulo Pinto Date: Thu, 15 Feb 2024 16:00:39 +0000 Subject: [PATCH 15/22] Cache jquery element --- assets/js/translation-events.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/assets/js/translation-events.js b/assets/js/translation-events.js index 2d8ea097..c5cd8193 100644 --- a/assets/js/translation-events.js +++ b/assets/js/translation-events.js @@ -3,7 +3,8 @@ jQuery( document ).ready( function ( $ ) { $gp.notices.init(); - if ( $( '#event-timezone' ).length && ! $( '#event-timezone' ).val() ) { + const timezoneElement = $( '#event-timezone' ); + if ( timezoneElement.length && ! timezoneElement.val() ) { selectUserTimezone(); } validateEventDates(); From 7ff3e12f7c9371871383419285380468549a2d06 Mon Sep 17 00:00:00 2001 From: Paulo Pinto Date: Thu, 15 Feb 2024 16:01:56 +0000 Subject: [PATCH 16/22] Use const instead of var --- assets/js/translation-events.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/assets/js/translation-events.js b/assets/js/translation-events.js index c5cd8193..ad727b44 100644 --- a/assets/js/translation-events.js +++ b/assets/js/translation-events.js @@ -18,16 +18,16 @@ $gp.notices.error( 'Event end date and time must be later than event start date and time.' ); return; } - var btnClicked = $( this ).data( 'event-status' ); + const btnClicked = $( this ).data( 'event-status' ); if ( btnClicked === 'publish' && '' === $( '#event-id' ).val() ) { - var submitPrompt = 'Are you sure you want to publish this event?'; + const submitPrompt = 'Are you sure you want to publish this event?'; if ( ! confirm( submitPrompt ) ) { return; } } $( '#event-form-action' ).val( btnClicked ); - var $form = $( '.translation-event-form' ); - var $is_creation = $('#form-name').val() === 'create_event'; + const $form = $( '.translation-event-form' ); + const $is_creation = $('#form-name').val() === 'create_event'; $.ajax( { @@ -67,7 +67,7 @@ if ( ! confirm( 'Are you sure you want to delete this event?' ) ) { return; } - var $form = $('.translation-event-form'); + const $form = $('.translation-event-form'); $('#form-name').val('delete_event'); $('#event-form-action').val('delete'); $.ajax({ @@ -83,8 +83,8 @@ }); }); function validateEventDates() { - var startDateTimeInput = $('#event-start'); - var endDateTimeInput = $('#event-end'); + const startDateTimeInput = $('#event-start'); + const endDateTimeInput = $('#event-end'); if ( ! startDateTimeInput.length || ! endDateTimeInput.length ) { return; } @@ -108,18 +108,18 @@ } function convertToUserLocalTime() { - var timeElements = document.querySelectorAll('time.event-utc-time'); + const timeElements = document.querySelectorAll('time.event-utc-time'); if ( timeElements.length === 0 ) { return; } timeElements.forEach( function ( timeEl ) { - var eventDateObj = new Date( timeEl.getAttribute('datetime') ); - var userTimezoneOffset = new Date().getTimezoneOffset(); - var userTimezoneOffsetMs = userTimezoneOffset * 60 * 1000; - var userLocalDateTime = new Date(eventDateObj.getTime() - userTimezoneOffsetMs); + const eventDateObj = new Date( timeEl.getAttribute('datetime') ); + const userTimezoneOffset = new Date().getTimezoneOffset(); + const userTimezoneOffsetMs = userTimezoneOffset * 60 * 1000; + const userLocalDateTime = new Date(eventDateObj.getTime() - userTimezoneOffsetMs); - var options = { + const options = { weekday: 'short', year: 'numeric', month: 'long', From 99d44c158951d50af8f0aa354e8cde4ba7db188f Mon Sep 17 00:00:00 2001 From: Paulo Pinto Date: Thu, 15 Feb 2024 16:07:30 +0000 Subject: [PATCH 17/22] Extract functions out of the ready function --- assets/js/translation-events.js | 97 +++++++++++++++++---------------- 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/assets/js/translation-events.js b/assets/js/translation-events.js index ad727b44..1cf2786d 100644 --- a/assets/js/translation-events.js +++ b/assets/js/translation-events.js @@ -82,59 +82,60 @@ }, }); }); - function validateEventDates() { - const startDateTimeInput = $('#event-start'); - const endDateTimeInput = $('#event-end'); - if ( ! startDateTimeInput.length || ! endDateTimeInput.length ) { - return; - } + } + ); - startDateTimeInput.add( endDateTimeInput ).on( - 'input', - function () { - endDateTimeInput.prop('min', startDateTimeInput.val()); - if (endDateTimeInput.val() < startDateTimeInput.val()) { - endDateTimeInput.val(startDateTimeInput.val()); - } - } - ); - } - function selectUserTimezone() { - const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone; - // phpcs:disable WordPress.WhiteSpace.OperatorSpacing.NoSpaceBefore - // phpcs:disable WordPress.WhiteSpace.OperatorSpacing.NoSpaceAfter - document.querySelector( `#event-timezone option[value="${timezone}"]` ).selected = true - // phpcs:enable - } + function validateEventDates() { + const startDateTimeInput = $('#event-start'); + const endDateTimeInput = $('#event-end'); + if ( ! startDateTimeInput.length || ! endDateTimeInput.length ) { + return; + } - function convertToUserLocalTime() { - const timeElements = document.querySelectorAll('time.event-utc-time'); - if ( timeElements.length === 0 ) { - return; + startDateTimeInput.add( endDateTimeInput ).on( + 'input', + function () { + endDateTimeInput.prop('min', startDateTimeInput.val()); + if (endDateTimeInput.val() < startDateTimeInput.val()) { + endDateTimeInput.val(startDateTimeInput.val()); } - timeElements.forEach( - function ( timeEl ) { - const eventDateObj = new Date( timeEl.getAttribute('datetime') ); - const userTimezoneOffset = new Date().getTimezoneOffset(); - const userTimezoneOffsetMs = userTimezoneOffset * 60 * 1000; - const userLocalDateTime = new Date(eventDateObj.getTime() - userTimezoneOffsetMs); + } + ); + } + function selectUserTimezone() { + const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone; + // phpcs:disable WordPress.WhiteSpace.OperatorSpacing.NoSpaceBefore + // phpcs:disable WordPress.WhiteSpace.OperatorSpacing.NoSpaceAfter + document.querySelector( `#event-timezone option[value="${timezone}"]` ).selected = true + // phpcs:enable + } + + function convertToUserLocalTime() { + const timeElements = document.querySelectorAll('time.event-utc-time'); + if ( timeElements.length === 0 ) { + return; + } + timeElements.forEach( + function ( timeEl ) { + const eventDateObj = new Date( timeEl.getAttribute('datetime') ); + const userTimezoneOffset = new Date().getTimezoneOffset(); + const userTimezoneOffsetMs = userTimezoneOffset * 60 * 1000; + const userLocalDateTime = new Date(eventDateObj.getTime() - userTimezoneOffsetMs); - const options = { - weekday: 'short', - year: 'numeric', - month: 'long', - day: 'numeric', - hour: 'numeric', - minute: 'numeric', - hour12: true, - timeZoneName: 'short' - }; + const options = { + weekday: 'short', + year: 'numeric', + month: 'long', + day: 'numeric', + hour: 'numeric', + minute: 'numeric', + hour12: true, + timeZoneName: 'short' + }; - timeEl.textContent = userLocalDateTime.toLocaleString('en-US', options); - } - ); + timeEl.textContent = userLocalDateTime.toLocaleString('en-US', options); } - } - ); + ); + } }( jQuery, $gp ) ); From ccc6de5535b8ab51ddd6ae830847118796321f6b Mon Sep 17 00:00:00 2001 From: Paulo Pinto Date: Thu, 15 Feb 2024 16:08:56 +0000 Subject: [PATCH 18/22] Extract submit logic to a function --- assets/js/translation-events.js | 94 +++++++++++++++++---------------- 1 file changed, 49 insertions(+), 45 deletions(-) diff --git a/assets/js/translation-events.js b/assets/js/translation-events.js index 1cf2786d..5efd5539 100644 --- a/assets/js/translation-events.js +++ b/assets/js/translation-events.js @@ -14,51 +14,7 @@ 'click', function ( e ) { e.preventDefault(); - if ( $( '#event-end' ).val() <= $( '#event-start' ).val() ) { - $gp.notices.error( 'Event end date and time must be later than event start date and time.' ); - return; - } - const btnClicked = $( this ).data( 'event-status' ); - if ( btnClicked === 'publish' && '' === $( '#event-id' ).val() ) { - const submitPrompt = 'Are you sure you want to publish this event?'; - if ( ! confirm( submitPrompt ) ) { - return; - } - } - $( '#event-form-action' ).val( btnClicked ); - const $form = $( '.translation-event-form' ); - const $is_creation = $('#form-name').val() === 'create_event'; - - $.ajax( - { - type: 'POST', - url: $translation_event.url, - data:$form.serialize(), - success: function(response) { - if ( response.data.eventId ) { - history.replaceState( '', '', response.data.eventEditUrl ); - $('#form-name').val('edit_event'); - $('.event-page-title').text('Edit Event'); - $('#event-id').val(response.data.eventId); - if( btnClicked === 'publish' ) { - $('button[data-event-status="draft"]').hide(); - $('button[data-event-status="publish"]').text('Update Event'); - } - if( btnClicked === 'draft' ) { - $('button[data-event-status="draft"]').text('Update Draft'); - } - $('#event-url').removeClass('hide-event-url').find('a').attr('href', response.data.eventUrl).text(response.data.eventUrl); - if ( $is_creation ) { - $('#delete-button').toggle(); - } - $gp.notices.success(response.data.message); - } - }, - error: function(error) { - $gp.notices.error(response.data.message); - } - } - ); + handleSubmit(); } ); @@ -85,6 +41,54 @@ } ); + function handleSubmit() { + if ( $( '#event-end' ).val() <= $( '#event-start' ).val() ) { + $gp.notices.error( 'Event end date and time must be later than event start date and time.' ); + return; + } + const btnClicked = $( this ).data( 'event-status' ); + if ( btnClicked === 'publish' && '' === $( '#event-id' ).val() ) { + const submitPrompt = 'Are you sure you want to publish this event?'; + if ( ! confirm( submitPrompt ) ) { + return; + } + } + $( '#event-form-action' ).val( btnClicked ); + const $form = $( '.translation-event-form' ); + const $is_creation = $('#form-name').val() === 'create_event'; + + $.ajax( + { + type: 'POST', + url: $translation_event.url, + data:$form.serialize(), + success: function(response) { + if ( response.data.eventId ) { + history.replaceState( '', '', response.data.eventEditUrl ); + $('#form-name').val('edit_event'); + $('.event-page-title').text('Edit Event'); + $('#event-id').val(response.data.eventId); + if( btnClicked === 'publish' ) { + $('button[data-event-status="draft"]').hide(); + $('button[data-event-status="publish"]').text('Update Event'); + } + if( btnClicked === 'draft' ) { + $('button[data-event-status="draft"]').text('Update Draft'); + } + $('#event-url').removeClass('hide-event-url').find('a').attr('href', response.data.eventUrl).text(response.data.eventUrl); + if ( $is_creation ) { + $('#delete-button').toggle(); + } + $gp.notices.success(response.data.message); + } + }, + error: function(error) { + $gp.notices.error(response.data.message); + } + } + ); + } + function validateEventDates() { const startDateTimeInput = $('#event-start'); const endDateTimeInput = $('#event-end'); From 83fca2cfd342c63b0a0f423c23729ff7899014d1 Mon Sep 17 00:00:00 2001 From: Paulo Pinto Date: Thu, 15 Feb 2024 16:12:54 +0000 Subject: [PATCH 19/22] Indent CSS with tabs --- assets/css/translation-events.css | 145 +++++++++++++++--------------- phpcs.xml | 2 +- 2 files changed, 73 insertions(+), 74 deletions(-) diff --git a/assets/css/translation-events.css b/assets/css/translation-events.css index 80683a83..5a7337c6 100644 --- a/assets/css/translation-events.css +++ b/assets/css/translation-events.css @@ -1,136 +1,135 @@ .translation-event-form label { - display: inline-block; - width: 140px; - vertical-align: top; + display: inline-block; + width: 140px; + vertical-align: top; } .translation-event-form #event-title, .translation-event-form #event-description { - width: 30%; + width: 30%; } .translation-event-form input[type="text"], .translation-event-form input[type="date"] { - width: 13%; + width: 13%; } .translation-event-form div { - margin-top: 1em; + margin-top: 1em; } .translation-event-form #submit-event { - margin-left: 10%; - width: 30%; - margin-top: 1em; - display: block; + margin-left: 10%; + width: 30%; + margin-top: 1em; + display: block; } .event-page-title { - border-bottom: #d9d8d8 thin solid; - padding-bottom: .5em; + border-bottom: #d9d8d8 thin solid; + padding-bottom: .5em; } .event-details-page { - border-bottom: #cfd4d4 thin solid; - width: 60%; - margin: 0 auto; + border-bottom: #cfd4d4 thin solid; + width: 60%; + margin: 0 auto; } .event-details-left { - width: 77%; - float: left; - border-right: #dadfdf thin solid; - margin-right: 1%; - padding-right: 1em; + width: 77%; + float: left; + border-right: #dadfdf thin solid; + margin-right: 1%; + padding-right: 1em; } .event-details-right { - width: 22%; - float: left; - padding: 1em; + width: 22%; + float: left; + padding: 1em; } .event-details-stats { - clear: both; - margin: 1em; + clear: both; + margin: 1em; } .event-details-stats table, .event-details-stats table td, .event-details-stats table th { - border: 0.2em solid var(--gp-color-primary); - padding: 1em; + border: 0.2em solid var(--gp-color-primary); + padding: 1em; } .event-details-stats-totals { - font-weight: bold; + font-weight: bold; } .hide-event-url { - display: none; + display: none; } .translation-event-form button.save-draft { - background: #fff; - color: var(--gp-color-btn-primary-bg); + background: #fff; + color: var(--gp-color-btn-primary-bg); } #event-url span { - width: 10%; - display: inline-block; + width: 10%; + display: inline-block; } span.event-list-date { - display: block; - color: #939393; - font-size: .9em; - font-weight: bold; + display: block; + color: #939393; + font-size: .9em; + font-weight: bold; } span.event-list-date.events-i-am-attending { font-size: .8em; font-weight: normal; } .event-list-item a{ - font-weight: bold; - font-size: 1.2em; + font-weight: bold; + font-size: 1.2em; } li.event-list-item { - list-style-type: none; + list-style-type: none; } li.event-list-item p { - margin-top: 0; - color: #5a5a5a; - font-size: .95em; + margin-top: 0; + color: #5a5a5a; + font-size: .95em; } h2.event_page_title { - border-bottom: #e0e0e0 thin solid; - padding-bottom: 0.5em; - font-weight: bold; + border-bottom: #e0e0e0 thin solid; + padding-bottom: 0.5em; + font-weight: bold; } .event-list-top-bar { - float: right; + float: right; } .event-list-nav li { - display: inline; - margin-right: 1em; + display: inline; + margin-right: 1em; } .event-left-col { - width: 70%; - float: left; + width: 70%; + float: left; } .event-right-col { - width: 25%; - float: left; - padding: 1em; - border-left: var(--wp--preset--color--cyan-bluish-gray) thin solid; + width: 25%; + float: left; + padding: 1em; + border-left: var(--wp--preset--color--cyan-bluish-gray) thin solid; } .event-attending-list { - list-style-type: none; - padding: 0; + list-style-type: none; + padding: 0; } .event-attending-list li { - margin-bottom: 1em; + margin-bottom: 1em; } .event-list-nav li a.button { - background-color: var(--gp-color-btn-primary-bg) !important; - color: #fff !important; + background-color: var(--gp-color-btn-primary-bg) !important; + color: #fff !important; } a.event-link-draft { - color:#80807f; + color:#80807f; } span.event-label-draft { - font-weight: 500; - color:#c05621; - border: 1px solid #c05621; - font-size: .7em; - margin-right: 0.3em; - width: 6em; - text-align: center; - padding: 0.2em 0.5em; - border-radius: 1em; - text-transform: capitalize; -} - + font-weight: 500; + color:#c05621; + border: 1px solid #c05621; + font-size: .7em; + margin-right: 0.3em; + width: 6em; + text-align: center; + padding: 0.2em 0.5em; + border-radius: 1em; + text-transform: capitalize; +} diff --git a/phpcs.xml b/phpcs.xml index abcbcddc..c7904ecf 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -3,7 +3,7 @@ Coding standards - + ./assets/ ./includes/ From 3d269c752e85fa78108e6b11433cad9b686c4aaf Mon Sep 17 00:00:00 2001 From: Paulo Pinto Date: Thu, 15 Feb 2024 16:40:31 +0000 Subject: [PATCH 20/22] Rename job --- .github/workflows/coding-standards.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index 528847b8..180b4934 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -5,8 +5,8 @@ on: types: [ opened, synchronize ] jobs: - php: - name: PHP + phpcs: + name: phpcs runs-on: ubuntu-latest steps: From 9e1cb645d99e41609e75d56fea78a1c6e5c48f53 Mon Sep 17 00:00:00 2001 From: Paulo Pinto Date: Fri, 16 Feb 2024 15:03:58 +0000 Subject: [PATCH 21/22] Extract delete logic to a function --- assets/js/translation-events.js | 45 +++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/assets/js/translation-events.js b/assets/js/translation-events.js index 5efd5539..608f282f 100644 --- a/assets/js/translation-events.js +++ b/assets/js/translation-events.js @@ -18,26 +18,13 @@ } ); - $('.delete-event').on('click', function(e) { - e.preventDefault(); - if ( ! confirm( 'Are you sure you want to delete this event?' ) ) { - return; + $('.delete-event').on( + 'click', + function ( e ) { + e.preventDefault(); + handleDelete() } - const $form = $('.translation-event-form'); - $('#form-name').val('delete_event'); - $('#event-form-action').val('delete'); - $.ajax({ - type: 'POST', - url: $translation_event.url, - data:$form.serialize(), - success: function(response) { - window.location = response.data.eventDeleteUrl; - }, - error: function(error) { - $gp.notices.error(response.data.message); - }, - }); - }); + ); } ); @@ -89,6 +76,26 @@ ); } + function handleDelete() { + if ( ! confirm( 'Are you sure you want to delete this event?' ) ) { + return; + } + const $form = $('.translation-event-form'); + $('#form-name').val('delete_event'); + $('#event-form-action').val('delete'); + $.ajax({ + type: 'POST', + url: $translation_event.url, + data:$form.serialize(), + success: function(response) { + window.location = response.data.eventDeleteUrl; + }, + error: function(error) { + $gp.notices.error(response.data.message); + }, + }); + } + function validateEventDates() { const startDateTimeInput = $('#event-start'); const endDateTimeInput = $('#event-end'); From 33c168bce7507d1f0da26a6abf0f9e263368040f Mon Sep 17 00:00:00 2001 From: Paulo Pinto Date: Fri, 16 Feb 2024 15:10:42 +0000 Subject: [PATCH 22/22] Fix formatting --- assets/css/translation-events.css | 4 +- assets/js/translation-events.js | 82 ++++++++++++++++--------------- 2 files changed, 44 insertions(+), 42 deletions(-) diff --git a/assets/css/translation-events.css b/assets/css/translation-events.css index 5a7337c6..5c43f767 100644 --- a/assets/css/translation-events.css +++ b/assets/css/translation-events.css @@ -70,8 +70,8 @@ span.event-list-date { font-weight: bold; } span.event-list-date.events-i-am-attending { - font-size: .8em; - font-weight: normal; + font-size: .8em; + font-weight: normal; } .event-list-item a{ font-weight: bold; diff --git a/assets/js/translation-events.js b/assets/js/translation-events.js index 608f282f..51e7fdcd 100644 --- a/assets/js/translation-events.js +++ b/assets/js/translation-events.js @@ -18,7 +18,7 @@ } ); - $('.delete-event').on( + $( '.delete-event' ).on( 'click', function ( e ) { e.preventDefault(); @@ -41,36 +41,36 @@ } } $( '#event-form-action' ).val( btnClicked ); - const $form = $( '.translation-event-form' ); - const $is_creation = $('#form-name').val() === 'create_event'; + const $form = $( '.translation-event-form' ); + const $is_creation = $( '#form-name' ).val() === 'create_event'; $.ajax( { type: 'POST', url: $translation_event.url, data:$form.serialize(), - success: function(response) { + success: function ( response ) { if ( response.data.eventId ) { history.replaceState( '', '', response.data.eventEditUrl ); - $('#form-name').val('edit_event'); - $('.event-page-title').text('Edit Event'); - $('#event-id').val(response.data.eventId); - if( btnClicked === 'publish' ) { - $('button[data-event-status="draft"]').hide(); - $('button[data-event-status="publish"]').text('Update Event'); + $( '#form-name' ).val( 'edit_event' ); + $( '.event-page-title' ).text( 'Edit Event' ); + $( '#event-id' ).val( response.data.eventId ); + if ( btnClicked === 'publish' ) { + $( 'button[data-event-status="draft"]' ).hide(); + $( 'button[data-event-status="publish"]' ).text( 'Update Event' ); } - if( btnClicked === 'draft' ) { - $('button[data-event-status="draft"]').text('Update Draft'); + if ( btnClicked === 'draft' ) { + $( 'button[data-event-status="draft"]' ).text( 'Update Draft' ); } - $('#event-url').removeClass('hide-event-url').find('a').attr('href', response.data.eventUrl).text(response.data.eventUrl); + $( '#event-url' ).removeClass( 'hide-event-url' ).find( 'a' ).attr( 'href', response.data.eventUrl ).text( response.data.eventUrl ); if ( $is_creation ) { - $('#delete-button').toggle(); + $( '#delete-button' ).toggle(); } - $gp.notices.success(response.data.message); + $gp.notices.success( response.data.message ); } }, - error: function(error) { - $gp.notices.error(response.data.message); + error: function ( error ) { + $gp.notices.error( response.data.message ); } } ); @@ -80,25 +80,27 @@ if ( ! confirm( 'Are you sure you want to delete this event?' ) ) { return; } - const $form = $('.translation-event-form'); - $('#form-name').val('delete_event'); - $('#event-form-action').val('delete'); - $.ajax({ - type: 'POST', - url: $translation_event.url, - data:$form.serialize(), - success: function(response) { - window.location = response.data.eventDeleteUrl; - }, - error: function(error) { - $gp.notices.error(response.data.message); - }, - }); + const $form = $( '.translation-event-form' ); + $( '#form-name' ).val( 'delete_event' ); + $( '#event-form-action' ).val( 'delete' ); + $.ajax( + { + type: 'POST', + url: $translation_event.url, + data:$form.serialize(), + success: function ( response ) { + window.location = response.data.eventDeleteUrl; + }, + error: function ( error ) { + $gp.notices.error( response.data.message ); + }, + } + ); } function validateEventDates() { - const startDateTimeInput = $('#event-start'); - const endDateTimeInput = $('#event-end'); + const startDateTimeInput = $( '#event-start' ); + const endDateTimeInput = $( '#event-end' ); if ( ! startDateTimeInput.length || ! endDateTimeInput.length ) { return; } @@ -106,9 +108,9 @@ startDateTimeInput.add( endDateTimeInput ).on( 'input', function () { - endDateTimeInput.prop('min', startDateTimeInput.val()); + endDateTimeInput.prop( 'min', startDateTimeInput.val() ); if (endDateTimeInput.val() < startDateTimeInput.val()) { - endDateTimeInput.val(startDateTimeInput.val()); + endDateTimeInput.val( startDateTimeInput.val() ); } } ); @@ -122,16 +124,16 @@ } function convertToUserLocalTime() { - const timeElements = document.querySelectorAll('time.event-utc-time'); + const timeElements = document.querySelectorAll( 'time.event-utc-time' ); if ( timeElements.length === 0 ) { return; } timeElements.forEach( function ( timeEl ) { - const eventDateObj = new Date( timeEl.getAttribute('datetime') ); - const userTimezoneOffset = new Date().getTimezoneOffset(); + const eventDateObj = new Date( timeEl.getAttribute( 'datetime' ) ); + const userTimezoneOffset = new Date().getTimezoneOffset(); const userTimezoneOffsetMs = userTimezoneOffset * 60 * 1000; - const userLocalDateTime = new Date(eventDateObj.getTime() - userTimezoneOffsetMs); + const userLocalDateTime = new Date( eventDateObj.getTime() - userTimezoneOffsetMs ); const options = { weekday: 'short', @@ -144,7 +146,7 @@ timeZoneName: 'short' }; - timeEl.textContent = userLocalDateTime.toLocaleString('en-US', options); + timeEl.textContent = userLocalDateTime.toLocaleString( 'en-US', options ); } ); }