2015-05-06 04:06:13 +02:00
|
|
|
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2016-07-04 23:11:48 +02:00
|
|
|
CalendarController.$inject = ['$scope', '$rootScope', '$state', '$stateParams', 'Calendar', 'Component', 'Preferences', 'stateEventsBlocks'];
|
|
|
|
function CalendarController($scope, $rootScope, $state, $stateParams, Calendar, Component, Preferences, stateEventsBlocks) {
|
2015-11-06 21:12:24 +01:00
|
|
|
var vm = this, deregisterCalendarsList;
|
2015-05-06 04:06:13 +02:00
|
|
|
|
2016-03-30 17:10:09 +02:00
|
|
|
// Make the toolbar state of all-day events persistent
|
|
|
|
if (angular.isUndefined(CalendarController.expandedAllDays))
|
|
|
|
CalendarController.expandedAllDays = false;
|
|
|
|
|
2016-07-04 23:11:48 +02:00
|
|
|
vm.selectedDate = $stateParams.day.asDate();
|
2016-03-30 17:10:09 +02:00
|
|
|
vm.expandedAllDays = CalendarController.expandedAllDays;
|
|
|
|
vm.toggleAllDays = toggleAllDays;
|
2015-09-29 20:08:05 +02:00
|
|
|
vm.views = stateEventsBlocks;
|
2016-01-12 19:38:54 +01:00
|
|
|
vm.changeDate = changeDate;
|
2015-05-06 04:06:13 +02:00
|
|
|
vm.changeView = changeView;
|
|
|
|
|
2016-07-04 23:11:48 +02:00
|
|
|
Preferences.ready().then(function() {
|
|
|
|
_formatDate(vm.selectedDate);
|
|
|
|
});
|
|
|
|
|
2015-05-06 04:06:13 +02:00
|
|
|
// Refresh current view when the list of calendars is modified
|
2015-11-06 21:12:24 +01:00
|
|
|
deregisterCalendarsList = $rootScope.$on('calendars:list', updateView);
|
|
|
|
|
2016-07-04 23:11:48 +02:00
|
|
|
// Destroy event listener when the controller is being deactivated
|
2015-11-06 21:12:24 +01:00
|
|
|
$scope.$on('$destroy', deregisterCalendarsList);
|
|
|
|
|
2016-07-04 23:11:48 +02:00
|
|
|
function _formatDate(date) {
|
|
|
|
if ($stateParams.view == 'month') {
|
|
|
|
date.setDate(1);
|
|
|
|
date.setHours(12);
|
|
|
|
date.$dateFormat = '%B %Y';
|
|
|
|
}
|
|
|
|
else if ($stateParams.view == 'week') {
|
|
|
|
date.setTime(date.beginOfWeek(Preferences.defaults.SOGoFirstDayOfWeek).getTime());
|
|
|
|
date.$dateFormat = l('Week %d').replace('%d', '%U');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
date.$dateFormat = '%A';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-30 17:10:09 +02:00
|
|
|
// Expand or collapse all-day events
|
|
|
|
function toggleAllDays() {
|
|
|
|
CalendarController.expandedAllDays = !CalendarController.expandedAllDays;
|
|
|
|
vm.expandedAllDays = CalendarController.expandedAllDays;
|
|
|
|
}
|
|
|
|
|
2015-11-06 21:12:24 +01:00
|
|
|
function updateView() {
|
2015-09-29 20:08:05 +02:00
|
|
|
// See stateEventsBlocks in Scheduler.app.js
|
2015-05-06 04:06:13 +02:00
|
|
|
Component.$eventsBlocksForView($stateParams.view, $stateParams.day.asDate()).then(function(data) {
|
2015-09-29 20:08:05 +02:00
|
|
|
vm.views = data;
|
|
|
|
_.forEach(vm.views, function(view) {
|
|
|
|
if (view.id) {
|
2015-11-06 21:12:24 +01:00
|
|
|
// Note: this can't be done in Component service since it would make Component dependent on
|
|
|
|
// the Calendar service and create a circular dependency
|
2015-09-29 20:08:05 +02:00
|
|
|
view.calendar = new Calendar({ id: view.id, name: view.calendarName });
|
|
|
|
}
|
|
|
|
});
|
2015-05-06 04:06:13 +02:00
|
|
|
});
|
2015-11-06 21:12:24 +01:00
|
|
|
}
|
2015-05-06 04:06:13 +02:00
|
|
|
|
2016-01-12 19:38:54 +01:00
|
|
|
// Change calendar's date
|
2016-07-04 23:11:48 +02:00
|
|
|
function changeDate($event, newDate) {
|
|
|
|
var date = newDate? newDate.getDayString() : angular.element($event.currentTarget).attr('date');
|
|
|
|
if (newDate)
|
|
|
|
_formatDate(newDate);
|
2016-01-12 19:38:54 +01:00
|
|
|
$state.go('calendars.view', { day: date });
|
|
|
|
}
|
|
|
|
|
|
|
|
// Change calendar's view
|
|
|
|
function changeView(view) {
|
|
|
|
$state.go('calendars.view', { view: view });
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
2016-01-12 19:38:54 +01:00
|
|
|
}
|
2015-09-29 20:08:05 +02:00
|
|
|
|
2015-05-06 04:06:13 +02:00
|
|
|
angular
|
|
|
|
.module('SOGo.SchedulerUI')
|
|
|
|
.controller('CalendarController', CalendarController);
|
|
|
|
})();
|