angular.module('app') .controller('PkGuidController', ['$scope', 'pkGuidBusiness', 'AppUtilsBusiness', '$mdDialog', function($scope, pkGuidBusiness, AppUtilsBusiness, $mdDialog) { $scope.selected = []; $scope.query = { order: 'someText', limit: 5, page: 1 }; $scope.pkGuids = null; $scope.error = null; $scope.askRemoveOne = function (pkguid) { var confirm = $mdDialog.confirm() .title('Confirm deletion') .textContent('Do you really want to delete PkGuid \'' + pkguid.someText + '\'?') .ok('Delete') .cancel('Cancel'); $mdDialog.show(confirm).then(function() { $scope.error = null; $scope.promise = pkGuidBusiness.deleteDbo(pkguid.id).then(function(data) { $scope.getPkGuids(); }, function(error) { $scope.error = error; }); }, function () {}); }; $scope.askRemoveSelected = function () { var confirm = $mdDialog.confirm() .title('Confirm deletion') .textContent('Do you really want to delete ' + $scope.selected.length + ' PkGuids?') .ok('Delete') .cancel('Cancel'); $mdDialog.show(confirm).then(function() { $scope.error = null; $scope.removeFirstSelected(); }, function () {}); }; $scope.removeFirstSelected = function() { if ($scope.selected.length == 0) { $scope.getPkGuids(); } else { pkGuidBusiness.deleteDbo($scope.selected[0].id) .then(function(data) { $scope.selected = $scope.selected.splice(1); $scope.removeFirstSelected(); }, function(error) { $scope.error = error; }); } }; $scope.getPkGuids = function() { $scope.error = null; $scope.selected = []; var orderBy = AppUtilsBusiness.convertOrderBy($scope.query.order); $scope.promise = pkGuidBusiness.getMultiple(orderBy, $scope.query.page - 1, $scope.query.limit).then(function(data) { $scope.pkGuids = data; }, function(error) { $scope.pkGuids = null; $scope.error = error; }); }; $scope.getPkGuids(); }]);