Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Datepair.js and jquery-timepicker for selecting time ranges #308

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions css/jquery.timepicker.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
.ui-timepicker-wrapper {
overflow-y: auto;
height: 150px;
width: 6.5em;
background: #fff;
border: 1px solid #ddd;
-webkit-box-shadow:0 5px 10px rgba(0,0,0,0.2);
-moz-box-shadow:0 5px 10px rgba(0,0,0,0.2);
box-shadow:0 5px 10px rgba(0,0,0,0.2);
outline: none;
z-index: 10001;
margin: 0;
}

.ui-timepicker-wrapper.ui-timepicker-with-duration {
width: 13em;
}

.ui-timepicker-wrapper.ui-timepicker-with-duration.ui-timepicker-step-30,
.ui-timepicker-wrapper.ui-timepicker-with-duration.ui-timepicker-step-60 {
width: 11em;
}

.ui-timepicker-list {
margin: 0;
padding: 0;
list-style: none;
}

.ui-timepicker-duration {
margin-left: 5px; color: #888;
}

.ui-timepicker-list:hover .ui-timepicker-duration {
color: #888;
}

.ui-timepicker-list li {
padding: 3px 0 3px 5px;
cursor: pointer;
white-space: nowrap;
color: #000;
list-style: none;
margin: 0;
}

.ui-timepicker-list:hover .ui-timepicker-selected {
background: #fff; color: #000;
}

li.ui-timepicker-selected,
.ui-timepicker-list li:hover,
.ui-timepicker-list .ui-timepicker-selected:hover {
background: #1980EC; color: #fff;
}

li.ui-timepicker-selected .ui-timepicker-duration,
.ui-timepicker-list li:hover .ui-timepicker-duration {
color: #ccc;
}

.ui-timepicker-list li.ui-timepicker-disabled,
.ui-timepicker-list li.ui-timepicker-disabled:hover,
.ui-timepicker-list li.ui-timepicker-selected.ui-timepicker-disabled {
color: #888;
cursor: default;
}

.ui-timepicker-list li.ui-timepicker-disabled:hover,
.ui-timepicker-list li.ui-timepicker-selected.ui-timepicker-disabled {
background: #f2f2f2;
}
120 changes: 68 additions & 52 deletions includes/event-organiser-register.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ function eventorganiser_register_script() {
$ext = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
$rtl = is_rtl() ? '-rtl' : '';

/* Moment.js */
/* Moment.js */
wp_register_script( 'eo_momentjs', EVENT_ORGANISER_URL."js/moment{$ext}.js", '2.9.0', true );

/* FullCalendar */
wp_register_script( 'eo_fullcalendar', EVENT_ORGANISER_URL."js/fullcalendar{$ext}.js",array(
'jquery',
Expand All @@ -25,11 +25,11 @@ function eventorganiser_register_script() {
'jquery-ui-widget',
'jquery-ui-button',
),$version,true);

/* Google Maps */
$protocal = is_ssl() ? 'https://' : 'http://';
wp_register_script( 'eo_GoogleMap', $protocal.'maps.googleapis.com/maps/api/js?sensor=false&language='.substr( get_locale(), 0, 2 ) );

/* Front-end script */
wp_register_script( 'eo_front', EVENT_ORGANISER_URL."js/frontend{$ext}.js",array(
'jquery','eo_qtip2',
Expand All @@ -40,7 +40,7 @@ function eventorganiser_register_script() {
'eo_fullcalendar',
'eo-wp-js-hooks',
),$version,true);

/* Add js variables to frontend script */
$category = get_taxonomy( 'event-category' );
$venue = get_taxonomy( 'event-venue' );
Expand Down Expand Up @@ -72,14 +72,14 @@ function eventorganiser_register_script() {

/* WP-JS-Hooks */
wp_register_script( 'eo-wp-js-hooks', EVENT_ORGANISER_URL."js/event-manager{$ext}.js",array('jquery'),$version,true);

/* Q-Tip */
wp_register_script( 'eo_qtip2', EVENT_ORGANISER_URL.'js/qtip2.js',array('jquery'),$version,true);

/* Styles */
eo_register_style( 'eo_calendar-style', EVENT_ORGANISER_URL . "css/fullcalendar{$ext}.css", array(), $version );
eo_register_style( 'eo_front', EVENT_ORGANISER_URL . "css/eventorganiser-front-end{$rtl}{$ext}.css", array() , $version );
}
}
add_action( 'init', 'eventorganiser_register_script' );

/**
Expand All @@ -99,37 +99,47 @@ function eventorganiser_register_scripts(){
'jquery',
'eo_GoogleMap'
),$version,true);

/* Venue script for venue edit */
wp_register_script( 'eo-venue-admin', EVENT_ORGANISER_URL."js/venue-admin{$ext}.js",array(
'jquery',
'eo-venue-util'
),$version,true);

/* Script for event edit page. (Legacy version) */
wp_register_script( 'eo-time-picker', EVENT_ORGANISER_URL."js/time-picker{$ext}.js",array(

/**
* jquery-timepicker
*
* @license MIT
* @link https://github.com/jonthornton/jquery-timepicker
*/
wp_register_script( 'eo-timepicker', EVENT_ORGANISER_URL . "js/jquery.timepicker{$ext}.js", array(
'jquery',
'jquery-ui-datepicker',
),$version,true);

/* New version - prefixed timepicker */
wp_register_script( 'eo-timepicker', EVENT_ORGANISER_URL."js/jquery-ui-eo-timepicker{$ext}.js",array(
), $version, true );

/**
* Datepair.js
*
* @license MIT
* @link https://github.com/jonthornton/Datepair.js
*/
wp_register_script( 'eo-datepair', EVENT_ORGANISER_URL . "js/datepair{$ext}.js", array(), $version, true );
wp_register_script( 'eo-jquery-datepair', EVENT_ORGANISER_URL . "js/jquery.datepair{$ext}.js", array(
'eo-datepair',
'jquery',
'jquery-ui-datepicker',
),$version,true);

), $version, true );

wp_register_script( 'eo_event', EVENT_ORGANISER_URL."js/event{$ext}.js",array(
'jquery',
'jquery-ui-datepicker',
'eo-timepicker',
'eo-time-picker',//Deprecated remove in 3.0?
'eo-jquery-datepair',
'eo-venue-util',
'jquery-ui-autocomplete',
'jquery-ui-widget',
'jquery-ui-button',
'jquery-ui-position',
),$version,true);

wp_register_script( 'eo-edit-event-controller', EVENT_ORGANISER_URL."js/edit-event-controller{$ext}.js",array(
'jquery',
'eo_event',
Expand All @@ -149,9 +159,15 @@ function eventorganiser_register_scripts(){

/* Pick and register jQuery UI style */
wp_register_style( 'eventorganiser-jquery-ui-style', EVENT_ORGANISER_URL."css/eventorganiser-jquery-ui{$rtl}{$ext}.css", array(), $version );


// Timepicker CSS
wp_register_style( 'eo-timepicker', EVENT_ORGANISER_URL . "css/jquery.timepicker{$ext}.css", array(), $version );

/* Admin styling */
wp_register_style( 'eventorganiser-style', EVENT_ORGANISER_URL."css/eventorganiser-admin-style{$rtl}{$ext}.css", array( 'eventorganiser-jquery-ui-style' ), $version );
wp_register_style( 'eventorganiser-style', EVENT_ORGANISER_URL."css/eventorganiser-admin-style{$rtl}{$ext}.css", array(
'eventorganiser-jquery-ui-style',
'eo-timepicker'
), $version );

/* Inline Help */
wp_register_script( 'eo-inline-help', EVENT_ORGANISER_URL.'js/inline-help.js',array( 'jquery', 'eo_qtip2' ), $version, true );
Expand All @@ -176,9 +192,9 @@ function eventorganiser_cgmp_workaround(){
remove_action( 'wp_head', 'cgmp_google_map_deregister_scripts', 200 );
}
add_action( 'wp_head', 'eventorganiser_cgmp_workaround', 1 );

/**
* Check the export and event creation (from Calendar view) actions.
* Check the export and event creation (from Calendar view) actions.
* These cannot be called later. Most other actions are only called when
* the appropriate page is loading.
*
Expand Down Expand Up @@ -206,7 +222,7 @@ function eventorganiser_public_export(){
add_action('init','eventorganiser_public_export');

/**
* Queues up the javascript / style scripts for Events custom page type
* Queues up the javascript / style scripts for Events custom page type
* Hooked onto admin_enqueue_scripts
*
* @since 1.0.0
Expand All @@ -217,10 +233,10 @@ function eventorganiser_add_admin_scripts( $hook ) {
global $post,$current_screen,$wp_locale;

if ( $hook == 'post-new.php' || $hook == 'post.php') {
if( $post->post_type == 'event' ) {
if( $post->post_type == 'event' ) {

wp_enqueue_script( 'eo-edit-event-controller' );
wp_localize_script( 'eo_event', 'EO_Ajax_Event', array(
wp_localize_script( 'eo_event', 'EO_Ajax_Event', array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'wpversion' => get_bloginfo( 'version' ),
'startday' => intval( get_option( 'start_of_week' ) ),
Expand Down Expand Up @@ -278,7 +294,7 @@ function eventorganiser_add_admin_scripts( $hook ) {


/**
* Perform database and WP version checks. Display appropriate error messages.
* Perform database and WP version checks. Display appropriate error messages.
* Triggered on update.
*
* @since 1.4.0
Expand Down Expand Up @@ -314,7 +330,7 @@ function eventorganiser_db_checks(){
<div class="error" >
<p>Event Organiser requires <strong>WordPress 3.8</strong> to function properly. Your version is <?php echo get_bloginfo('version'); ?>. </p>
</div>
<?php endif;
<?php endif;
}


Expand Down Expand Up @@ -359,7 +375,7 @@ function eventorganiser_admin_notices(){
* @access private
*/
function eventorganiser_plugin_settings_link($links, $file) {

if( $file == 'event-organiser/event-organiser.php' ) {
/* Insert the link at the end*/
$links['settings'] = sprintf('<a href="%s"> %s </a>',
Expand All @@ -369,7 +385,7 @@ function eventorganiser_plugin_settings_link($links, $file) {
}
return $links;
}
add_filter('plugin_action_links', 'eventorganiser_plugin_settings_link', 10, 2);
add_filter('plugin_action_links', 'eventorganiser_plugin_settings_link', 10, 2);

/**
* Schedules cron job for automatically deleting expired events
Expand Down Expand Up @@ -423,35 +439,35 @@ function eventorganiser_get_next_cron_time( $cron_name ){
function eventorganiser_delete_expired_events(){
//Get expired events
$events = eo_get_events(array('showrepeats'=>0,'showpastevents'=>1,'eo_interval'=>'expired'));

/**
* Filters how long (in seconds) after an event as finished it should be considered expired.
*
*
* If enabled in *Settings > Event Organiser > General*, expired events are trashed.
*
* @param int $time_until_expired Time (in seconds) to wait after an event has finished. Defaults to 24 hours.
*
* @param int $time_until_expired Time (in seconds) to wait after an event has finished. Defaults to 24 hours.
*/
$time_until_expired = (int) apply_filters( 'eventorganiser_events_expire_time', 24*60*60 );
$time_until_expired = max( $time_until_expired, 0 );

if($events):
$now = new DateTime('now', eo_get_blog_timezone());

foreach($events as $event):

$start = eo_get_the_start( DATETIMEOBJ, $event->ID, null, $event->occurrence_id );
$end = eo_get_the_end( DATETIMEOBJ, $event->ID, null, $event->occurrence_id );

$expired = round(abs($end->format('U')-$start->format('U'))) + $time_until_expired; //Duration + expire time

$finished = eo_get_schedule_last( DATETIMEOBJ, $event->ID );
$finished->modify("+$expired seconds");//[Expired time] after the last occurrence finishes

//Delete if [expired time] has passed
if( $finished <= $now ){
wp_trash_post((int) $event->ID);
}

endforeach;
endif;
}
Expand Down Expand Up @@ -492,7 +508,7 @@ function eventorganiser_admin_print_scripts() {
add_action( 'admin_print_styles', 'eventorganiser_admin_print_scripts' );


/**
/**
* Purge the occurrences cache
* Hooked onto eventorganiser_save_event and eventorganiser_delete_event
*
Expand Down Expand Up @@ -533,7 +549,7 @@ function _eventorganiser_delete_calendar_cache() {
$hooks = array(
'eventorganiser_save_event', 'eventorganiser_delete_event', 'wp_trash_post','update_option_gmt_offset', /* obvious */
'update_option_start_of_week', /* Start of week is used for calendars */
'update_option_rewrite_rules', /* If permalinks updated - links on fullcalendar might now be invalid */
'update_option_rewrite_rules', /* If permalinks updated - links on fullcalendar might now be invalid */
'delete_option_rewrite_rules',
'update_option_siteurl',
'update_option_home',
Expand Down Expand Up @@ -588,16 +604,16 @@ function eventorganiser_pointer_load( $hook_suffix ) {
}

//No valid pointers? Stop here.
if( empty($valid_pointers) )
if( empty($valid_pointers) )
return;

// Add pointers style to queue.
// Add pointers style to queue.
wp_enqueue_style( 'wp-pointer' );

// Add pointers script to queue. Add custom script.
wp_enqueue_script('eventorganiser-pointer',EVENT_ORGANISER_URL.'js/eventorganiser-pointer.js',array('wp-pointer','eo_event'));

// Add pointer options to script.
// Add pointer options to script.
wp_localize_script('eventorganiser-pointer', 'eventorganiserPointer', $valid_pointers);
}
add_action( 'admin_enqueue_scripts', 'eventorganiser_pointer_load',99999);
Expand Down Expand Up @@ -630,7 +646,7 @@ function _eventorganiser_upgrade_admin_notice() {

$message = sprintf(
"<h4>" . sprintf( esc_html__('Your site timezone is %s','eventorganiser'), "<em>{$tzstring}</em>" ). '</h4>'
."<p>" . __( "Is this correct? Using a fixed offset from UTC may cause unexpected behaviour, particular if you observe Daylight Savings Time.", 'eventorganiser' ) . '<br>'
."<p>" . __( "Is this correct? Using a fixed offset from UTC may cause unexpected behaviour, particular if you observe Daylight Savings Time.", 'eventorganiser' ) . '<br>'
.__( "It is strongly recommended you select a city instead, even if you don't observe Daylight Savings Time.",'eventorganiser') . '</p>'
."<p>" . __( "You can <a href='%s'>change your timezone settings here</a>.",'eventorganiser') . '</p>',
admin_url( 'options-general.php' ).'#default_role'
Expand All @@ -645,7 +661,7 @@ function _eventorganiser_upgrade_admin_notice() {
* Handles city auto-fill request.
*
* Hooked onto admin_post_eo-autofillcity. Triggered when user clicks 'autofill' link.
* This routine goes through all the venues, reverse geocodes to find their city and
* This routine goes through all the venues, reverse geocodes to find their city and
* autofills the city field (added in 1.7).
*
*@ignore
Expand All @@ -671,7 +687,7 @@ function _eventorganiser_autofill_city(){
If( eo_get_venue_meta($venue_id,'_city',true) )
continue;

$response=wp_remote_get("http://open.mapquestapi.com/nominatim/v1/reverse?format=json&lat={$lat}&lon={$lng}&osm_type=N&limit=1");
$response=wp_remote_get("http://open.mapquestapi.com/nominatim/v1/reverse?format=json&lat={$lat}&lon={$lng}&osm_type=N&limit=1");
$geo = json_decode(wp_remote_retrieve_body( $response ));
if( isset($geo->address->city) ){
$cities[$venue_id] = $geo->address->city;
Expand All @@ -689,7 +705,7 @@ function _eventorganiser_autofill_city(){
eo_update_venue_meta($venue_id, '_state', $geo->address->state);
}
}
}
}

wp_safe_redirect(admin_url('edit.php?post_type=event&page=venues'));
}
Expand Down
Loading