mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
client-side duplicate check for move/rename/create
This commit is contained in:
parent
2f52e6c4b4
commit
63fa024d98
2 changed files with 28 additions and 1 deletions
|
@ -321,7 +321,20 @@ define [
|
|||
|
||||
return null
|
||||
|
||||
existsInThisFolder: (folder, name) ->
|
||||
for entity in folder?.children or []
|
||||
return true if entity.name is name
|
||||
return false
|
||||
|
||||
nameExistsError: (message = "already exists") ->
|
||||
nameExists = @ide.$q.defer()
|
||||
nameExists.reject({data: message})
|
||||
return nameExists.promise
|
||||
|
||||
createDoc: (name, parent_folder = @getCurrentFolder()) ->
|
||||
# check if a doc/file/folder already exists with this name
|
||||
if @existsInThisFolder parent_folder, name
|
||||
return @nameExistsError()
|
||||
# We'll wait for the socket.io notification to actually
|
||||
# add the doc for us.
|
||||
@ide.$http.post "/project/#{@ide.project_id}/doc", {
|
||||
|
@ -331,6 +344,9 @@ define [
|
|||
}
|
||||
|
||||
createFolder: (name, parent_folder = @getCurrentFolder()) ->
|
||||
# check if a doc/file/folder already exists with this name
|
||||
if @existsInThisFolder parent_folder, name
|
||||
return @nameExistsError()
|
||||
# We'll wait for the socket.io notification to actually
|
||||
# add the folder for us.
|
||||
return @ide.$http.post "/project/#{@ide.project_id}/folder", {
|
||||
|
@ -342,6 +358,12 @@ define [
|
|||
renameEntity: (entity, name, callback = (error) ->) ->
|
||||
return if entity.name == name
|
||||
return if name.length >= 150
|
||||
# check if a doc/file/folder already exists with this name
|
||||
parent_folder = @getCurrentFolder()
|
||||
if @existsInThisFolder parent_folder, name
|
||||
return @nameExistsError()
|
||||
# We'll wait for the socket.io notification to actually
|
||||
# do the rename for us.
|
||||
@ide.$http.post("/project/#{@ide.project_id}/#{entity.type}/#{entity.id}/rename", {
|
||||
name: name,
|
||||
_csrf: window.csrfToken
|
||||
|
@ -362,6 +384,10 @@ define [
|
|||
# Abort move if the folder being moved (entity) has the parent_folder as child
|
||||
# since that would break the tree structure.
|
||||
return if @_isChildFolder(entity, parent_folder)
|
||||
# check if a doc/file/folder already exists with this name
|
||||
if @existsInThisFolder entity.name, parent_folder
|
||||
return @nameExistsError()
|
||||
# Wait for the http response before doing the move
|
||||
@ide.queuedHttp.post("/project/#{@ide.project_id}/#{entity.type}/#{entity.id}/move", {
|
||||
folder_id: parent_folder.id
|
||||
_csrf: window.csrfToken
|
||||
|
|
|
@ -3,10 +3,11 @@ define [
|
|||
], (App) ->
|
||||
# We create and provide this as service so that we can access the global ide
|
||||
# from within other parts of the angular app.
|
||||
App.factory "ide", ["$http", "queuedHttp", "$modal", ($http, queuedHttp, $modal) ->
|
||||
App.factory "ide", ["$http", "queuedHttp", "$modal", "$q", ($http, queuedHttp, $modal, $q) ->
|
||||
ide = {}
|
||||
ide.$http = $http
|
||||
ide.queuedHttp = queuedHttp
|
||||
ide.$q = $q
|
||||
|
||||
@recentEvents = []
|
||||
ide.pushEvent = (type, meta = {}) =>
|
||||
|
|
Loading…
Reference in a new issue