StartScreen.coffee 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. class StartScreen extends Class
  2. constructor: ->
  3. @
  4. addDots: (s) ->
  5. s = ".".repeat(18-s.length)+s
  6. getTermLines: ->
  7. lines = []
  8. server_info = Page.server_info
  9. site_info = Page.site_info
  10. end_version = server_info.version+" r"+server_info.rev
  11. if server_info.rev > 630
  12. end_version += " [OK]"
  13. else
  14. end_version += " [FAIL]"
  15. if site_info.bad_files == 0
  16. end_publickeys = "[DONE]"
  17. else
  18. if site_info.workers > 0
  19. percent = Math.round(100-(site_info.bad_files/site_info.started_task_num)*100)
  20. end_publickeys = "[ #{percent}%]"
  21. else
  22. end_publickeys = "[BAD:#{site_info.bad_files}]"
  23. end_messages = ""
  24. if site_info.bad_files == 0
  25. end_messages = "[DONE]"
  26. else
  27. if site_info.workers > 0
  28. percent = Math.round(100-(site_info.bad_files/site_info.started_task_num)*100)
  29. end_messages += "[ #{percent}%]"
  30. else
  31. end_messages += "[BAD:#{site_info.bad_files}]"
  32. lines.push("Checking ZeroNet version.......................#{@addDots(end_version)}")
  33. lines.push("Checking public keys in database...............#{@addDots(end_publickeys)}")
  34. lines.push("Checking messages in database..................#{@addDots(end_messages)}")
  35. lines.push("Checking current user's public key in database........[NOT FOUND]")
  36. return lines.join("\n")
  37. handleCertselect: ->
  38. Page.cmd "certSelect", [["zeroid.bit"]]
  39. return false
  40. handleCreate: ->
  41. Page.user.createData()
  42. return false
  43. renderBody: (node) =>
  44. node.innerHTML = Text.renderMarked(node.textContent, {"sanitize": true})
  45. renderNocert: =>
  46. @log "renderNocert"
  47. h("div.StartScreen.nocert", {"key": "nocert", "afterCreate": Animation.addVisibleClass, "exitAnimation": Animation.slideUp}, [
  48. h("div.banner.term", {"afterCreate": Animation.termLines}, ["W E L C O M E T O \n\n#{$('#banner').textContent}\n\n\n"]),
  49. if Page.server_info and Page.site_info
  50. h("div.term", {"afterCreate": Animation.termLines, "delay": 1, "delay_step": 0.2}, [@getTermLines()])
  51. ,
  52. if Page.server_info and Page.site_info
  53. if Page.server_info.rev < 630
  54. h("a.button.button-submit.button-certselect.disabled", {"href": "#Update", "afterCreate": Animation.show, "delay": 0, "style": "margin-left: -150px"}, ["Please update your ZeroNet client!"])
  55. else if not Page.site_info.cert_user_id
  56. h("a.button.button-submit.button-certselect", {"key": "certselect", "href": "#Select+username", "afterCreate": Animation.show, "delay": 1, onclick: @handleCertselect}, ["Select username"])
  57. else
  58. [
  59. h("div.term", {"key": "username-term", "afterCreate": Animation.termLines}, [
  60. "Selected username: #{Page.site_info.cert_user_id}#{'.'.repeat( Math.max(22-Page.site_info.cert_user_id.length, 0) )}......[NO MAILBOX FOUND]"
  61. ]),
  62. h("a.button.button-submit.button-certselect", {"key": "create", "href": "#Create+data", "afterCreate": Animation.show, "delay": 1, onclick: @handleCreate}, ["Create my mailbox"])
  63. ]
  64. ])
  65. renderNomessage: =>
  66. @log "renderNomessage"
  67. h("div.StartScreen.nomessage", {"key": "nomessage", "enterAnimation": Animation.slideDown}, [
  68. h("div.subject", ["Successful registration!"]),
  69. h("div.from", [
  70. "From: ",
  71. h("a.username", {"href": "#"}, "zeromail")
  72. ]),
  73. h("div.body", {afterCreate: @renderBody}, [
  74. """
  75. Hello #{Page.site_info.cert_user_id.replace(/@.*/, "")}!
  76. Welcome to the ZeroNet family. From now on anyone is able to message you in a simple and secure way.
  77. _Best regards: The users of ZeroNet_
  78. ###### PS: To keep your identity safe don't forget to backup your **data/users.json** file!
  79. """
  80. ])
  81. ])
  82. window.start_screen = new StartScreen()