2015-05-06 04:06:13 +02:00
|
|
|
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* JavaScript for SOGo.SchedulerUI module */
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
2015-07-29 17:47:01 +02:00
|
|
|
angular.module('SOGo.SchedulerUI', ['ngSanitize', 'ui.router', 'SOGo.Common', 'SOGo.PreferencesUI', 'SOGo.ContactsUI', 'SOGo.MailerUI'])
|
2015-05-06 04:06:13 +02:00
|
|
|
.config(configure)
|
|
|
|
.run(runBlock);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
|
|
|
configure.$inject = ['$stateProvider', '$urlRouterProvider'];
|
|
|
|
function configure($stateProvider, $urlRouterProvider) {
|
|
|
|
$stateProvider
|
|
|
|
.state('calendars', {
|
|
|
|
url: '/calendar',
|
|
|
|
views: {
|
|
|
|
calendars: {
|
|
|
|
templateUrl: 'UIxCalMainFrame', // UI/Templates/SchedulerUI/UIxCalMainFrame.wox
|
|
|
|
controller: 'CalendarsController',
|
2015-09-17 16:33:12 +02:00
|
|
|
controllerAs: 'app'
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
stateCalendars: stateCalendars
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.state('calendars.view', {
|
|
|
|
url: '/{view:(?:day|week|month)}/:day',
|
|
|
|
sticky: true,
|
|
|
|
deepStateRedirect: true,
|
|
|
|
views: {
|
|
|
|
calendarView: {
|
|
|
|
templateUrl: function($stateParams) {
|
|
|
|
// UI/Templates/SchedulerUI/UIxCalDayView.wox or
|
|
|
|
// UI/Templates/SchedulerUI/UIxCalWeekView.wox or
|
|
|
|
// UI/Templates/SchedulerUI/UIxCalMonthView.wox
|
|
|
|
return $stateParams.view + 'view?day=' + $stateParams.day;
|
|
|
|
},
|
|
|
|
controller: 'CalendarController',
|
|
|
|
controllerAs: 'calendar'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
stateEventsBlocks: stateEventsBlocks
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$urlRouterProvider.when('/calendar/day', function() {
|
|
|
|
// If no date is specified, show today
|
|
|
|
var now = new Date();
|
|
|
|
return '/calendar/day/' + now.getDayString();
|
2015-07-29 17:47:01 +02:00
|
|
|
});
|
2015-05-06 04:06:13 +02:00
|
|
|
$urlRouterProvider.when('/calendar/week', function() {
|
|
|
|
// If no date is specified, show today's week
|
|
|
|
var now = new Date();
|
|
|
|
return '/calendar/week/' + now.getDayString();
|
2015-07-29 17:47:01 +02:00
|
|
|
});
|
2015-05-06 04:06:13 +02:00
|
|
|
$urlRouterProvider.when('/calendar/month', function() {
|
|
|
|
// If no date is specified, show today's month
|
|
|
|
var now = new Date();
|
|
|
|
return '/calendar/month/' + now.getDayString();
|
|
|
|
});
|
|
|
|
|
2015-07-29 17:47:01 +02:00
|
|
|
// If none of the above states are matched, use this as the fallback.
|
|
|
|
// runBlock will also act as a fallback by looking at user's settings
|
2015-05-06 04:06:13 +02:00
|
|
|
$urlRouterProvider.otherwise('/calendar');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
|
|
|
stateCalendars.$inject = ['Calendar'];
|
|
|
|
function stateCalendars(Calendar) {
|
|
|
|
return Calendar.$calendars || Calendar.$findAll(window.calendarsData);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
|
|
|
stateEventsBlocks.$inject = ['$stateParams', 'Component'];
|
|
|
|
function stateEventsBlocks($stateParams, Component) {
|
|
|
|
return Component.$eventsBlocksForView($stateParams.view, $stateParams.day.asDate());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2015-07-29 17:47:01 +02:00
|
|
|
runBlock.$inject = ['$rootScope', '$location', 'Preferences'];
|
|
|
|
function runBlock($rootScope, $location, Preferences) {
|
2015-05-06 04:06:13 +02:00
|
|
|
$rootScope.$on('$routeChangeError', function(event, current, previous, rejection) {
|
|
|
|
console.error(event, current, previous, rejection);
|
|
|
|
});
|
2015-07-29 17:47:01 +02:00
|
|
|
if ($location.url().length === 0) {
|
|
|
|
// Restore user's last view
|
|
|
|
Preferences.ready().then(function() {
|
|
|
|
var view = /(.+)view/.exec(Preferences.settings.Calendar.View);
|
|
|
|
if (view) {
|
|
|
|
$location.replace().url('/calendar/' + view[1]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
})();
|