genofire/hs_monolith
genofire
/
hs_monolith
Archived
1
0
Fork 0
This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
hs_monolith/webroot/static/js/item-add.controller.js

32 lines
1020 B
JavaScript

'use strict';
angular.module('microStock')
.controller('ItemAddCtrl',['$scope','$http','$stateParams',function($scope,$http,$stateParams){
$scope.product = {};
$scope.obj = {};
$scope.msg = {};
$scope.count = 1;
$http.get(config.microservice_dependencies.productById.replace("%d", $stateParams.productid)).then(function(res) {
$scope.product = res.data
});
$scope.submit = function(){
var count = 0;
function request(){
count++;
return $http.post(config.store.goods.productById.replace("%d",$stateParams.productid),$scope.obj);
}
var last = request();
for(var i=1;i < $scope.count;i++){
last.then(request);
}
last.then(function(){
$scope.obj = {};
$scope.msg = {type:'success',text:'Saved '+count+' good(s) from product '+$scope.product.title+'.'};
},function(){
$scope.msg = {type:'error',text:'Saved '+count+' good(s) from product '+$scope.product.title+'.'};
})
};
}]);