Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
psrpinto committed Feb 16, 2024
1 parent 9e1cb64 commit 33c168b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 42 deletions.
4 changes: 2 additions & 2 deletions assets/css/translation-events.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
82 changes: 42 additions & 40 deletions assets/js/translation-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
);

$('.delete-event').on(
$( '.delete-event' ).on(
'click',
function ( e ) {
e.preventDefault();
Expand All @@ -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 );
}
}
);
Expand All @@ -80,35 +80,37 @@
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;
}

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() );
}
}
);
Expand All @@ -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',
Expand All @@ -144,7 +146,7 @@
timeZoneName: 'short'
};

timeEl.textContent = userLocalDateTime.toLocaleString('en-US', options);
timeEl.textContent = userLocalDateTime.toLocaleString( 'en-US', options );
}
);
}
Expand Down

0 comments on commit 33c168b

Please sign in to comment.