Skip to content

Instantly share code, notes, and snippets.

Created June 15, 2016 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/ee36d253a9f9b80b1eba7e8a0bc16872 to your computer and use it in GitHub Desktop.
Save anonymous/ee36d253a9f9b80b1eba7e8a0bc16872 to your computer and use it in GitHub Desktop.
'use strict';
App.controller('PoController', ['$scope', 'PoService', function($scope, PoService) {
var vm = this;
vm.order = {id: null, status: null, item:null , plannedQty: null, plannedDate: '', description:''};
vm.orders = [];
vm.fetchAllOrders = function () {
PoService.fetchAllOrders()
.then(
function (d) {
vm.orders = d;
},
function (errResp) {
console.error('Error while fetching production orders!');
}
);
};
vm.createOrder = function (item) {
PoService.createOrder(item)
.then(
vm.fetchAllOrders,
function (errResponse) {
console.error('Error while creating production order');
}
);
};
vm.fetchAllOrders();
vm.submit = function () {
if (vm.order.id === null) {
console.log('Saving new order', vm.order);
vm.createOrder(vm.order);
} else {
console.log('Sth wrong with adding new order');
}
vm.reset();
};
vm.reset = function () {
vm.order = {id: null, status:null, item: null, plannedQty: null, plannedDate: '', description:''};
$scope.myForm.$setPristine();
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment