diff --git a/dashboard/src/js/index.js b/dashboard/src/js/index.js
index a84046838..b262fd0e9 100644
--- a/dashboard/src/js/index.js
+++ b/dashboard/src/js/index.js
@@ -74,6 +74,9 @@ app.config(['$routeProvider', function ($routeProvider) {
}).when('/email', {
controller: 'EmailController',
templateUrl: 'views/email.html?<%= revision %>'
+ }).when('/email/:domain', {
+ controller: 'EmailController',
+ templateUrl: 'views/email.html?<%= revision %>'
}).when('/settings', {
controller: 'SettingsController',
templateUrl: 'views/settings.html?<%= revision %>'
diff --git a/dashboard/src/views/email.html b/dashboard/src/views/email.html
index b09073913..e956cc25b 100644
--- a/dashboard/src/views/email.html
+++ b/dashboard/src/views/email.html
@@ -231,7 +231,7 @@
Email
-
+
diff --git a/dashboard/src/views/email.js b/dashboard/src/views/email.js
index 5d01c4931..b7226e007 100644
--- a/dashboard/src/views/email.js
+++ b/dashboard/src/views/email.js
@@ -474,6 +474,10 @@ angular.module('Application').controller('EmailController', ['$scope', '$locatio
}
}
+ $scope.selectDomain = function () {
+ $location.path('/email/' + $scope.selectedDomain.domain, false);
+ };
+
$scope.refreshDomain = function () {
$scope.refreshBusy = true;
@@ -556,6 +560,8 @@ angular.module('Application').controller('EmailController', ['$scope', '$locatio
};
Client.onReady(function () {
+ var domain = $location.path().slice('/email/'.length);
+
Client.getUsers(function (error, users) {
if (error) return console.error('Unable to get user listing.', error);
@@ -569,14 +575,39 @@ angular.module('Application').controller('EmailController', ['$scope', '$locatio
if (error) return console.error('Unable to get domain listing.', error);
$scope.domains = domains;
- $scope.selectedDomain = $scope.domains[0];
+ $scope.selectedDomain = domains.find(function (d) { return d.domain === domain; });
- $scope.refreshDomain();
+ if (!$scope.selectedDomain) {
+ $location.path('/email/' + domains[0].domain, false);
+ } else {
+ $scope.refreshDomain();
+ }
$scope.ready = true;
});
});
+ });
+ function hashChangeListener() {
+ if (!$scope.ready) return;
+
+ // event listener is called from DOM not angular, need to use $apply
+ $scope.$apply(function () {
+ var domain = $location.path().slice('/email/'.length);
+ $scope.selectedDomain = $scope.domains.find(function (d) { return d.domain === domain; });
+
+ if (!$scope.selectedDomain) {
+ $location.path('/email/' + $scope.domains[0].domain, false);
+ } else {
+ $scope.refreshDomain();
+ }
+ });
+ }
+
+ window.addEventListener('hashchange', hashChangeListener);
+
+ $scope.$on('$destroy', function handler() {
+ window.removeEventListener('hashchange', hashChangeListener);
});
// setup all the dialog focus handling