Skip to content

Commit

Permalink
Update recurring pattern is dates edited
Browse files Browse the repository at this point in the history
If dates are changed, recurring pattern also needs to be updated. Auto toggle open on change to ensure this happens.
  • Loading branch information
joedolson committed Nov 7, 2021
1 parent 7479ff0 commit db7fd11
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/includes/general-utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function mc_add_inner_box() {
$url = admin_url( 'admin.php?page=my-calendar&mode=edit&event_id=' . $event_id );
$event = mc_get_first_event( $event_id );
$content = '<p><strong>' . strip_tags( $event->event_title, mc_strip_tags() ) . '</strong><br />' . $event->event_begin . ' @ ' . $event->event_time . '</p>';
if ( ! ( 'S' === $event->event_recur || 'S1' === $event->event_recur ) ) {
if ( ! mc_is_recurring( $event ) ) {
$recur = mc_event_recur_string( $event, $event->event_begin );
$content .= wpautop( $recur );
}
Expand Down
7 changes: 7 additions & 0 deletions src/js/jquery.admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ jQuery(document).ready(function ($) {
}
});

$( '#e_schedule' ).on( 'change', 'input', function() {
recurrences.find( 'fieldset' ).show();
recurrences.find( '.enable-repetition' ).attr( 'aria-expanded', 'true' );
recurrences.find( '.enable-repetition .dashicons' ).addClass( 'dashicons-arrow-down' ).removeClass( 'dashicons-arrow-right' );
recurrences.find( 'fieldset input, fieldset select, fieldset duet-date-picker' ).prop( 'disabled', false );
});

var addLocations = document.querySelector( '.add-location' );
if ( null !== addLocations ) {
var locationSelector = document.getElementById( 'l_preset' );
Expand Down
32 changes: 29 additions & 3 deletions src/js/mc-datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ const eventEnd = document.querySelector( 'duet-date-picker[identifier=mc_e
const eventDateError = document.querySelector( '#event_date_error' );
const submitButton = document.querySelector( '#my-calendar .button-primary' );

var startDate = false;
var endDate = false;
var startDate = false;
var endDate = false;
var recurrences = document.querySelector( '.disable-recurrences' );

if ( null !== eventRecur ) {
eventRecur.addEventListener( 'duetChange', function(e) {
Expand All @@ -34,7 +35,6 @@ if ( null !== eventRecur ) {
});
}


eventBegin.addEventListener( 'duetChange', function(e) {
startDate = e.detail.value;
endValue = document.querySelector( 'input[name="event_end[]"]' ).value;
Expand All @@ -45,13 +45,39 @@ eventBegin.addEventListener( 'duetChange', function(e) {
endDate.value = e.detail.value;
}

if ( null !== recurrences ) {
var fieldset = recurrences.querySelector( 'fieldset' );
fieldset.setAttribute( 'style', '' );
recurrences.querySelector( '.enable-repetition' ).setAttribute( 'aria-expanded', 'true' );
var icon = recurrences.querySelector( '.dashicons' );
icon.classList.add( 'dashicons-arrow-down' );
icon.classList.remove( 'dashicons-arrow-right' );
var inputs = recurrences.querySelectorAll( 'fieldset input, fieldset select, fieldset duet-date-picker' );
inputs.forEach((input) => {
input.disabled = false;
});
}

myCalendarTestDates( endDate, startDate );
});

eventEnd.addEventListener( 'duetChange', function(e) {
endDate = e.detail.value;
startDate = document.querySelector( 'input[name="event_begin[]"]' ).value;

if ( null !== recurrences ) {
var fieldset = recurrences.querySelector( 'fieldset' );
fieldset.setAttribute( 'style', '' );
recurrences.querySelector( '.enable-repetition' ).setAttribute( 'aria-expanded', 'true' );
var icon = recurrences.querySelector( '.dashicons' );
icon.classList.add( 'dashicons-arrow-down' );
icon.classList.remove( 'dashicons-arrow-right' );
var inputs = recurrences.querySelectorAll( 'fieldset input, fieldset select, fieldset duet-date-picker' );
inputs.forEach((input) => {
input.disabled = false;
});
}

myCalendarTestDates( endDate, startDate );
});

Expand Down
5 changes: 4 additions & 1 deletion src/my-calendar-event-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,7 @@ function mc_show_block( $field, $has_data, $data, $echo = true, $default = '', $
$class = '';
if ( $has_data && false !== mc_admin_instances( $data->event_id ) ) {
$class = 'disable-recurrences';
$warning = '<div class="recurrences-disabled"><p><span>' . __( 'Editing the repetition pattern will remove and recreate all scheduled dates for this event.', 'my-calendar' ) . '</span><button type="button" class="button enable-repetition" aria-expanded="false"><span class="dashicons dashicons-arrow-right" aria-hidden="true"></span>' . __( 'Edit Repetition Pattern', 'my-calendar' ) . '</button></p></div>';
$warning = '<div class="recurrences-disabled"><p><span>' . __( 'Editing the repetition pattern will regenerate scheduled dates for this event.', 'my-calendar' ) . '</span><button type="button" class="button enable-repetition" aria-expanded="false"><span class="dashicons dashicons-arrow-right" aria-hidden="true"></span>' . __( 'Edit Repetition Pattern', 'my-calendar' ) . '</button></p></div>';
}
$args = array(
'value' => $repeats,
Expand Down Expand Up @@ -1662,6 +1662,9 @@ function mc_form_fields( $data, $mode, $event_id ) {
<input type="hidden" name="prev_event_end" value="<?php echo esc_attr( $data->event_end ); ?>"/>
<input type="hidden" name="prev_event_endtime" value="<?php echo esc_attr( $data->event_endtime ); ?>"/>
<?php
if ( mc_is_recurring( $data ) ) {
echo '<p><span>' . esc_html__( 'Editing dates and times will regenerate recurring dates for this event.', 'my-calendar' ) . '</span></p>';
}
}
?>
<fieldset class="datetime">
Expand Down
15 changes: 14 additions & 1 deletion src/my-calendar-output.php
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,19 @@ function mc_date_relation( $event ) {
return $date_relation;
}

/**
* Determine whether an event is recurring.
*
* @param object $event Event object.
*
* @return bool
*/
function mc_is_recurring( $event ) {
$is_recurring = ( ! ( 'S' === $event->event_recur || 'S1' === $event->event_recur ) ) ? true : false;

return $is_recurring;
}

/**
* Generate classes for a given event
*
Expand All @@ -784,7 +797,7 @@ function mc_event_classes( $event, $type ) {
}
$primary = 'mc_primary_' . sanitize_title( mc_get_category_detail( $event->event_category, 'category_name' ) );

$is_recurring = ( ! ( 'S' === $event->event_recur || 'S1' === $event->event_recur ) ) ? 'recurring' : 'nonrecurring';
$is_recurring = ( mc_is_recurring( $event ) ) ? 'recurring' : 'nonrecurring';

$classes = array(
'mc-' . $uid,
Expand Down

0 comments on commit db7fd11

Please sign in to comment.