angular.module('app') .controller('PkGuidController', ['$scope', 'pkGuidBusiness', 'AppUtilsBusiness', '$mdDialog', 'luBusyBusiness', function($scope, pkGuidBusiness, AppUtilsBusiness, $mdDialog, luBusyBusiness) { $scope.selected = []; $scope.query = { order: 'someText', filter: '', limit: 5, page: 1 }; $scope.busy = luBusyBusiness.reset(); $scope.appUtils = AppUtilsBusiness; $scope.isFilterShown = false; $scope.pkGuids = null; $scope.showFilter = function(show) { $scope.isFilterShown = show; if (!$scope.isFilterShown) { if ($scope.query.filter != '') { $scope.query.filter = ''; $scope.getPkGuids(); } } }; $scope.askRemoveOne = function (pkguid) { var confirm = $mdDialog.confirm() .title(AppUtilsBusiness.tr('common.confirmDelete')) .textContent(AppUtilsBusiness.tr('pkguid.deleteOne', {text: pkguid.someText})) .ok(AppUtilsBusiness.tr('common.delete')) .cancel(AppUtilsBusiness.tr('common.cancel')); $mdDialog.show(confirm).then(function() { pkGuidBusiness.deleteDbo(pkguid.id, 'pkguid.table').then(function(data) { $scope.getPkGuids(); }, function(error) { }); }, function () {}); }; $scope.askRemoveSelected = function () { var confirm = $mdDialog.confirm() .title(AppUtilsBusiness.tr('common.confirmDelete')) .textContent(AppUtilsBusiness.tr('pkguid.deleteMultiple', {count: $scope.selected.length})) .ok(AppUtilsBusiness.tr('common.delete')) .cancel(AppUtilsBusiness.tr('common.cancel')); $mdDialog.show(confirm).then(function() { $scope.removeFirstSelected(); }, function () {}); }; $scope.removeFirstSelected = function() { if ($scope.selected.length == 0) { $scope.getPkGuids(); } else { pkGuidBusiness.deleteDbo($scope.selected[0].id, 'pkguid.table') .then(function(data) { $scope.selected = $scope.selected.splice(1); $scope.removeFirstSelected(); }, function(error) {}); } }; $scope.getPkGuids = function() { $scope.selected = []; var orderBy = AppUtilsBusiness.convertOrderBy($scope.query.order); pkGuidBusiness.getMultiple(orderBy, $scope.query.filter, $scope.query.page - 1, $scope.query.limit, 'pkguid.table').then(function(data) { $scope.pkGuids = data; }, function(error) { $scope.pkGuids = null; }); }; $scope.getPkGuids(); }]);