Code cleanup.

This commit is contained in:
Alexis Lahouze 2015-07-20 12:59:07 +02:00
parent a54da59dc8
commit cf9d15b932

View File

@ -32,12 +32,6 @@ accountantApp
"$scope", "$rootScope", "$routeParams", "Accounts", "$scope", "$rootScope", "$routeParams", "Accounts",
function($scope, $rootScope, $routeParams, Accounts) { function($scope, $rootScope, $routeParams, Accounts) {
$scope.accountClass = function(account) {
if(account == $scope.selectedAccount) {
return "active";
}
};
$scope.valueClass = function(account, value) { $scope.valueClass = function(account, value) {
if(!account) { if(!account) {
return; return;
@ -144,11 +138,6 @@ accountantApp
* Reload acounts when an account is deleted. * Reload acounts when an account is deleted.
*/ */
$rootScope.$on("accountDeletedEvent", function(e, account) { $rootScope.$on("accountDeletedEvent", function(e, account) {
// Reset the selected account if this is the one whe have deleted.
if($scope.selectedAccount.id == account.id) {
$scope.selectedAccount = null;
}
$scope.loadAccounts(); $scope.loadAccounts();
}); });
@ -165,58 +154,5 @@ accountantApp
}); });
}; };
/*
* Update the selected account with loaded one or select the first of the
* list.
*/
$rootScope.$on("accountsLoadedEvent", function(e, accounts) {
var accountToSelect = null;
// Reset selected account to the new instance corresponding to the old
// one.
if($routeParams.accountId) {
// Find the new instance of the previously selected account.
angular.forEach($scope.accounts, function(account) {
if(account.id == $routeParams.accountId) {
// No need to emit accountSelectedEvent.
$scope.selectedAccount = account;
}
});
} else if($scope.selectedAccount) {
// Find the new instance of the previously selected account.
angular.forEach($scope.accounts, function(account) {
if(account.id == $scope.selectedAccount.id) {
// No need to emit accountSelectedEvent.
$scope.selectedAccount = account;
}
});
} else {
// Set selected account to first one if not yet selected
$scope.selectAccount($scope.accounts[0]);
}
});
/*
* Select the account to display and emit accountSelectedEvent.
*/
$scope.selectAccount = function(account) {
$scope.selectedAccount = account;
$scope.$emit("accountSelectedEvent", {account: account});
};
/*
* Refresh account information.
*/
$scope.refreshAccount = function() {
$scope.selectedAccount.$get();
};
$rootScope.$on("entrySavedEvent", $scope.refreshAccount);
$rootScope.$on("entryCreatedEvent", $scope.refreshAccount);
$rootScope.$on("entryRemovedEvent", $scope.refreshAccount);
//$rootScope.$on("operationSavedEvent", $scope.refreshAccount);
//$rootScope.$on("operationRemovedEvent", $scope.refreshAccount);
$scope.loadAccounts(); $scope.loadAccounts();
}]); }]);