2017-05-12 10:58:43 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular.module('microStock')
|
|
|
|
.controller('ItemAddCtrl',['$scope','$http','$stateParams',function($scope,$http,$stateParams){
|
|
|
|
$scope.product = {};
|
|
|
|
$scope.obj = {};
|
2017-05-12 11:54:59 +02:00
|
|
|
$scope.msg = {};
|
2017-05-12 10:58:43 +02:00
|
|
|
$scope.count = 1;
|
|
|
|
|
|
|
|
$http.get(config.microservice_dependencies.productById.replace("%d", $stateParams.productid)).then(function(res) {
|
|
|
|
$scope.product = res.data
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.submit = function(){
|
2017-05-12 11:54:59 +02:00
|
|
|
var count = 0;
|
2017-05-12 10:58:43 +02:00
|
|
|
function request(){
|
2017-05-12 11:54:59 +02:00
|
|
|
count++;
|
2017-05-12 10:58:43 +02:00
|
|
|
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);
|
|
|
|
}
|
2017-05-12 11:54:59 +02:00
|
|
|
last.then(function(){
|
|
|
|
$scope.obj = {};
|
2017-05-15 10:22:24 +02:00
|
|
|
$scope.msg = {type:'success',text:'Saved '+count+' good(s) from product '+$scope.product.title+'.'};
|
2017-05-12 11:54:59 +02:00
|
|
|
},function(){
|
2017-05-15 10:22:24 +02:00
|
|
|
$scope.msg = {type:'error',text:'Saved '+count+' good(s) from product '+$scope.product.title+'.'};
|
2017-05-12 10:58:43 +02:00
|
|
|
})
|
|
|
|
};
|
|
|
|
}]);
|