2015-05-06 04:06:13 +02:00
|
|
|
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
2016-02-25 03:12:23 +01:00
|
|
|
angular.module('SOGo.Common', ['ngAnimate', 'ngMessages', 'ngSanitize', 'ngMaterial', 'mdColors'])
|
2015-08-03 17:53:54 +02:00
|
|
|
.value('sgSettings', {
|
2015-09-04 23:31:16 +02:00
|
|
|
isPopup: document.body.classList.contains('popup'),
|
2015-08-03 17:53:54 +02:00
|
|
|
baseURL: function() {
|
|
|
|
return ApplicationBaseURL || null;
|
|
|
|
},
|
2016-06-22 03:29:44 +02:00
|
|
|
resourcesURL: function() {
|
|
|
|
return ResourcesURL || null;
|
|
|
|
},
|
2015-08-03 17:53:54 +02:00
|
|
|
activeUser: function(param) {
|
|
|
|
var settings = {
|
|
|
|
login: UserLogin || null,
|
|
|
|
identification: UserIdentification || null,
|
2015-08-14 18:14:15 +02:00
|
|
|
email: UserEmail || null,
|
2015-08-03 17:53:54 +02:00
|
|
|
language: UserLanguage || null,
|
|
|
|
folderURL: UserFolderURL || null,
|
2015-08-14 18:14:15 +02:00
|
|
|
isSuperUser: IsSuperUser || null,
|
|
|
|
path: {
|
|
|
|
calendar: UserCalendarPath || null,
|
|
|
|
contacts: UserContactsPath || null,
|
|
|
|
mail: UserMailPath || null,
|
|
|
|
preferences: UserPreferencesPath || null,
|
|
|
|
administration: (IsSuperUser ? UserAdministrationPath : null),
|
2016-05-11 17:04:10 +02:00
|
|
|
help: HelpURL || null,
|
2015-08-14 18:14:15 +02:00
|
|
|
logoff: UserLogoffPath || null
|
|
|
|
}
|
2015-08-03 17:53:54 +02:00
|
|
|
};
|
|
|
|
if (param)
|
|
|
|
return settings[param];
|
|
|
|
else
|
|
|
|
return settings;
|
2016-10-26 21:44:43 +02:00
|
|
|
},
|
|
|
|
minimumSearchLength: function() {
|
|
|
|
return angular.isNumber(minimumSearchLength)? minimumSearchLength : 2;
|
2015-07-29 17:47:01 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2015-07-31 17:11:55 +02:00
|
|
|
.constant('sgColors', {
|
|
|
|
selection: [
|
|
|
|
'#FFFFFF',
|
|
|
|
'#330033',
|
|
|
|
'#C0C0C0',
|
|
|
|
'#999999',
|
|
|
|
'#666666',
|
|
|
|
'#333333',
|
|
|
|
'#000000',
|
|
|
|
'#FFCCCC',
|
|
|
|
'#FF6666',
|
|
|
|
'#FF0000',
|
|
|
|
'#CC0000',
|
|
|
|
'#990000',
|
|
|
|
'#660000',
|
|
|
|
'#330000',
|
|
|
|
'#FFCC99',
|
|
|
|
'#FF9966',
|
|
|
|
'#FF9900',
|
|
|
|
'#FF6600',
|
|
|
|
'#CC6600',
|
|
|
|
'#993300',
|
|
|
|
'#663300',
|
|
|
|
'#FFFF99',
|
|
|
|
'#FFFF66',
|
|
|
|
'#FFCC66',
|
|
|
|
'#FFCC33',
|
|
|
|
'#CC9933',
|
|
|
|
'#996633',
|
|
|
|
'#663333',
|
|
|
|
'#FFFFCC',
|
|
|
|
'#FFFF33',
|
|
|
|
'#FFFF00',
|
|
|
|
'#FFCC00',
|
|
|
|
'#999900',
|
|
|
|
'#666600',
|
|
|
|
'#333300',
|
|
|
|
'#CCCCCC',
|
|
|
|
'#66FF99',
|
|
|
|
'#33FF33',
|
|
|
|
'#33CC00',
|
|
|
|
'#009900',
|
|
|
|
'#006600',
|
|
|
|
'#003300',
|
|
|
|
'#99FFFF',
|
|
|
|
'#33FFFF',
|
|
|
|
'#66CCCC',
|
|
|
|
'#00CCCC',
|
|
|
|
'#339999',
|
|
|
|
'#336666',
|
|
|
|
'#003333',
|
|
|
|
'#CCFFFF',
|
|
|
|
'#66FFFF',
|
|
|
|
'#33CCFF',
|
|
|
|
'#3366FF',
|
|
|
|
'#3333FF',
|
|
|
|
'#000099',
|
|
|
|
'#000066',
|
|
|
|
'#CCCCFF',
|
|
|
|
'#9999FF',
|
|
|
|
'#6666CC',
|
|
|
|
'#6633FF',
|
|
|
|
'#6600CC',
|
|
|
|
'#333399',
|
|
|
|
'#330099',
|
|
|
|
'#FFCCFF',
|
|
|
|
'#FF99FF',
|
|
|
|
'#CC66CC',
|
|
|
|
'#CC33CC',
|
|
|
|
'#993399',
|
|
|
|
'#663366',
|
|
|
|
'#99FF99'
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
2015-05-06 04:06:13 +02:00
|
|
|
// md break-points values are hard-coded in angular-material/src/core/util/constant.js
|
2016-05-18 20:35:24 +02:00
|
|
|
// $mdMedia has a built-in support for those values but can also evaluate others.
|
|
|
|
// The following breakpoints match our CSS breakpoints in scss/core/variables.scss
|
2015-05-06 04:06:13 +02:00
|
|
|
.constant('sgConstant', {
|
2015-11-30 20:13:15 +01:00
|
|
|
'xs' : '(max-width: 599px)' ,
|
|
|
|
'gt-xs' : '(min-width: 600px)' ,
|
|
|
|
'sm' : '(min-width: 600px) and (max-width: 959px)' ,
|
|
|
|
'gt-sm' : '(min-width: 960px)' ,
|
2016-05-18 20:35:24 +02:00
|
|
|
'md' : '(min-width: 960px) and (max-width: 1023px)' ,
|
|
|
|
'gt-md' : '(min-width: 1024px)' ,
|
|
|
|
'lg' : '(min-width: 1024px) and (max-width: 1279px)',
|
|
|
|
'gt-lg' : '(min-width: 1280px)' ,
|
|
|
|
'xl' : '(min-width: 1920px)' ,
|
|
|
|
'print' : 'print'
|
2015-05-06 04:06:13 +02:00
|
|
|
})
|
|
|
|
|
2015-10-27 16:31:31 +01:00
|
|
|
.config(configure)
|
|
|
|
|
2015-12-08 22:45:24 +01:00
|
|
|
.factory('AuthInterceptor', AuthInterceptor)
|
|
|
|
.factory('ErrorInterceptor', ErrorInterceptor);
|
2015-05-06 04:06:13 +02:00
|
|
|
|
2015-09-09 22:35:09 +02:00
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2016-08-30 17:57:26 +02:00
|
|
|
configure.$inject = ['$logProvider', '$compileProvider', '$httpProvider', '$mdThemingProvider', '$mdAriaProvider'];
|
|
|
|
function configure($logProvider, $compileProvider, $httpProvider, $mdThemingProvider, $mdAriaProvider) {
|
2015-12-04 21:00:58 +01:00
|
|
|
// Accent palette
|
2015-05-06 04:06:13 +02:00
|
|
|
$mdThemingProvider.definePalette('sogo-green', {
|
|
|
|
'50': 'eaf5e9',
|
|
|
|
'100': 'cbe5c8',
|
|
|
|
'200': 'aad6a5',
|
|
|
|
'300': '88c781',
|
|
|
|
'400': '66b86a',
|
|
|
|
'500': '56b04c',
|
|
|
|
'600': '4da143',
|
|
|
|
'700': '388e3c',
|
|
|
|
'800': '367d2e',
|
|
|
|
'900': '225e1b',
|
2015-12-04 21:00:58 +01:00
|
|
|
// 'A100': 'b9f6ca',
|
2016-11-17 21:42:14 +01:00
|
|
|
'A100': 'fafafa', // assigned to md-hue-1, equivalent to grey-50 (default background palette)
|
2015-05-06 04:06:13 +02:00
|
|
|
'A200': '69f0ae',
|
|
|
|
'A400': '00e676',
|
|
|
|
'A700': '00c853',
|
|
|
|
'contrastDefaultColor': 'dark',
|
2015-12-04 21:00:58 +01:00
|
|
|
// 'contrastDarkColors': ['50', '100', '200', 'A100'],
|
2015-09-09 22:35:09 +02:00
|
|
|
'contrastLightColors': ['300', '400', '500', '600', '700', '800', '900']
|
2015-05-06 04:06:13 +02:00
|
|
|
});
|
2015-12-04 21:00:58 +01:00
|
|
|
// Primary palette
|
2015-05-06 04:06:13 +02:00
|
|
|
$mdThemingProvider.definePalette('sogo-blue', {
|
|
|
|
'50': 'f0faf9',
|
|
|
|
'100': 'e1f5f3',
|
|
|
|
'200': 'ceebe8',
|
|
|
|
'300': 'bfe0dd',
|
|
|
|
'400': 'b2d6d3',
|
|
|
|
'500': 'a1ccc8',
|
|
|
|
'600': '8ebfbb',
|
|
|
|
'700': '7db3b0',
|
|
|
|
'800': '639997',
|
|
|
|
'900': '4d8080',
|
|
|
|
'A100': 'd4f7fa',
|
|
|
|
'A200': 'c3f5fa',
|
|
|
|
'A400': '53e3f0',
|
|
|
|
'A700': '00b0c0',
|
|
|
|
'contrastDefaultColor': 'light',
|
|
|
|
'contrastDarkColors': ['50', '100', '200'],
|
2015-12-04 21:00:58 +01:00
|
|
|
// 'contrastLightColors': ['300', '400', '500', '600', '700', '800', '900', 'A100', 'A200', 'A400', 'A700']
|
2015-05-06 04:06:13 +02:00
|
|
|
});
|
2015-12-04 21:00:58 +01:00
|
|
|
// Background palette
|
2015-05-06 04:06:13 +02:00
|
|
|
$mdThemingProvider.definePalette('sogo-paper', {
|
|
|
|
'50': 'fcf7f8',
|
|
|
|
'100': 'f7f1dc',
|
|
|
|
'200': 'ede5ca',
|
|
|
|
'300': 'e6d8ba',
|
|
|
|
'400': 'e2d2a3',
|
|
|
|
'500': 'd6c48d',
|
|
|
|
'600': 'baa870',
|
|
|
|
'700': '857545',
|
|
|
|
'800': '524517',
|
|
|
|
'900': '433809',
|
|
|
|
'1000': '000000',
|
|
|
|
'A100': 'ffffff',
|
|
|
|
'A200': 'eeeeee',
|
|
|
|
'A400': 'bdbdbd',
|
|
|
|
'A700': '616161',
|
|
|
|
'contrastDefaultColor': 'dark',
|
2015-09-09 22:35:09 +02:00
|
|
|
'contrastLightColors': ['800', '900']
|
2015-05-06 04:06:13 +02:00
|
|
|
});
|
|
|
|
// Default theme definition
|
|
|
|
$mdThemingProvider.theme('default')
|
|
|
|
.primaryPalette('sogo-blue', {
|
2015-12-04 21:00:58 +01:00
|
|
|
'default': '900',
|
|
|
|
'hue-1': '400',
|
|
|
|
'hue-2': '800',
|
2015-05-06 04:06:13 +02:00
|
|
|
'hue-3': 'A700'
|
|
|
|
})
|
|
|
|
.accentPalette('sogo-green', {
|
|
|
|
'default': '500',
|
2015-12-04 21:00:58 +01:00
|
|
|
// 'hue-1': '200',
|
2016-11-17 21:42:14 +01:00
|
|
|
'hue-1': 'A100', // grey-50
|
2015-05-06 04:06:13 +02:00
|
|
|
'hue-2': '300',
|
|
|
|
'hue-3': 'A700'
|
|
|
|
});
|
2015-09-11 16:56:57 +02:00
|
|
|
|
|
|
|
if (!DebugEnabled) {
|
2016-09-20 20:09:19 +02:00
|
|
|
// Disable debugging information
|
2015-09-11 16:56:57 +02:00
|
|
|
$logProvider.debugEnabled(false);
|
|
|
|
$compileProvider.debugInfoEnabled(false);
|
2016-09-20 20:09:19 +02:00
|
|
|
// Disable warnings
|
2016-08-30 17:57:26 +02:00
|
|
|
$mdAriaProvider.disableWarnings();
|
2016-09-20 20:09:19 +02:00
|
|
|
// Disable theme generation but keep definition in config (required by mdColors)
|
|
|
|
$mdThemingProvider.generateThemesOnDemand(true);
|
|
|
|
// Disable theming completely
|
|
|
|
//$mdThemingProvider.disableTheming();
|
2015-09-11 16:56:57 +02:00
|
|
|
}
|
2015-10-27 16:31:31 +01:00
|
|
|
|
|
|
|
$httpProvider.interceptors.push('AuthInterceptor');
|
2015-12-08 22:45:24 +01:00
|
|
|
$httpProvider.interceptors.push('ErrorInterceptor');
|
2015-10-27 16:31:31 +01:00
|
|
|
}
|
|
|
|
|
2016-08-30 17:57:26 +02:00
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2015-10-27 16:31:31 +01:00
|
|
|
AuthInterceptor.$inject = ['$window', '$q'];
|
|
|
|
function AuthInterceptor($window, $q) {
|
|
|
|
return {
|
|
|
|
response: function(response) {
|
|
|
|
// When expecting JSON but receiving HTML, assume session has expired and reload page
|
2016-01-14 20:45:50 +01:00
|
|
|
if (response && /^application\/json/.test(response.config.headers.Accept) &&
|
2016-12-01 17:56:07 +01:00
|
|
|
/^[\n\r ]*<!DOCTYPE html>/.test(response.data)) {
|
2015-10-27 16:31:31 +01:00
|
|
|
$window.location.reload(true);
|
|
|
|
return $q.reject();
|
|
|
|
}
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
};
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
|
2015-12-08 22:45:24 +01:00
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2017-03-01 15:37:37 +01:00
|
|
|
ErrorInterceptor.$inject = ['$rootScope', '$q', '$injector'];
|
|
|
|
function ErrorInterceptor($rootScope, $q, $injector) {
|
2015-12-08 22:45:24 +01:00
|
|
|
return {
|
|
|
|
responseError: function(rejection) {
|
2017-03-01 17:14:59 +01:00
|
|
|
var deferred, iframe;
|
2017-03-01 22:31:36 +01:00
|
|
|
if (/^application\/json/.test(rejection.config.headers.Accept)) {
|
|
|
|
// Handle CAS ticket renewal (TODO: add check on usesCASAuthentication)
|
|
|
|
if (rejection.status == -1) {
|
|
|
|
deferred = $q.defer();
|
|
|
|
iframe = angular.element('<iframe class="ng-hide" src="' + UserFolderURL + 'recover"></iframe>');
|
|
|
|
iframe.on('load', function() {
|
|
|
|
// Once the browser has followed the redirection, send the initial request
|
|
|
|
var $http = $injector.get('$http');
|
|
|
|
$http(rejection.config).then(deferred.resolve, deferred.reject);
|
|
|
|
iframe.remove();
|
|
|
|
});
|
|
|
|
document.body.appendChild(iframe[0]);
|
|
|
|
return deferred.promise;
|
|
|
|
}
|
|
|
|
else {
|
2017-03-01 17:14:59 +01:00
|
|
|
// Broadcast the response error
|
|
|
|
$rootScope.$broadcast('http:Error', rejection);
|
2017-03-01 15:37:37 +01:00
|
|
|
}
|
2017-03-01 17:14:59 +01:00
|
|
|
}
|
2017-03-01 22:31:36 +01:00
|
|
|
return $q.reject(rejection);
|
2015-12-08 22:45:24 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-05-06 04:06:13 +02:00
|
|
|
})();
|