mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-29 14:03:07 +00:00
36 lines
965 B
CoffeeScript
36 lines
965 B
CoffeeScript
define [
|
|
"models/FolderChildren"
|
|
"models/File"
|
|
"models/Doc"
|
|
"libs/backbone"
|
|
], (FolderChildren, File, Doc) ->
|
|
Folder = Backbone.Model.extend
|
|
initialize: () ->
|
|
if !@get("children")?
|
|
@set("children", new FolderChildren())
|
|
|
|
@get("children").parentFolder = @
|
|
@on "change:children", () =>
|
|
@get("children").parentFolder = @
|
|
|
|
@set("type", "folder")
|
|
|
|
parse: (rawAttributes) ->
|
|
attributes =
|
|
id: rawAttributes._id
|
|
name: rawAttributes.name
|
|
children = []
|
|
for childFolder in rawAttributes.folders or []
|
|
children.push new Folder(childFolder, parse: true)
|
|
for file in rawAttributes.fileRefs or []
|
|
children.push new File(file, parse: true)
|
|
for doc in rawAttributes.docs or []
|
|
children.push new Doc(doc, parse: true)
|
|
attributes.children = new FolderChildren(children)
|
|
return attributes
|
|
|
|
getParentFolderIds: () ->
|
|
ids = @collection?.parentFolder?.getParentFolderIds() or []
|
|
ids.push @id
|
|
return ids
|
|
|