From bff2d826dc5f8557ed5305e9e59f0981b6fdf58b Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Fri, 14 Oct 2016 08:51:35 +0200 Subject: [PATCH] Fix event handling and emiting. --- accountant-ui/js/app.js | 2 +- accountant-ui/js/operations.js | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/accountant-ui/js/app.js b/accountant-ui/js/app.js index 1520f9d..4dd1b87 100644 --- a/accountant-ui/js/app.js +++ b/accountant-ui/js/app.js @@ -156,7 +156,7 @@ angular.module('accountant', [ vm.onAuthLoginRequired = $rootScope.$on('event:auth-loginRequired', vm.showLoginForm); - vm.$on('$destroy', function() { + $rootScope.$on('$destroy', function() { vm.onAuthLoginRequired = angular.noop(); }); }) diff --git a/accountant-ui/js/operations.js b/accountant-ui/js/operations.js index f02025f..ce14598 100644 --- a/accountant-ui/js/operations.js +++ b/accountant-ui/js/operations.js @@ -205,7 +205,7 @@ angular.module('accountant.operations', [ vm.getBalance(args.begin, args.end); }); - vm.$on('$destroy', function(){ + $rootScope.$on('$destroy', function(){ vm.onRangeSelected = angular.noop(); }); } @@ -214,7 +214,7 @@ angular.module('accountant.operations', [ /* * Controller for the sold chart. */ -.controller('SoldChartController', function($rootScope, $http, OHLC) { +.controller('SoldChartController', function($rootScope, $scope, $http, OHLC) { var vm = this; // Configure chart for operations. @@ -285,7 +285,7 @@ angular.module('accountant.operations', [ minRange: 3600 * 1000 * 24 * 14, // 2 weeks events: { afterSetExtremes: function(e) { - vm.$emit('rangeSelectedEvent', { + $scope.$emit('rangeSelectedEvent', { begin: moment.utc(e.min), end: moment.utc(e.max) }); } @@ -320,7 +320,7 @@ angular.module('accountant.operations', [ ]); }); - vm.$emit('rangeSelectedEvent', { + $scope.$emit('rangeSelectedEvent', { begin: vm.config.xAxis.currentMin, end: vm.config.xAxis.currentMax }); @@ -344,7 +344,7 @@ angular.module('accountant.operations', [ vm.config.yAxis.plotLines[1].value = account.authorized_overdraft; }); - vm.$on('$destroy', function() { + $rootScope.$on('$destroy', function() { vm.onOperationSaved = angular.noop(); vm.onOperationDeleted = angular.noop(); vm.onAccountLoaded = angular.noop(); @@ -357,7 +357,7 @@ angular.module('accountant.operations', [ /* * Controller for the operations. */ -.controller('OperationController', function($rootScope, $routeParams, $ngBootbox, Notification, Account, Operation) { +.controller('OperationController', function($rootScope, $scope, $routeParams, $ngBootbox, Notification, Account, Operation) { var vm = this; // List of operations. @@ -438,7 +438,7 @@ angular.module('accountant.operations', [ return operation.$save().then(function(data) { Notification.success('Operation #' + data.id + ' saved.'); - vm.$emit('operationSavedEvent', data); + $scope.$emit('operationSavedEvent', data); }); }; @@ -458,7 +458,7 @@ angular.module('accountant.operations', [ // Remove operation from array. vm.operation.splice($index, 1); - vm.$emit('operationDeletedEvent', operation); + $scope.$emit('operationDeletedEvent', operation); }); } } @@ -476,7 +476,7 @@ angular.module('accountant.operations', [ vm.load(args.begin, args.end); }); - vm.$on('$destroy', function() { + $rootScope.$on('$destroy', function() { vm.onRangeSelected = angular.noop; }); })