2015-03-31 03:20:35 +02:00
|
|
|
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* JavaScript for SOGo.SchedulerUI module */
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular.module('SOGo.Common', []);
|
|
|
|
angular.module('SOGo.ContactsUI', []);
|
|
|
|
|
2015-04-24 22:48:41 +02:00
|
|
|
angular.module('SOGo.SchedulerUI', ['ngSanitize', 'ui.router', 'ct.ui.router.extras.sticky', 'ct.ui.router.extras.previous', 'vs-repeat', 'SOGo.Common', 'SOGo.UI', 'SOGo.UIDesktop', 'SOGo.ContactsUI'])
|
2015-03-31 03:20:35 +02:00
|
|
|
|
|
|
|
.constant('sgSettings', {
|
|
|
|
baseURL: ApplicationBaseURL,
|
|
|
|
activeUser: {
|
|
|
|
login: UserLogin,
|
|
|
|
identification: UserIdentification,
|
|
|
|
language: UserLanguage,
|
|
|
|
folderURL: UserFolderURL,
|
|
|
|
isSuperUser: IsSuperUser
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
|
|
|
|
$stateProvider
|
|
|
|
.state('calendars', {
|
|
|
|
url: '/calendar',
|
|
|
|
views: {
|
|
|
|
calendars: {
|
|
|
|
templateUrl: 'UIxCalMainFrame', // UI/Templates/SchedulerUI/UIxCalMainFrame.wox
|
|
|
|
controller: 'CalendarsController',
|
|
|
|
controllerAs: 'calendars'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
stateCalendars: ['sgCalendar', function(Calendar) {
|
|
|
|
return Calendar.$calendars || Calendar.$findAll(window.calendarsData);
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
})
|
2015-04-01 17:18:19 +02:00
|
|
|
.state('calendars.view', {
|
2015-04-08 22:01:52 +02:00
|
|
|
url: '/{view:(?:day|week|month)}/:day',
|
2015-04-24 22:48:41 +02:00
|
|
|
sticky: true,
|
|
|
|
deepStateRedirect: true,
|
2015-03-31 03:20:35 +02:00
|
|
|
views: {
|
|
|
|
calendarView: {
|
2015-04-01 17:18:19 +02:00
|
|
|
templateUrl: function($stateParams) {
|
|
|
|
// UI/Templates/SchedulerUI/UIxCalDayView.wox or
|
2015-04-08 22:01:52 +02:00
|
|
|
// UI/Templates/SchedulerUI/UIxCalWeekView.wox or
|
|
|
|
// UI/Templates/SchedulerUI/UIxCalMonthView.wox
|
2015-04-01 17:18:19 +02:00
|
|
|
return $stateParams.view + 'view?day=' + $stateParams.day;
|
2015-03-31 03:20:35 +02:00
|
|
|
},
|
|
|
|
controller: 'CalendarController',
|
|
|
|
controllerAs: 'calendar'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
stateEventsBlocks: ['$stateParams', 'sgComponent', function($stateParams, Component) {
|
2015-04-01 17:18:19 +02:00
|
|
|
return Component.$eventsBlocksForView($stateParams.view, $stateParams.day.asDate());
|
2015-03-31 03:20:35 +02:00
|
|
|
}]
|
|
|
|
}
|
2015-04-24 22:48:41 +02:00
|
|
|
})
|
|
|
|
.state('calendars.component', {
|
|
|
|
url: '/:calendarId/event/:componentId',
|
|
|
|
views: {
|
|
|
|
componentEditor: {
|
|
|
|
templateUrl: 'UIxAppointmentEditorTemplate',
|
|
|
|
controller: 'ComponentController',
|
|
|
|
controllerAs: 'editor'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
stateComponent: ['$stateParams', 'sgCalendar', function($stateParams, Calendar) {
|
|
|
|
return Calendar.$get($stateParams.calendarId).$getComponent($stateParams.componentId);
|
|
|
|
}]
|
|
|
|
}
|
2015-03-31 03:20:35 +02:00
|
|
|
});
|
|
|
|
|
2015-04-01 17:18:19 +02:00
|
|
|
$urlRouterProvider.when('/calendar/day', function() {
|
|
|
|
// If no date is specified, show today
|
|
|
|
var now = new Date();
|
|
|
|
return '/calendar/day/' + now.getDayString();
|
|
|
|
})
|
|
|
|
$urlRouterProvider.when('/calendar/week', function() {
|
2015-03-31 03:20:35 +02:00
|
|
|
// If no date is specified, show today's week
|
|
|
|
var now = new Date();
|
2015-04-01 17:18:19 +02:00
|
|
|
return '/calendar/week/' + now.getDayString();
|
2015-04-08 22:01:52 +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-03-31 03:20:35 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// if none of the above states are matched, use this as the fallback
|
|
|
|
$urlRouterProvider.otherwise('/calendar');
|
|
|
|
}])
|
|
|
|
|
|
|
|
.run(function($rootScope) {
|
|
|
|
$rootScope.$on('$routeChangeError', function(event, current, previous, rejection) {
|
|
|
|
console.error(event, current, previous, rejection)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2015-04-24 22:07:48 +02:00
|
|
|
|
|
|
|
.controller('CalendarsController', ['$scope', '$rootScope', '$stateParams', '$state', '$timeout', '$q', '$mdDialog', '$log', 'sgFocus', 'encodeUriFilter', 'sgDialog', 'sgSettings', 'sgCalendar', 'sgUser', 'stateCalendars', function($scope, $rootScope, $stateParams, $state, $timeout, $q, $mdDialog, $log, focus, encodeUriFilter, Dialog, Settings, Calendar, User, stateCalendars) {
|
2015-04-24 21:08:55 +02:00
|
|
|
var vm = this;
|
|
|
|
|
|
|
|
vm.activeUser = Settings.activeUser;
|
|
|
|
vm.service = Calendar;
|
2015-03-31 03:20:35 +02:00
|
|
|
|
|
|
|
// Dispatch the event named 'calendars:list' when a calendar is activated or deactivated or
|
|
|
|
// when the color of a calendar is changed
|
2015-04-24 21:08:55 +02:00
|
|
|
$scope.$watch(
|
|
|
|
function() {
|
|
|
|
return _.union(
|
|
|
|
_.map(Calendar.$calendars, function(o) { return _.pick(o, ['id', 'active', 'color']) }),
|
|
|
|
_.map(Calendar.$subscriptions, function(o) { return _.pick(o, ['id', 'active', 'color']) })
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function(newList, oldList) {
|
|
|
|
// Identify which calendar has changed
|
|
|
|
var ids = _.pluck(_.filter(newList, function(o, i) { return !_.isEqual(o, oldList[i]); }), 'id');
|
|
|
|
if (ids.length > 0) {
|
|
|
|
$log.debug(ids.join(', ') + ' changed');
|
|
|
|
_.each(ids, function(id) {
|
|
|
|
var calendar = Calendar.$get(id);
|
|
|
|
calendar.$setActivation().then(function() {
|
|
|
|
$scope.$broadcast('calendars:list');
|
|
|
|
});
|
2015-03-31 03:20:35 +02:00
|
|
|
});
|
2015-04-24 21:08:55 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
true // compare for object equality
|
|
|
|
);
|
|
|
|
|
2015-04-25 01:20:32 +02:00
|
|
|
$scope.newCalendar = function(ev) {
|
|
|
|
$mdDialog.show({
|
|
|
|
parent: angular.element(document.body),
|
|
|
|
targetEvent: ev,
|
|
|
|
clickOutsideToClose: true,
|
|
|
|
escapeToClose: true,
|
|
|
|
template:
|
|
|
|
'<md-dialog aria-label="' + l('New calendar') + '">' +
|
2015-04-27 19:33:26 +02:00
|
|
|
' <md-dialog-content layout="column">' +
|
2015-04-25 01:20:32 +02:00
|
|
|
' <md-input-container>' +
|
|
|
|
' <label>' + l('Name of the Calendar') + '</label>' +
|
|
|
|
' <input type="text" ng-model="name" required="required"/>' +
|
|
|
|
' </md-input-container>' +
|
|
|
|
' <div layout="row">' +
|
|
|
|
' <md-button ng-click="cancelClicked()">' +
|
|
|
|
' Cancel' +
|
|
|
|
' </md-button>' +
|
|
|
|
' <md-button ng-click="okClicked()" ng-disabled="!name.length">' +
|
|
|
|
' OK' +
|
|
|
|
' </md-button>' +
|
|
|
|
' </div>'+
|
2015-04-27 19:33:26 +02:00
|
|
|
' </md-dialog-content>' +
|
2015-04-25 01:20:32 +02:00
|
|
|
'</md-dialog>',
|
|
|
|
controller: NewCalendarDialogController
|
|
|
|
});
|
|
|
|
function NewCalendarDialogController(scope, $mdDialog) {
|
|
|
|
scope.name = "";
|
|
|
|
scope.cancelClicked = function() {
|
|
|
|
$mdDialog.hide();
|
|
|
|
}
|
|
|
|
scope.okClicked = function() {
|
|
|
|
var calendar = new Calendar(
|
|
|
|
{
|
|
|
|
name: scope.name,
|
|
|
|
isEditable: true,
|
|
|
|
isRemote: false,
|
|
|
|
owner: UserLogin
|
|
|
|
}
|
|
|
|
);
|
|
|
|
Calendar.$add(calendar);
|
|
|
|
$mdDialog.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-04-24 22:07:48 +02:00
|
|
|
$scope.share = function(calendar) {
|
|
|
|
$mdDialog.show({
|
|
|
|
templateUrl: calendar.id + '/UIxAclEditor', // UI/Templates/UIxAclEditor.wox
|
|
|
|
controller: CalendarACLController,
|
|
|
|
clickOutsideToClose: true,
|
|
|
|
escapeToClose: true,
|
|
|
|
locals: {
|
|
|
|
usersWithACL: calendar.$acl.$users(),
|
|
|
|
User: User,
|
|
|
|
stateCalendar: calendar,
|
|
|
|
q: $q
|
|
|
|
}
|
|
|
|
});
|
|
|
|
function CalendarACLController($scope, $mdDialog, usersWithACL, User, stateCalendar, q) {
|
|
|
|
$scope.users = usersWithACL; // ACL users
|
|
|
|
$scope.stateCalendar = stateCalendar;
|
|
|
|
$scope.userToAdd = '';
|
|
|
|
$scope.searchText = '';
|
|
|
|
$scope.userFilter = function($query) {
|
|
|
|
var deferred = q.defer();
|
|
|
|
User.$filter($query).then(function(results) {
|
|
|
|
deferred.resolve(results)
|
|
|
|
});
|
|
|
|
return deferred.promise;
|
|
|
|
};
|
|
|
|
$scope.closeModal = function() {
|
|
|
|
stateCalendar.$acl.$resetUsersRights(); // cancel changes
|
|
|
|
$mdDialog.hide();
|
|
|
|
};
|
|
|
|
$scope.saveModal = function() {
|
|
|
|
stateCalendar.$acl.$saveUsersRights().then(function() {
|
|
|
|
$mdDialog.hide();
|
|
|
|
}, function(data, status) {
|
|
|
|
Dialog.alert(l('Warning'), l('An error occured please try again.'));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
$scope.confirmChange = function(user) {
|
|
|
|
var confirmation = user.$confirmRights();
|
|
|
|
if (confirmation) {
|
|
|
|
Dialog.confirm(l('Warning'), confirmation).then(function(res) {
|
|
|
|
if (!res)
|
|
|
|
user.$resetRights(true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
$scope.removeUser = function(user) {
|
|
|
|
stateCalendar.$acl.$removeUser(user.uid).then(function() {
|
|
|
|
if (user.uid == $scope.selectedUser.uid) {
|
|
|
|
$scope.selectedUser = null;
|
|
|
|
}
|
|
|
|
}, function(data, status) {
|
|
|
|
Dialog.alert(l('Warning'), l('An error occured please try again.'))
|
|
|
|
});
|
|
|
|
};
|
|
|
|
$scope.addUser = function(data) {
|
|
|
|
stateCalendar.$acl.$addUser(data).then(function() {
|
|
|
|
$scope.userToAdd = '';
|
|
|
|
$scope.searchText = '';
|
|
|
|
}, function(error) {
|
|
|
|
Dialog.alert(l('Warning'), error);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
$scope.selectUser = function(user) {
|
|
|
|
// Check if it is a different user
|
|
|
|
if ($scope.selectedUser != user) {
|
|
|
|
$scope.selectedUser = user;
|
|
|
|
$scope.selectedUser.$rights();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
2015-04-22 21:55:52 +02:00
|
|
|
/**
|
|
|
|
* subscribeToFolder - Callback of sgSubscribe directive
|
|
|
|
*/
|
|
|
|
$scope.subscribeToFolder = function(calendarData) {
|
|
|
|
console.debug('subscribeToFolder ' + calendarData.owner + calendarData.name);
|
|
|
|
Calendar.$subscribe(calendarData.owner, calendarData.name).catch(function(data) {
|
|
|
|
Dialog.alert(l('Warning'), l('An error occured please try again.'));
|
|
|
|
});
|
|
|
|
};
|
2015-03-31 03:20:35 +02:00
|
|
|
}])
|
|
|
|
|
2015-04-24 22:48:41 +02:00
|
|
|
.controller('CalendarListController', ['$scope', '$rootScope', '$timeout', 'sgFocus', 'encodeUriFilter', 'sgDialog', 'sgSettings', 'sgCalendar', 'sgComponent', '$mdSidenav', function($scope, $rootScope, $timeout, focus, encodeUriFilter, Dialog, Settings, Calendar, Component, $mdSidenav) {
|
2015-03-31 03:20:35 +02:00
|
|
|
// Scope variables
|
|
|
|
this.component = Component;
|
|
|
|
this.componentType = null;
|
|
|
|
|
|
|
|
// Switch between components tabs
|
|
|
|
this.selectComponentType = angular.bind(this, function(type, options) {
|
|
|
|
console.debug("selectComponentType " + type);
|
|
|
|
if (options && options.reload || this.componentType != type) {
|
|
|
|
// TODO: save user settings (Calendar.SelectedList)
|
|
|
|
Component.$filter(type);
|
|
|
|
this.componentType = type;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Refresh current list when the list of calendars is modified
|
|
|
|
$scope.$on('calendars:list', angular.bind(this, function() {
|
|
|
|
Component.$filter(this.componentType);
|
|
|
|
}));
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
// TODO: should reflect last state userSettings -> Calendar -> SelectedList
|
|
|
|
this.selectedList = 0;
|
|
|
|
this.selectComponentType('events');
|
|
|
|
}])
|
|
|
|
|
|
|
|
.controller('CalendarController', ['$scope', '$state', '$stateParams', '$timeout', '$interval', '$log', 'sgFocus', 'sgCalendar', 'sgComponent', 'stateEventsBlocks', function($scope, $state, $stateParams, $timeout, $interval, $log, focus, Calendar, Component, stateEventsBlocks) {
|
|
|
|
// Scope variables
|
|
|
|
this.blocks = stateEventsBlocks;
|
|
|
|
|
|
|
|
// Change calendar's view
|
|
|
|
this.changeView = function($event) {
|
|
|
|
var date = angular.element($event.currentTarget).attr('date');
|
2015-04-01 17:18:19 +02:00
|
|
|
$state.go('calendars.view', { view: $stateParams.view, day: date });
|
2015-03-31 03:20:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Refresh current view when the list of calendars is modified
|
|
|
|
$scope.$on('calendars:list', angular.bind(this, function() {
|
|
|
|
var ctrl = this;
|
2015-04-01 17:18:19 +02:00
|
|
|
Component.$eventsBlocksForView($stateParams.view, $stateParams.day.asDate()).then(function(data) {
|
2015-03-31 03:20:35 +02:00
|
|
|
ctrl.blocks = data;
|
|
|
|
});
|
|
|
|
}));
|
2015-04-24 22:48:41 +02:00
|
|
|
}])
|
|
|
|
|
|
|
|
.controller('ComponentController', ['$scope', '$log', '$timeout', '$state', '$previousState', '$mdSidenav', '$mdDialog', 'sgCalendar', 'sgComponent', 'stateCalendars', 'stateComponent', function($scope, $log, $timeout, $state, $previousState, $mdSidenav, $mdDialog, Calendar, Component, stateCalendars, stateComponent) {
|
|
|
|
var vm = this;
|
|
|
|
|
|
|
|
vm.calendars = stateCalendars;
|
|
|
|
vm.event = stateComponent;
|
|
|
|
vm.categories = {};
|
|
|
|
vm.editRecurrence = editRecurrence;
|
|
|
|
vm.cancel = cancel;
|
|
|
|
vm.save = save;
|
|
|
|
|
|
|
|
$scope.$on('$viewContentLoaded', function(event) {
|
|
|
|
$timeout(function() {
|
|
|
|
$mdSidenav('right').open()
|
|
|
|
.then(function() {
|
|
|
|
$scope.$watch($mdSidenav('right').isOpen, function(isOpen, wasOpen) {
|
|
|
|
if (!isOpen) {
|
|
|
|
if ($previousState.get())
|
|
|
|
$previousState.go()
|
|
|
|
else
|
|
|
|
$state.go('calendars');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}, 100); // don't ask why
|
|
|
|
});
|
|
|
|
|
|
|
|
function editRecurrence($event) {
|
|
|
|
$mdDialog.show({
|
|
|
|
templateUrl: 'editRecurrence', // UI/Templates/SchedulerUI/UIxRecurrenceEditor.wox
|
|
|
|
controller: RecurrenceController
|
|
|
|
});
|
|
|
|
function RecurrenceController() {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function save(form) {
|
|
|
|
if (form.$valid) {
|
|
|
|
vm.event.$save()
|
|
|
|
.then(function(data) {
|
|
|
|
$scope.$emit('calendars:list');
|
|
|
|
$mdSidenav('right').close();
|
|
|
|
}, function(data, status) {
|
|
|
|
console.debug('failed');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function cancel() {
|
|
|
|
vm.event.$reset();
|
|
|
|
if (vm.event.isNew) {
|
|
|
|
// Cancelling the creation of a card
|
|
|
|
vm.event = null;
|
|
|
|
}
|
|
|
|
$mdSidenav('right').close();
|
|
|
|
}
|
2015-03-31 03:20:35 +02:00
|
|
|
}]);
|
|
|
|
|
|
|
|
})();
|