1
0

PostMeta.coffee 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. class PostMeta extends Class
  2. constructor: (@post, @meta) ->
  3. @
  4. afterCreateImage: (tag) =>
  5. Page.scrollwatcher.add tag, =>
  6. try
  7. @image_preview.preview_uri = @image_preview.getPreviewUri()
  8. Page.cmd "optionalFileInfo", @post.user.getPath()+"/"+@post.row.post_id+".jpg", (res) =>
  9. @image_preview.optional_info = res
  10. Page.projector.scheduleRender()
  11. catch e
  12. @log "Image preview error: #{e}"
  13. Page.projector.scheduleRender()
  14. handleImageClick: (e) =>
  15. if @image_preview.load_fullsize or @image_preview.optional_info?.is_downloaded
  16. Page.overlay.zoomImageTag(e.currentTarget, @image_preview.width, @image_preview.height)
  17. else
  18. @image_preview.load_fullsize = true
  19. @image_preview.loading = true
  20. image = new Image()
  21. image.src = "#{@post.user.getPath()}/#{@post.row.post_id}.jpg"
  22. image.onload = =>
  23. @image_preview.loading = false
  24. @image_preview.optional_info.is_downloaded = 1
  25. @image_preview.optional_info.peer += 1
  26. Page.projector.scheduleRender()
  27. Page.projector.scheduleRender()
  28. return false
  29. handleOptionalHelpClick: =>
  30. @post.user.hasHelp (optional_helping) =>
  31. @optional_helping = optional_helping
  32. if @optional_helping
  33. Page.cmd "OptionalHelpRemove", ["data/users/#{@post.user.auth_address}", @post.user.hub]
  34. @optional_helping = false
  35. else
  36. Page.cmd "OptionalHelp", ["data/users/#{@post.user.auth_address}", "#{@post.row.user_name}'s new images", @post.user.hub]
  37. @optional_helping = true
  38. Page.content_profile.update()
  39. Page.projector.scheduleRender()
  40. return true
  41. handleImageDeleteClick: =>
  42. inner_path = "#{@post.user.getPath()}/#{@post.row.post_id}.jpg"
  43. Page.cmd "optionalFileDelete", inner_path, =>
  44. @image_preview.optional_info.is_downloaded = 0
  45. @image_preview.optional_info.peer -= 1
  46. Page.projector.scheduleRender()
  47. handleImageSettingsClick: (e) =>
  48. if e.target.classList.contains("menu-item")
  49. return
  50. @post.user.hasHelp (helping) =>
  51. if not @menu_image
  52. @menu_image = new Menu()
  53. @optional_helping = helping
  54. @menu_image.items = []
  55. @menu_image.items.push ["Help distribute this user's new images", @handleOptionalHelpClick, ( => return @optional_helping)]
  56. @menu_image.items.push ["---"]
  57. if @image_preview.optional_info?.is_downloaded
  58. @menu_image.items.push ["Delete image", @handleImageDeleteClick]
  59. else
  60. @menu_image.items.push ["Show image", @handleImageClick, false]
  61. @menu_image.toggle()
  62. return false
  63. render: =>
  64. if @meta.img
  65. if not @image_preview
  66. @image_preview = new ImagePreview()
  67. @image_preview.setPreviewData(@meta.img)
  68. [width, height] = @image_preview.getSize(530, 600)
  69. if @image_preview?.preview_uri
  70. style_preview = "background-image: url(#{@image_preview.preview_uri})"
  71. else
  72. style_preview = ""
  73. if @image_preview.load_fullsize or @image_preview.optional_info?.is_downloaded
  74. style_fullsize = "background-image: url(#{@post.user.getPath()}/#{@post.row.post_id}.jpg)"
  75. else
  76. style_fullsize = ""
  77. h("div.img.preview", {
  78. afterCreate: @afterCreateImage,
  79. style: "width: #{width}px; height: #{height}px; #{style_preview}",
  80. classes: {downloaded: @image_preview.optional_info?.is_downloaded, hasinfo: @image_preview.optional_info?.peer != null, loading: @image_preview.loading}
  81. },
  82. h("a.fullsize", {href: "#", onclick: @handleImageClick, style: style_fullsize}),
  83. if Page.server_info.rev < 1700
  84. h("small.oldversion", "You need ZeroNet 0.5.0 to view this image")
  85. if @image_preview?.optional_info
  86. h("a.show", {href: "#", onclick: @handleImageClick}, h("div.title", "Loading...\nShow image"))
  87. if @image_preview?.optional_info
  88. h("a.details", {href: "#Settings", onclick: Page.returnFalse, onmousedown: @handleImageSettingsClick}, [
  89. h("div.size", Text.formatSize(@image_preview.optional_info?.size)),
  90. h("div.peers.icon-profile"), @image_preview.optional_info?.peer,
  91. h("a.image-settings", "\u22EE")
  92. if @menu_image then @menu_image.render(".menu-right")
  93. ])
  94. )
  95. window.PostMeta = PostMeta