Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

cameraedit.controller.js 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**
  2. * Created by robin on 11/4/15.
  3. */
  4. angular.module('camotionAdmin')
  5. .controller('CameraEditController', ['$scope', 'CamerasService', 'data', 'dialogs', '$q', 'luticateAuthCache', 'HelperService',
  6. function($scope, CamerasService, data, dialogs, $q, luticateAuthCache, HelperService) {
  7. if (data != null) {
  8. $scope.camera = data;
  9. $scope.camera.Data = JSON.parse($scope.camera.Data);
  10. $scope.camera.camera_id = $scope.camera.Id;
  11. $scope.permission = "CAMOTION_CAMERA_EDIT";
  12. }
  13. else {
  14. $scope.camera = {
  15. Name: "",
  16. Description: "",
  17. Data: null,
  18. HostId: null,
  19. CameraTypeId: null
  20. };
  21. $scope.permission = "CAMOTION_CAMERA_ADD";
  22. }
  23. $scope.hosts = {};
  24. $scope.cameraTypes = {};
  25. var promiseLoadForeign = {
  26. id: "promiseLoadForeign",
  27. groups: ["modal"]
  28. };
  29. HelperService.getForeignEntities(CamerasService, promiseLoadForeign).then(function(data)
  30. {
  31. $scope.hosts = data.hosts;
  32. $scope.cameraTypes = data.types;
  33. if ($scope.camera.Id == null) {
  34. var keys = Object.keys($scope.hosts);
  35. if (keys.length != 0) {
  36. $scope.camera.HostId = $scope.hosts[keys[0]].Id;
  37. }keys = Object.keys($scope.cameraTypes);
  38. if (keys.length != 0) {
  39. $scope.camera.CameraTypeId = $scope.cameraTypes[keys[0]].Id;
  40. $scope.setCamerayType($scope.cameraTypes[keys[0]]);
  41. }
  42. }
  43. else if ($scope.camera.Data == null) {
  44. $scope.setCameraType($scope.cameraTypes[$scope.camera.CameraTypeId]);
  45. }
  46. });
  47. $scope.submitForm = function()
  48. {
  49. if (luticateAuthCache.hasEffectivePermission($scope.permission)) {
  50. $scope.camera.Data = JSON.stringify($scope.camera.Data);
  51. if ($scope.camera.Id != null) {
  52. var promiseEditCamera = {
  53. id: "promiseEditCamera",
  54. loaderGroups: ["modal"]
  55. };
  56. return CamerasService.edit($scope.camera, promiseEditCamera);
  57. }
  58. else {
  59. var promiseAddCamera = {
  60. id: "promiseAddCamera",
  61. loaderGroups: ["modal"]
  62. };
  63. return CamerasService.add($scope.camera, promiseAddCamera);
  64. }
  65. }
  66. else {
  67. var defer = $q.defer();
  68. defer.resolve();
  69. return defer.promise;
  70. }
  71. };
  72. $scope.setCameraType = function(cameraType)
  73. {
  74. $scope.camera.CameraTypeId = cameraType.Id;
  75. $scope.camera.Data = JSON.parse($scope.cameraTypes[$scope.camera.CameraTypeId].DefaultData);
  76. };
  77. }]);