modal-controllers.js 4.7 KB

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