/** * Created by robin on 11/4/15. */ angular.module('camotionAdmin') .controller('HostEditController', ['$scope', 'HostsService', 'data', 'dialogs', '$q', 'luticateAuthCache', function($scope, HostsService, data, dialogs, $q, luticateAuthCache) { if (data != null) { $scope.host = data; $scope.host.host_id = $scope.host.Id; $scope.permission = "CAMOTION_HOST_EDIT"; } else { $scope.host = { Name: "", Url: "", Token: "" }; $scope.permission = "CAMOTION_HOST_ADD"; } $scope.submitForm = function() { if (luticateAuthCache.hasEffectivePermission($scope.permission)) { if ($scope.host.Id != null) { var promiseEditHost = { id: "promiseEditHost", loaderGroups: ["modal"] }; return HostsService.edit($scope.host, promiseEditHost); } else { var promiseAddHost = { id: "promiseAddHost", loaderGroups: ["modal"] }; return HostsService.add($scope.host, promiseAddHost); } } else { var defer = $q.defer(); defer.resolve(); return defer.promise; } }; }]);