Created
November 21, 2017 11:51
-
-
Save Mantus667/ec5e5a2e914cd2983af7058aae75f641 to your computer and use it in GitHub Desktop.
Calendar macro code
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; | |
@using System.Globalization | |
@using Umbraco.Web.Extensions | |
@inherits Umbraco.Web.Macros.PartialViewMacroPage | |
@{ | |
Udi parsedUdi; | |
if (!Udi.TryParse(Model.MacroParameters["detailPage"].ToString(), out parsedUdi)) | |
{ | |
@Html.Raw("<p>Detail page couldn't be parsed - aborting</p>") | |
return; | |
} | |
var detailPage = parsedUdi.ToPublishedContent(); | |
var queryDispatcher = EventCalendarServiceContainer.GetService<IQueryDispatcher>(); | |
var result = queryDispatcher.Dispatch<GetCalendarSourcesQuery, GetCalendarSourcesQueryResult>( | |
new GetCalendarSourcesQuery { CalendarId = Convert.ToInt32(Model.MacroParameters["calendar"]), Culture = CultureInfo.CurrentCulture.ToString() } | |
); | |
} | |
@Html.AntiForgeryToken() | |
<div class="container"> | |
<div id="calendar"></div> | |
</div> | |
<script type="text/javascript"> | |
var event_details_url = '@detailPage.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