Created
November 9, 2017 12:01
-
-
Save Mantus667/a05a70e7606934982a4fb415584d8d5a to your computer and use it in GitHub Desktop.
Rendering a calendar in a partial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@using EventCalendar.Core; | |
@using EventCalendar.Core.CQRS.Query.Calendar; | |
@using EventCalendar.Core.CQRS.QueryResult.Calendar; | |
@using EventCalendar.Core.Interfaces.Query; | |
@{ | |
var queryDispatcher = EventCalendarServiceContainer.GetService<IQueryDispatcher>(); | |
var result = queryDispatcher.Dispatch<GetCalendarSourcesQuery, GetCalendarSourcesQueryResult>( | |
new GetCalendarSourcesQuery { CalendarId = Convert.ToInt32("the id of the calendar or 0"), Culture = CultureInfo.CurrentCulture.ToString() } | |
); | |
} | |
@Html.AntiForgeryToken() | |
<div class="container"> | |
<div id="calendar"></div> | |
</div> | |
<script type="text/javascript"> | |
var event_details_url = '"".EnsureEndsWith("/")'; | |
$(document).ready(function () { | |
var csrfToken = $("input[name='__RequestVerificationToken']").val(); | |
var sources = @Html.Raw(Json.Encode(result.Sources)); | |
$.each(sources, function (key, data) { | |
data.headers = { "X-XSRF-Token": csrfToken }; | |
}); | |
$('#calendar').fullCalendar({ | |
defaultView: '@(result.Sources.Count == 1 ? ((dynamic)result.Sources.First()).view : "month")', | |
header: { | |
left: 'prev,next today', | |
center: 'title', | |
right: 'month,basicWeek,basicDay' | |
}, | |
lang: '@CultureInfo.CurrentCulture.TwoLetterISOLanguageName.ToLower()', | |
eventSources: sources, | |
eventClick: function (event) { | |
if(event.source.googleCalendarId != null){ | |
window.location.href = event_details_url + event.title + '/' + event.source.googleCalendarId + '/' + event.id; | |
return false; | |
} | |
else if (event.url) { | |
window.open(event.url); | |
return false; | |
} else { | |
window.location.href = event_details_url + event.title + '/' + event.id; | |
return false; | |
} | |
}, | |
eventRender: function (event, element) { | |
if (event.end != null) { | |
element.qtip({ | |
content: { | |
text: "<h2>" + event.title + "</h2><h5>Start: " + event.start.format('llll') + "</h5><h5>End: " + event.end.format('llll') + "</h5><div>" + event.excerpt + "</div>", | |
title: event.title | |
}, | |
style: "qtip-blue" | |
}); | |
} else { | |
element.qtip({ | |
content: { | |
text: "<h2>" + event.title + "</h2><h5>Start: " + event.start.format('llll') + "</h5><div>" + event.excerpt + "</div>", | |
title: event.title | |
}, | |
style: "qtip-blue" | |
}); | |
} | |
} | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment