12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- /**
- * Created by robin on 11/4/15.
- */
-
- angular.module('camotionAdmin')
- .controller('CameraEditController', ['$scope', 'CamerasService', 'data', 'dialogs', '$q', 'luticateAuthCache', 'HelperService',
- function($scope, CamerasService, data, dialogs, $q, luticateAuthCache, HelperService) {
- if (data != null) {
- $scope.camera = data;
- $scope.camera.Data = JSON.parse($scope.camera.Data);
- $scope.camera.camera_id = $scope.camera.Id;
- $scope.permission = "CAMOTION_CAMERA_EDIT";
- }
- else {
- $scope.camera = {
- Name: "",
- Description: "",
- Data: null,
- HostId: null,
- EntityTypeId: null
- };
- $scope.permission = "CAMOTION_CAMERA_ADD";
- }
-
- $scope.hosts = {};
- $scope.entityTypes = {};
- var promiseLoadForeign = {
- id: "promiseLoadForeign",
- groups: ["modal"]
- };
-
- HelperService.getForeignEntities(promiseLoadForeign).then(function(data)
- {
- $scope.hosts = data.hosts;
- $scope.entityTypes = data.entityTypes;
- if ($scope.camera.Id == null) {
- var keys = Object.keys($scope.hosts);
- if (keys.length != 0) {
- $scope.camera.HostId = $scope.hosts[keys[0]].Id;
- }keys = Object.keys($scope.entityTypes);
- if (keys.length != 0) {
- $scope.camera.EntityTypeId = $scope.entityTypes[keys[0]].Id;
- $scope.setEntityType($scope.entityTypes[keys[0]]);
- }
- }
- else if ($scope.camera.Data == null) {
- $scope.setEntityType($scope.entityTypes[$scope.camera.EntityTypeId]);
- }
- });
-
- $scope.submitForm = function()
- {
- if (luticateAuthCache.hasEffectivePermission($scope.permission)) {
- $scope.camera.Data = JSON.stringify($scope.camera.Data);
- if ($scope.camera.Id != null) {
- var promiseEditCamera = {
- id: "promiseEditCamera",
- loaderGroups: ["modal"]
- };
- return CamerasService.edit($scope.camera, promiseEditCamera);
- }
- else {
- var promiseAddCamera = {
- id: "promiseAddCamera",
- loaderGroups: ["modal"]
- };
- return CamerasService.add($scope.camera, promiseAddCamera);
- }
- }
- else {
- var defer = $q.defer();
- defer.resolve();
- return defer.promise;
- }
- };
-
- $scope.setEntityType = function(entityType)
- {
- $scope.camera.EntityTypeId = entityType.Id;
- $scope.camera.Data = JSON.parse($scope.entityTypes[$scope.camera.EntityTypeId].DefaultData);
- };
- }]);
|