Refactor and additional permissions checks

Don't include non-permitted enterprises in existin product count

Tweaked feedback
This commit is contained in:
Matt-Yorkley
2017-03-07 14:31:44 +00:00
committed by Rob Harrington
parent 91fc3f33a0
commit cc5a335fb7
6 changed files with 67 additions and 60 deletions

View File

@@ -1,15 +1,15 @@
angular.module("ofn.admin").controller "ImportOptionsFormCtrl", ($scope, $timeout, $rootScope, ProductImportService) ->
angular.module("ofn.admin").controller "ImportOptionsFormCtrl", ($scope, $rootScope, ProductImportService) ->
$scope.toggleResetAbsent = () ->
confirmed = confirm 'This will set stock level to zero on all products for this \n' +
'enterprise that are not present in the uploaded file.' if $scope.resetAbsent
if confirmed or !$scope.resetAbsent
ProductImportService.updateResetAbsent($scope.supplierId, $scope.nonUpdated, $scope.resetAbsent)
ProductImportService.updateResetAbsent($scope.supplierId, $scope.resetCount, $scope.resetAbsent)
else
$scope.resetAbsent = false
$scope.resetCount = ProductImportService.resetCount
$scope.resetTotal = ProductImportService.resetTotal
$rootScope.$watch 'resetCount', (newValue) ->
$scope.resetCount = newValue if newValue || newValue == 0
$rootScope.$watch 'resetTotal', (newValue) ->
$scope.resetTotal = newValue if newValue || newValue == 0

View File

@@ -1,15 +1,15 @@
angular.module("ofn.admin").factory "ProductImportService", ($rootScope, $timeout) ->
angular.module("ofn.admin").factory "ProductImportService", ($rootScope) ->
new class ProductImportService
suppliers: {}
resetCount: 0
resetTotal: 0
updateResetAbsent: (supplierId, nonUpdated, resetAbsent) ->
updateResetAbsent: (supplierId, resetCount, resetAbsent) ->
if resetAbsent
@suppliers[supplierId] = nonUpdated
@resetCount += nonUpdated
@suppliers[supplierId] = resetCount
@resetTotal += resetCount
else
@suppliers[supplierId] = null
@resetCount -= nonUpdated
@resetTotal -= resetCount
$rootScope.resetCount = @resetCount
$rootScope.resetTotal = @resetTotal