modal-controllers.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /* eslint-disable
  2. n/handle-callback-err,
  3. max-len,
  4. no-return-assign,
  5. */
  6. // TODO: This file was created by bulk-decaffeinate.
  7. // Fix any style issues and re-enable lint.
  8. /*
  9. * decaffeinate suggestions:
  10. * DS102: Remove unnecessary code created because of implicit returns
  11. * DS207: Consider shorter variations of null checks
  12. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  13. */
  14. import App from '../../base'
  15. App.controller(
  16. 'RenameProjectModalController',
  17. function ($scope, $modalInstance, $timeout, project, queuedHttp) {
  18. $scope.inputs = { projectName: project.name }
  19. $scope.state = {
  20. inflight: false,
  21. error: false,
  22. }
  23. $modalInstance.opened.then(() =>
  24. $timeout(() => $scope.$broadcast('open'), 200)
  25. )
  26. $scope.rename = function () {
  27. $scope.state.inflight = true
  28. $scope.state.error = false
  29. return $scope
  30. .renameProject(project, $scope.inputs.projectName)
  31. .then(function () {
  32. $scope.state.inflight = false
  33. $scope.state.error = false
  34. return $modalInstance.close()
  35. })
  36. .catch(function (response) {
  37. const { data, status } = response
  38. $scope.state.inflight = false
  39. if (status === 400) {
  40. return ($scope.state.error = { message: data })
  41. } else {
  42. return ($scope.state.error = true)
  43. }
  44. })
  45. }
  46. return ($scope.cancel = () => $modalInstance.dismiss('cancel'))
  47. }
  48. )
  49. App.controller(
  50. 'CloneProjectModalController',
  51. function ($scope, $modalInstance, $timeout, project) {
  52. $scope.inputs = { projectName: project.name + ' (Copy)' }
  53. $scope.state = {
  54. inflight: false,
  55. error: false,
  56. }
  57. $modalInstance.opened.then(() =>
  58. $timeout(() => $scope.$broadcast('open'), 200)
  59. )
  60. $scope.clone = function () {
  61. $scope.state.inflight = true
  62. return $scope
  63. .cloneProject(project, $scope.inputs.projectName)
  64. .then(function () {
  65. $scope.state.inflight = false
  66. $scope.state.error = false
  67. return $modalInstance.close()
  68. })
  69. .catch(function (response) {
  70. const { data, status } = response
  71. $scope.state.inflight = false
  72. if (status === 400) {
  73. return ($scope.state.error = { message: data })
  74. } else {
  75. return ($scope.state.error = true)
  76. }
  77. })
  78. }
  79. return ($scope.cancel = () => $modalInstance.dismiss('cancel'))
  80. }
  81. )
  82. App.controller(
  83. 'NewProjectModalController',
  84. function ($scope, $modalInstance, $timeout, template) {
  85. $scope.inputs = { projectName: '' }
  86. $scope.state = {
  87. inflight: false,
  88. error: false,
  89. }
  90. $modalInstance.opened.then(() =>
  91. $timeout(() => $scope.$broadcast('open'), 200)
  92. )
  93. $scope.create = function () {
  94. $scope.state.inflight = true
  95. $scope.state.error = false
  96. return $scope
  97. .createProject($scope.inputs.projectName, template)
  98. .then(function (response) {
  99. const { data } = response
  100. $scope.state.inflight = false
  101. $scope.state.error = false
  102. return $modalInstance.close(data.project_id)
  103. })
  104. .catch(function (response) {
  105. const { data, status } = response
  106. $scope.state.inflight = false
  107. if (status === 400) {
  108. return ($scope.state.error = { message: data })
  109. } else {
  110. return ($scope.state.error = true)
  111. }
  112. })
  113. }
  114. return ($scope.cancel = () => $modalInstance.dismiss('cancel'))
  115. }
  116. )
  117. App.controller(
  118. 'ArchiveTrashLeaveOrDeleteProjectsModalController',
  119. function ($scope, $modalInstance, $timeout, projects, action) {
  120. $scope.projects = projects
  121. $scope.action = action
  122. $scope.confirm = () => $modalInstance.close({ projects, action })
  123. $scope.cancel = () => $modalInstance.dismiss('cancel')
  124. }
  125. )
  126. App.controller(
  127. 'UploadProjectModalController',
  128. function ($scope, $modalInstance, $timeout) {
  129. $scope.cancel = () => $modalInstance.dismiss('cancel')
  130. return ($scope.onComplete = function (error, name, response) {
  131. if (response.project_id != null) {
  132. return (window.location = `/project/${response.project_id}`)
  133. }
  134. })
  135. }
  136. )
  137. App.controller(
  138. 'V1ImportModalController',
  139. function ($scope, $modalInstance, project) {
  140. $scope.project = project
  141. return ($scope.dismiss = () => $modalInstance.dismiss('cancel'))
  142. }
  143. )
  144. export default App.controller(
  145. 'ShowErrorModalController',
  146. function ($scope, $modalInstance, error) {
  147. $scope.error = error
  148. return ($scope.cancel = () => $modalInstance.dismiss('cancel'))
  149. }
  150. )