Allow deeplinking of domains into email view

This commit is contained in:
Johannes Zellner
2018-04-09 18:00:08 +02:00
parent 9acde7fe86
commit 8565130166
3 changed files with 37 additions and 3 deletions

View File

@@ -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