PluginList.coffee 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. class PluginList extends Class
  2. constructor: (plugins) ->
  3. @plugins = plugins
  4. savePluginStatus: (plugin, is_enabled) =>
  5. Page.cmd "pluginConfigSet", [plugin.source, plugin.inner_path, "enabled", is_enabled], (res) =>
  6. if res == "ok"
  7. Page.updatePlugins()
  8. else
  9. Page.cmd "wrapperNotification", ["error", res.error]
  10. Page.projector.scheduleRender()
  11. handleCheckboxChange: (e) =>
  12. node = e.currentTarget
  13. plugin = node["data-plugin"]
  14. node.classList.toggle("checked")
  15. value = node.classList.contains("checked")
  16. @savePluginStatus(plugin, value)
  17. handleResetClick: (e) =>
  18. node = e.currentTarget
  19. plugin = node["data-plugin"]
  20. @savePluginStatus(plugin, null)
  21. handleUpdateClick: (e) =>
  22. node = e.currentTarget
  23. plugin = node["data-plugin"]
  24. node.classList.add("loading")
  25. Page.cmd "pluginUpdate", [plugin.source, plugin.inner_path], (res) =>
  26. if res == "ok"
  27. Page.cmd "wrapperNotification", ["done", "Plugin #{plugin.name} updated to latest version"]
  28. Page.updatePlugins()
  29. else
  30. Page.cmd "wrapperNotification", ["error", res.error]
  31. node.classList.remove("loading")
  32. return false
  33. handleDeleteClick: (e) =>
  34. node = e.currentTarget
  35. plugin = node["data-plugin"]
  36. if plugin.loaded
  37. Page.cmd "wrapperNotification", ["info", "You can only delete plugin that are not currently active"]
  38. return false
  39. node.classList.add("loading")
  40. Page.cmd "wrapperConfirm", ["Delete #{plugin.name} plugin?", "Delete"], (res) =>
  41. if not res
  42. node.classList.remove("loading")
  43. return false
  44. Page.cmd "pluginRemove", [plugin.source, plugin.inner_path], (res) =>
  45. if res == "ok"
  46. Page.cmd "wrapperNotification", ["done", "Plugin #{plugin.name} deleted"]
  47. Page.updatePlugins()
  48. else
  49. Page.cmd "wrapperNotification", ["error", res.error]
  50. node.classList.remove("loading")
  51. return false
  52. render: ->
  53. h("div.plugins", @plugins.map (plugin) =>
  54. if not plugin.info
  55. return
  56. descr = plugin.info.description
  57. plugin.info.default ?= "enabled"
  58. if plugin.info.default
  59. descr += " (default: #{plugin.info.default})"
  60. tag_version = ""
  61. tag_source = ""
  62. tag_delete = ""
  63. if plugin.source != "builtin"
  64. tag_update = ""
  65. if plugin.site_info?.rev
  66. if plugin.site_info.rev > plugin.info.rev
  67. tag_update = h("a.version-update.button",
  68. {href: "#Update+plugin", onclick: @handleUpdateClick, "data-plugin": plugin},
  69. "Update to rev#{plugin.site_info.rev}"
  70. )
  71. else
  72. tag_update = h("span.version-missing", "(unable to get latest vesion: update site missing)")
  73. tag_version = h("span.version",[
  74. "rev#{plugin.info.rev} ",
  75. tag_update,
  76. ])
  77. tag_source = h("div.source",[
  78. "Source: ",
  79. h("a", {"href": "/#{plugin.source}", "target": "_top"}, if plugin.site_title then plugin.site_title else plugin.source),
  80. " /" + plugin.inner_path
  81. ])
  82. tag_delete = h("a.delete", {"href": "#Delete+plugin", onclick: @handleDeleteClick, "data-plugin": plugin}, "Delete plugin")
  83. enabled_default = plugin.info.default == "enabled"
  84. if plugin.enabled != plugin.loaded or plugin.updated
  85. marker_title = "Change pending"
  86. is_pending = true
  87. else
  88. marker_title = "Changed from default status (click to reset to #{plugin.info.default})"
  89. is_pending = false
  90. is_changed = plugin.enabled != enabled_default and plugin.owner == "builtin"
  91. h("div.plugin", {key: plugin.name}, [
  92. h("div.title", [
  93. h("h3", [plugin.name, tag_version]),
  94. h("div.description", [descr, tag_source, tag_delete]),
  95. ])
  96. h("div.value.value-right",
  97. h("div.checkbox", {onclick: @handleCheckboxChange, "data-plugin": plugin, classes: {checked: plugin.enabled}}, h("div.checkbox-skin"))
  98. h("a.marker", {
  99. href: "#Reset", title: marker_title,
  100. onclick: @handleResetClick, "data-plugin": plugin,
  101. classes: {visible: is_pending or is_changed, pending: is_pending}
  102. }, "\u2022")
  103. )
  104. ])
  105. )
  106. window.PluginList = PluginList