angular.module('camotionAdmin') .controller('CommandsController', ['$scope', 'CommandsService', 'HelperService', '$q', 'luticateAuthCache', function($scope, CommandsService, HelperService, $q, luticateAuthCache) { $scope.foreighLoaded = false; $scope.hosts = {}; $scope.commandTypes = {}; $scope.luTable = { columns: [ { name: "Name", width: 3, getValue: function (item) { return item.Name; } }, { name: "Type", width: 3, getValue: function (item) { return $scope.commandTypes[item.CommandTypeId].Name; } }, { name: "Description", width: 6, getValue: function (item) { return item.Description; } } ], canAdd: function() { return luticateAuthCache.hasAllEffectivePermissions([ 'CAMOTION_COMMAND_ADD', 'CAMOTION_HOST_GET' ]) }, canDel: 'CAMOTION_COMMAND_DEL', canEdit: function() { return true; }, getLoadPagePromise: function (page, perPage, query, promise) { var defer = $q.defer(); CommandsService.getAll({page: page, perPage: perPage, query: query}, promise) .then(function(commands) { if (!$scope.foreighLoaded) { HelperService.getForeignEntities(CommandsService, promise).then(function (data) { $scope.hosts = data.hosts; $scope.commandTypes = data.types; $scope.foreighLoaded = true; defer.resolve(commands); }, defer.reject); } else { defer.resolve(commands); } }, defer.reject); return defer.promise; }, getDelPromise: function (id, promise) { return CommandsService.del({command_id: id}, promise); }, getEditController: function () { return "CommandEdit"; } }; }]);