Skip to content

Instantly share code, notes, and snippets.

@siegy22
Created January 16, 2017 16:44
Show Gist options
  • Save siegy22/46aad81e20f7ee0ee78c4009c2cb850d to your computer and use it in GitHub Desktop.
Save siegy22/46aad81e20f7ee0ee78c4009c2cb850d to your computer and use it in GitHub Desktop.
$(document).on("turbolinks:load", function(){
var availableTimesPath = "<%= Rails.application.routes.url_helpers.pastor_me_available_times_path %>";
$('#calendar').fullCalendar({
selectable: true,
selectHelper: true,
header: {
left: 'prev,next',
center: 'title',
right: 'month,agendaWeek'
},
select: function(start, end, resource, x, y) {
var allDay = (!start.hasTime() && !end.hasTime());
$.post(availableTimesPath, {
available_time: {
start: start.toDate(),
end: end.toDate(),
all_day: allDay
}
}, function(data){
$('#calendar').fullCalendar('renderEvent', data, true);
});
},
eventClick: function(calEvent, jsEvent, view) {
$("#confirm-deletion").data("event-id", calEvent.id)
$.blockUI({
message: $('#confirm-deletion'),
css: {
border: "none",
padding: "8px"
}
});
}
});
if ($("#calendar").length) {
// Initial loading of all events
$.getJSON(availableTimesPath, function(data){
$.each(data, function(_key, item){
item.start = moment(item.start);
item.end = moment(item.end);
$('#calendar').fullCalendar('renderEvent', item, true);
});
});
}
$("#confirm-deletion #yes").click(function(){
var id = $(this).parent().data("event-id");
$.ajax({
url: availableTimesPath + "/" + id,
type: "DELETE",
success: function(){
$('#calendar').fullCalendar('removeEvents', id);
$.unblockUI();
}
});
});
$("#confirm-deletion #no").click(function(){
$.unblockUI();
});
// Override fullcalendar styles with bootstrap ones
$('.fc-toolbar').find('.fc-button-group').attr('class', 'btn-group');
$('.fc-toolbar').find('.fc-button').attr('class', 'btn btn-default');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment