limitless.directive('cultureSelector', ['$rootScope', 'Zupit.Core.AppService', 'config', '$translate', '$cookies', 'Zupit.Core.HttpClient', 'Zupit.Core.NotificationService', function ($rootScope, app, config, $translate, $cookies, $http,notify) { return { restrict: 'E', replace:true, templateUrl: config.baseUrl + 'app/components/cultureSelector.html', scope:{}, controller: function ($scope) { $translate.use(app.culture); $scope.cultures = config.languages.map(function (c) { return c.toUpperCase() }); $scope.culture =app.culture!==null? app.culture.toUpperCase():''; $scope.changeCulture = function (culture) { if (!app.canILeaveThePage()) { notify.confirm('ARE_YOU_SURE_DIRTY_FORM').then(function () { $cookies.putObject(config.languageCookieName, { language: culture, currency: app.currency, timeZone: $rootScope.timezone._z.name }); app.Loading.show(); $http.get('api/admin/ping').then(function () { window.location.reload(); }); }, function () { }); } else { $cookies.putObject(config.languageCookieName, { language: culture, currency: app.currency, timeZone: $rootScope.timezone._z.name }); app.Loading.show(); $http.get('api/admin/ping').then(function () { $rootScope.$broadcast('CULTURE_CHANGED'); window.location.reload(); }); } } } } }]);