modal-controllers.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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('DeleteProjectsModalController', function(
  126. $scope,
  127. $modalInstance,
  128. $timeout,
  129. projects
  130. ) {
  131. $scope.projectsToDelete = projects.filter(
  132. project => project.accessLevel === 'owner'
  133. )
  134. $scope.projectsToLeave = projects.filter(
  135. project => project.accessLevel !== 'owner'
  136. )
  137. $scope.projectsToArchive = projects.filter(
  138. project => project.accessLevel === 'owner' && !project.archived
  139. )
  140. if (
  141. $scope.projectsToLeave.length > 0 &&
  142. $scope.projectsToDelete.length > 0
  143. ) {
  144. if (
  145. $scope.projectsToArchive.length > 0 &&
  146. window.ExposedSettings.isOverleaf
  147. ) {
  148. $scope.action = 'archive-and-leave'
  149. } else {
  150. $scope.action = 'delete-and-leave'
  151. }
  152. } else if (
  153. $scope.projectsToLeave.length === 0 &&
  154. $scope.projectsToDelete.length > 0
  155. ) {
  156. if (
  157. $scope.projectsToArchive.length > 0 &&
  158. window.ExposedSettings.isOverleaf
  159. ) {
  160. $scope.action = 'archive'
  161. } else {
  162. $scope.action = 'delete'
  163. }
  164. } else {
  165. $scope.action = 'leave'
  166. }
  167. $scope.delete = () => $modalInstance.close()
  168. return ($scope.cancel = () => $modalInstance.dismiss('cancel'))
  169. })
  170. App.controller('UploadProjectModalController', function(
  171. $scope,
  172. $modalInstance,
  173. $timeout
  174. ) {
  175. $scope.cancel = () => $modalInstance.dismiss('cancel')
  176. return ($scope.onComplete = function(error, name, response) {
  177. if (response.project_id != null) {
  178. return (window.location = `/project/${response.project_id}`)
  179. }
  180. })
  181. })
  182. App.controller('V1ImportModalController', function(
  183. $scope,
  184. $modalInstance,
  185. project
  186. ) {
  187. $scope.project = project
  188. return ($scope.dismiss = () => $modalInstance.dismiss('cancel'))
  189. })
  190. return App.controller('ShowErrorModalController', function(
  191. $scope,
  192. $modalInstance,
  193. error
  194. ) {
  195. $scope.error = error
  196. return ($scope.cancel = () => $modalInstance.dismiss('cancel'))
  197. })
  198. })