// Add extra functionality to the online event selector in the Event editor
if ($('body').attr('id') == 'events_edit') {
function lockLocation(){
$('.places-remove').click(); // remove location map if one was added
$('#places_location').prop('readonly',true).css({'opacity':'.5','pointer-events':'none'}); // disable location field
$('.places-add-new-checkbox').prop('disabled',true); // disable new location checkbox
$('.places-select-existing, .places-options .checkbox').addClass('disabled'); // disable all locations button
};
function unlockLocation(){
$('#places_location').prop('readonly',false).css({'opacity':'','pointer-events':''}); // enable location field
$('.places-add-new-checkbox').prop('disabled',false); // enable new location checkbox
$('.places-select-existing, .places-options .checkbox').removeClass('disabled'); // enable all locations button
};
$(window).on('load',function(){
// If loading an event with the online event box checked and the online only option chosen
if ( $('#is_online').prop('checked') && $('[name="online_type"]:checked').val() == 1 ) {
lockLocation(); // just lock the location fields (location should have already been saved as "virtual")
}
})
$('#is_online').on('change',function(){
// when the online event checkbox is checked and online type is not 2 (hybrid)
if ( $('#is_online').prop('checked') && $('[name="online_type"]:checked').val() != 2 ) {
$('#places_location').val('Virtual'); // set the location field to "Virtual"
lockLocation(); // and lock the location fields
}
// otherwise, means the online checkbox was unchecked OR hybrid is chosen
else {
if ($('#places_location').val() == 'Virtual') {
$('#places_location').val(''); // if location field has a value of "virtual", clear it
}
unlockLocation(); // unlock the location fields
}
});
$('[name="online_type"]').on('change',function(){
// when the online type option is set to online only
if ( $('[name="online_type"]:checked').val() == 1 ) {
$('#places_location').val('Virtual'); // set the location field to "Virtual"
lockLocation(); // and lock the location fields
}
// otherwise, means it is set to hybrid
else {
if ($('#places_location').val() == 'Virtual') {
$('#places_location').val(''); // if location field has a value of "virtual", clear it
}
unlockLocation(); // unlock the location fields
}
});
}