選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

cameraedit.controller.js 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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.camera_id = $scope.camera.Id;
  10. $scope.permission = "CAMOTION_CAMERA_EDIT";
  11. }
  12. else {
  13. $scope.camera = {
  14. Name: "",
  15. Description: "",
  16. Token: "",
  17. HostId: null,
  18. EntityTypeId: null
  19. };
  20. $scope.permission = "CAMOTION_CAMERA_ADD";
  21. }
  22. $scope.hosts = {};
  23. $scope.entityTypes = {};
  24. var promiseLoadForeign = {
  25. id: "promiseLoadForeign",
  26. groups: ["modal"]
  27. };
  28. HelperService.getForeignEntities(promiseLoadForeign).then(function(data)
  29. {
  30. $scope.hosts = data.hosts;
  31. $scope.entityTypes = data.entityTypes;
  32. if ($scope.camera.Id == null) {
  33. var keys = Object.keys($scope.hosts);
  34. if (keys.length != 0) {
  35. $scope.camera.HostId = $scope.hosts[keys[0]].Id;
  36. }keys = Object.keys($scope.entityTypes);
  37. if (keys.length != 0) {
  38. $scope.camera.EntityTypeId = $scope.entityTypes[keys[0]].Id;
  39. }
  40. }
  41. });
  42. $scope.submitForm = function()
  43. {
  44. if (luticateAuthCache.hasEffectivePermission($scope.permission)) {
  45. if ($scope.camera.Id != null) {
  46. var promiseEditCamera = {
  47. id: "promiseEditCamera",
  48. loaderGroups: ["modal"]
  49. };
  50. return CamerasService.edit($scope.camera, promiseEditCamera);
  51. }
  52. else {
  53. var promiseAddCamera = {
  54. id: "promiseAddCamera",
  55. loaderGroups: ["modal"]
  56. };
  57. return CamerasService.add($scope.camera, promiseAddCamera);
  58. }
  59. }
  60. else {
  61. var defer = $q.defer();
  62. defer.resolve();
  63. return defer.promise;
  64. }
  65. };
  66. }]);