Folder.coffee 965 B

123456789101112131415161718192021222324252627282930313233343536
  1. define [
  2. "models/FolderChildren"
  3. "models/File"
  4. "models/Doc"
  5. "libs/backbone"
  6. ], (FolderChildren, File, Doc) ->
  7. Folder = Backbone.Model.extend
  8. initialize: () ->
  9. if !@get("children")?
  10. @set("children", new FolderChildren())
  11. @get("children").parentFolder = @
  12. @on "change:children", () =>
  13. @get("children").parentFolder = @
  14. @set("type", "folder")
  15. parse: (rawAttributes) ->
  16. attributes =
  17. id: rawAttributes._id
  18. name: rawAttributes.name
  19. children = []
  20. for childFolder in rawAttributes.folders or []
  21. children.push new Folder(childFolder, parse: true)
  22. for file in rawAttributes.fileRefs or []
  23. children.push new File(file, parse: true)
  24. for doc in rawAttributes.docs or []
  25. children.push new Doc(doc, parse: true)
  26. attributes.children = new FolderChildren(children)
  27. return attributes
  28. getParentFolderIds: () ->
  29. ids = @collection?.parentFolder?.getParentFolderIds() or []
  30. ids.push @id
  31. return ids