Make link to calendar view bookable (#3063)

This commit is contained in:
Konstantin
2017-02-24 07:38:08 +09:00
committed by Frédéric Guillot
parent 343e86a138
commit 437fc1b7d9

View File

@@ -1,13 +1,23 @@
KB.component('calendar', function (containerElement, options) { KB.component('calendar', function (containerElement, options) {
var modeMapping = { // Let's have bookable pretty mode names
month: 'month',
week: 'agendaWeek',
day: 'agendaDay'
};
this.render = function () { this.render = function () {
var calendar = $(containerElement); var calendar = $(containerElement);
var mode = 'month';
if (window.location.hash) { // Check if hash contains mode
var hashMode = window.location.hash.substr(1);
mode = modeMapping[hashMode] || mode;
}
calendar.fullCalendar({ calendar.fullCalendar({
locale: $("body").data("js-lang"), locale: $("body").data("js-lang"),
editable: true, editable: true,
eventLimit: true, eventLimit: true,
defaultView: "month", defaultView: mode,
header: { header: {
left: 'prev,next today', left: 'prev,next today',
center: 'title', center: 'title',
@@ -26,7 +36,14 @@ KB.component('calendar', function (containerElement, options) {
}) })
}); });
}, },
viewRender: function() { viewRender: function(view) {
// Map view.name back and update location.hash
for (var id in modeMapping) {
if (modeMapping[id] === view.name) { // Found
window.location.hash = id;
break;
}
}
var url = options.checkUrl; var url = options.checkUrl;
var params = { var params = {
"start": calendar.fullCalendar('getView').start.format(), "start": calendar.fullCalendar('getView').start.format(),