FilesResult.coffee 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. class FilesResult extends Class
  2. constructor: ->
  3. @files = new SiteFiles(@)
  4. @files.mode = "result"
  5. @files.limit = 20
  6. @files.update = @updateFiles
  7. @row = {"address": "result"}
  8. @filter_inner_path = ""
  9. updateFiles: (cb) =>
  10. @log "Update FilesResult", @filter_inner_path
  11. if Page.server_info.rev < 4120
  12. Page.projector.scheduleRender()
  13. return cb?()
  14. orderby = @files.orderby + (if @files.orderby_desc then " DESC" else "")
  15. Page.cmd "optionalFileList", {address: "all", filter: "downloaded", filter_inner_path: "%#{@filter_inner_path}%", limit: @files.limit+1, orderby: orderby}, (res) =>
  16. for row in res
  17. row.site = Page.site_list.sites_byaddress[row.address]
  18. @files.items = res[0..@files.limit-1]
  19. @files.loaded = true
  20. @files.has_more = res.length > @files.limit
  21. Page.projector.scheduleRender()
  22. cb?()
  23. setFilter: (filter, cb) =>
  24. @filter_inner_path = filter
  25. @updateFiles(cb)
  26. getHref: (row) =>
  27. return row.inner_path
  28. render: =>
  29. if Page.server_info.rev < 4120
  30. return h("div.empty", [
  31. h("h4", "Feature not supported"),
  32. h("small", "You need to update to the latest version to use this feature")
  33. ])
  34. if not @filter_inner_path
  35. return []
  36. if not @files.items.length
  37. return h("div.empty", [
  38. h("h4", "Filter result: #{@filter_inner_path}"),
  39. h("small", "No files found")
  40. ])
  41. h("div.site", [
  42. h("div.title", [h("h3.name", "Filter result: #{@filter_inner_path}")])
  43. @files.render()
  44. ])
  45. window.FilesResult = FilesResult