diff --git a/UI/Scheduler/UIxReminderEditor.h b/UI/Scheduler/UIxReminderEditor.h index d2e2277de..3b963352d 100644 --- a/UI/Scheduler/UIxReminderEditor.h +++ b/UI/Scheduler/UIxReminderEditor.h @@ -1,8 +1,6 @@ /* UIxReminderEditor.h - this file is part of SOGo * - * Copyright (C) 2009 Inverse inc. - * - * Author: Francis Lachapelle + * Copyright (C) 2009-2015 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/UI/Scheduler/UIxReminderEditor.m b/UI/Scheduler/UIxReminderEditor.m index 1593a4bd1..8dc44e649 100644 --- a/UI/Scheduler/UIxReminderEditor.m +++ b/UI/Scheduler/UIxReminderEditor.m @@ -1,8 +1,6 @@ /* UIxReminderEditor.m - this file is part of SOGo * - * Copyright (C) 2009 Inverse inc. - * - * Author: Francis Lachapelle + * Copyright (C) 2009-2015 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/UI/WebServerResources/js/Common/Alarm.service.js b/UI/WebServerResources/js/Common/Alarm.service.js new file mode 100644 index 000000000..6a6d70bf4 --- /dev/null +++ b/UI/WebServerResources/js/Common/Alarm.service.js @@ -0,0 +1,142 @@ +/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ + +(function() { + 'use strict'; + + /** + * @name Alarm + * @constructor + */ + function Alarm() { + this.currentAlarm = null; + } + + /** + * @name getAlarms + * @desc Fetch the list of alarms from the server and use the last one + */ + Alarm.getAlarms = function() { + var _this = this; + var now = new Date(); + var browserTime = Math.floor(now.getTime()/1000); + + this.$$resource.fetch('', 'alarmslist?browserTime=' + browserTime).then(function(data) { + + var alarms = data.alarms.sort(function reverseSortByAlarmTime(a, b) { + var x = parseInt(a[2]); + var y = parseInt(b[2]); + return (y - x); + }); + + if (alarms.length > 0) { + var next = alarms.pop(); + var now = new Date(); + var utc = Math.floor(now.getTime()/1000); + var url = next[0] + '/' + next[1]; + var alarmTime = parseInt(next[2]); + var delay = alarmTime; + if (alarmTime > 0) delay -= utc; + var d = new Date(alarmTime*1000); + //console.log ("now = " + now.toUTCString()); + //console.log ("next event " + url + " in " + delay + " seconds (on " + d.toUTCString() + ")"); + + var f = angular.bind(_this, Alarm.showAlarm, url); + + if (_this.currentAlarm) + _this.$timeout.cancel(_this.currentAlarm); + + _this.currentAlarm = _this.$timeout(f, delay*1000); + } + }); + }; + + /** + * @name showAlarm + * @desc Show the latest alarm using a toast + * @param url The URL of the calendar component for snoozing + */ + Alarm.showAlarm = function(url) { + var _this = this; + + this.$toast.show({ + position: 'top right', + hideDelay: 0, + template: [ + '', + ' ', + ' ', + ' ', + l('5 minutes'), + ' ', + ' ', + l('10 minutes'), + ' ', + ' ', + l('15 minutes'), + ' ', + ' ', + l('30 minutes'), + ' ', + ' ', + l('45 minutes'), + ' ', + ' ', + l('1 hour'), + ' ', + ' ', + l('1 day'), + ' ', + ' ', + ' ', + ' ', + l('Cancel'), + ' ', + ' ', + l('Ok'), + ' ', + '' + ].join(''), + locals: { + url: url + }, + controller: AlarmController + }); + + /** + * @ngInject + */ + AlarmController.$inject = ['scope', '$mdToast', 'url']; + function AlarmController(scope, $mdToast, url) { + scope.reminder = '10'; + scope.cancel = function() { + $mdToast.hide(); + }; + scope.ok = function() { + _this.$$resource.fetch(url, 'view?snoozeAlarm=' + scope.reminder); + $mdToast.hide(); + }; + } + }; + + /** + * @memberof Alarm + * @desc The factory we'll register as Alarm in the Angular module SOGo.Common + * @ngInject + */ + AlarmService.$inject = ['$timeout', 'sgSettings', 'Resource', '$mdToast']; + function AlarmService($timeout, Settings, Resource, $mdToast) { + angular.extend(Alarm, { + $timeout: $timeout, + $$resource: new Resource(Settings.activeUser.folderURL + 'Calendar', Settings.activeUser), + $toast: $mdToast + }); + + return Alarm; // return constructor + } + + /* Factory registration in Angular module */ + angular + .module('SOGo.Common') + .factory('Alarm', AlarmService); + +})(); diff --git a/UI/WebServerResources/js/Common/navController.js b/UI/WebServerResources/js/Common/navController.js index 76e133bfa..a4fc4b160 100644 --- a/UI/WebServerResources/js/Common/navController.js +++ b/UI/WebServerResources/js/Common/navController.js @@ -9,8 +9,8 @@ /** * @ngInject */ - navController.$inject = ['$scope', '$timeout', '$interval', '$http', '$mdSidenav', '$mdBottomSheet', '$mdMedia', '$log', 'sgConstant', 'sgSettings']; - function navController($scope, $timeout, $interval, $http, $mdSidenav, $mdBottomSheet, $mdMedia, $log, sgConstant, sgSettings) { + navController.$inject = ['$scope', '$timeout', '$interval', '$http', '$mdSidenav', '$mdBottomSheet', '$mdMedia', '$log', 'sgConstant', 'sgSettings', 'Alarm']; + function navController($scope, $timeout, $interval, $http, $mdSidenav, $mdBottomSheet, $mdMedia, $log, sgConstant, sgSettings, Alarm) { $scope.activeUser = sgSettings.activeUser; @@ -52,6 +52,8 @@ }, function(newVal) { $scope.isGtMedium = newVal; }); + + Alarm.getAlarms(); } angular.module('SOGo.Common') diff --git a/UI/WebServerResources/js/Scheduler/ComponentController.js b/UI/WebServerResources/js/Scheduler/ComponentController.js index a508b000a..70a584a54 100644 --- a/UI/WebServerResources/js/Scheduler/ComponentController.js +++ b/UI/WebServerResources/js/Scheduler/ComponentController.js @@ -59,8 +59,8 @@ /** * @ngInject */ - ComponentEditorController.$inject = ['$rootScope', '$scope', '$log', '$timeout', '$mdDialog', 'User', 'Calendar', 'Component', 'AddressBook', 'Card', 'stateComponent']; - function ComponentEditorController($rootScope, $scope, $log, $timeout, $mdDialog, User, Calendar, Component, AddressBook, Card, stateComponent) { + ComponentEditorController.$inject = ['$rootScope', '$scope', '$log', '$timeout', '$mdDialog', 'User', 'Calendar', 'Component', 'AddressBook', 'Card', 'Alarm', 'stateComponent']; + function ComponentEditorController($rootScope, $scope, $log, $timeout, $mdDialog, User, Calendar, Component, AddressBook, Card, Alarm, stateComponent) { var vm = this, component; vm.calendars = Calendar.$calendars; @@ -163,6 +163,7 @@ .then(function(data) { $rootScope.$broadcast('calendars:list'); $mdDialog.hide(); + Alarm.getAlarms(); }, function(data, status) { $log.debug('failed'); }); diff --git a/UI/WebServerResources/scss/styles.scss b/UI/WebServerResources/scss/styles.scss index 9dad212aa..744fb4a23 100755 --- a/UI/WebServerResources/scss/styles.scss +++ b/UI/WebServerResources/scss/styles.scss @@ -56,7 +56,7 @@ //@import 'components/swipe/swipe'; @import 'components/switch/switch'; @import 'components/tabs/tabs'; -//@import 'components/toast/toast'; +@import 'components/toast/toast'; @import 'components/toolbar/toolbar'; @import 'components/tooltip/tooltip'; @import 'components/virtualRepeat/virtualRepeat';