overleaf/services/web/public/coffee/models/Folder.coffee
2014-06-06 14:43:45 +01:00

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