Sidebar save sidebar object to local variable
This commit is contained in:
parent
3d0a20452f
commit
50bfc8db09
1 changed files with 54 additions and 58 deletions
|
@ -1,5 +1,5 @@
|
|||
class Sidebar extends Class
|
||||
constructor: ->
|
||||
constructor: (@wrapper) ->
|
||||
@tag = null
|
||||
@container = null
|
||||
@opened = false
|
||||
|
@ -15,7 +15,7 @@ class Sidebar extends Class
|
|||
@globe = null
|
||||
@preload_html = null
|
||||
|
||||
@original_set_site_info = wrapper.setSiteInfo # We going to override this, save the original
|
||||
@original_set_site_info = @wrapper.setSiteInfo # We going to override this, save the original
|
||||
|
||||
# Start in opened state for debugging
|
||||
if false
|
||||
|
@ -26,14 +26,6 @@ class Sidebar extends Class
|
|||
|
||||
|
||||
initFixbutton: ->
|
||||
###
|
||||
@fixbutton.on "mousedown touchstart", (e) =>
|
||||
if not @opened
|
||||
@logStart("Preloading")
|
||||
wrapper.ws.cmd "sidebarGetHtmlTag", {}, (res) =>
|
||||
@logEnd("Preloading")
|
||||
@preload_html = res
|
||||
###
|
||||
|
||||
# Detect dragging
|
||||
@fixbutton.on "mousedown touchstart", (e) =>
|
||||
|
@ -121,9 +113,9 @@ class Sidebar extends Class
|
|||
$(window).trigger "resize"
|
||||
|
||||
# Override setsiteinfo to catch changes
|
||||
wrapper.setSiteInfo = (site_info) =>
|
||||
@wrapper.setSiteInfo = (site_info) =>
|
||||
@setSiteInfo(site_info)
|
||||
@original_set_site_info.apply(wrapper, arguments)
|
||||
@original_set_site_info.apply(@wrapper, arguments)
|
||||
|
||||
# Preload world.jpg
|
||||
img = new Image();
|
||||
|
@ -154,7 +146,7 @@ class Sidebar extends Class
|
|||
@setHtmlTag(@preload_html)
|
||||
@preload_html = null
|
||||
else
|
||||
wrapper.ws.cmd "sidebarGetHtmlTag", {}, @setHtmlTag
|
||||
@wrapper.ws.cmd "sidebarGetHtmlTag", {}, @setHtmlTag
|
||||
|
||||
setHtmlTag: (res) =>
|
||||
if @tag.find(".content").children().length == 0 # First update
|
||||
|
@ -262,59 +254,59 @@ class Sidebar extends Class
|
|||
|
||||
# Site limit button
|
||||
@tag.find("#button-sitelimit").off("click touchend").on "click touchend", =>
|
||||
wrapper.ws.cmd "siteSetLimit", $("#input-sitelimit").val(), (res) =>
|
||||
@wrapper.ws.cmd "siteSetLimit", $("#input-sitelimit").val(), (res) =>
|
||||
if res == "ok"
|
||||
wrapper.notifications.add "done-sitelimit", "done", "Site storage limit modified!", 5000
|
||||
@wrapper.notifications.add "done-sitelimit", "done", "Site storage limit modified!", 5000
|
||||
@updateHtmlTag()
|
||||
return false
|
||||
|
||||
# Database reload
|
||||
@tag.find("#button-dbreload").off("click touchend").on "click touchend", =>
|
||||
wrapper.ws.cmd "dbReload", [], =>
|
||||
wrapper.notifications.add "done-dbreload", "done", "Database schema reloaded!", 5000
|
||||
@wrapper.ws.cmd "dbReload", [], =>
|
||||
@wrapper.notifications.add "done-dbreload", "done", "Database schema reloaded!", 5000
|
||||
@updateHtmlTag()
|
||||
return false
|
||||
|
||||
# Database rebuild
|
||||
@tag.find("#button-dbrebuild").off("click touchend").on "click touchend", =>
|
||||
wrapper.notifications.add "done-dbrebuild", "info", "Database rebuilding...."
|
||||
wrapper.ws.cmd "dbRebuild", [], =>
|
||||
wrapper.notifications.add "done-dbrebuild", "done", "Database rebuilt!", 5000
|
||||
@wrapper.notifications.add "done-dbrebuild", "info", "Database rebuilding...."
|
||||
@wrapper.ws.cmd "dbRebuild", [], =>
|
||||
@wrapper.notifications.add "done-dbrebuild", "done", "Database rebuilt!", 5000
|
||||
@updateHtmlTag()
|
||||
return false
|
||||
|
||||
# Update site
|
||||
@tag.find("#button-update").off("click touchend").on "click touchend", =>
|
||||
@tag.find("#button-update").addClass("loading")
|
||||
wrapper.ws.cmd "siteUpdate", wrapper.site_info.address, =>
|
||||
wrapper.notifications.add "done-updated", "done", "Site updated!", 5000
|
||||
@wrapper.ws.cmd "siteUpdate", @wrapper.site_info.address, =>
|
||||
@wrapper.notifications.add "done-updated", "done", "Site updated!", 5000
|
||||
@tag.find("#button-update").removeClass("loading")
|
||||
return false
|
||||
|
||||
# Pause site
|
||||
@tag.find("#button-pause").off("click touchend").on "click touchend", =>
|
||||
@tag.find("#button-pause").addClass("hidden")
|
||||
wrapper.ws.cmd "sitePause", wrapper.site_info.address
|
||||
@wrapper.ws.cmd "sitePause", @wrapper.site_info.address
|
||||
return false
|
||||
|
||||
# Resume site
|
||||
@tag.find("#button-resume").off("click touchend").on "click touchend", =>
|
||||
@tag.find("#button-resume").addClass("hidden")
|
||||
wrapper.ws.cmd "siteResume", wrapper.site_info.address
|
||||
@wrapper.ws.cmd "siteResume", @wrapper.site_info.address
|
||||
return false
|
||||
|
||||
# Delete site
|
||||
@tag.find("#button-delete").off("click touchend").on "click touchend", =>
|
||||
wrapper.displayConfirm "Are you sure?", ["Delete this site", "Blacklist"], (confirmed) =>
|
||||
@wrapper.displayConfirm "Are you sure?", ["Delete this site", "Blacklist"], (confirmed) =>
|
||||
if confirmed == 1
|
||||
@tag.find("#button-delete").addClass("loading")
|
||||
wrapper.ws.cmd "siteDelete", wrapper.site_info.address, ->
|
||||
@wrapper.ws.cmd "siteDelete", @wrapper.site_info.address, ->
|
||||
document.location = $(".fixbutton-bg").attr("href")
|
||||
else if confirmed == 2
|
||||
wrapper.displayPrompt "Blacklist this site", "text", "Delete and Blacklist", "Reason", (reason) =>
|
||||
@wrapper.displayPrompt "Blacklist this site", "text", "Delete and Blacklist", "Reason", (reason) =>
|
||||
@tag.find("#button-delete").addClass("loading")
|
||||
wrapper.ws.cmd "blacklistAdd", [wrapper.site_info.address, reason]
|
||||
wrapper.ws.cmd "siteDelete", wrapper.site_info.address, ->
|
||||
@wrapper.ws.cmd "blacklistAdd", [@wrapper.site_info.address, reason]
|
||||
@wrapper.ws.cmd "siteDelete", @wrapper.site_info.address, ->
|
||||
document.location = $(".fixbutton-bg").attr("href")
|
||||
|
||||
|
||||
|
@ -322,35 +314,35 @@ class Sidebar extends Class
|
|||
|
||||
# Owned checkbox
|
||||
@tag.find("#checkbox-owned").off("click touchend").on "click touchend", =>
|
||||
wrapper.ws.cmd "siteSetOwned", [@tag.find("#checkbox-owned").is(":checked")]
|
||||
@wrapper.ws.cmd "siteSetOwned", [@tag.find("#checkbox-owned").is(":checked")]
|
||||
|
||||
# Owned checkbox
|
||||
@tag.find("#checkbox-autodownloadoptional").off("click touchend").on "click touchend", =>
|
||||
wrapper.ws.cmd "siteSetAutodownloadoptional", [@tag.find("#checkbox-autodownloadoptional").is(":checked")]
|
||||
@wrapper.ws.cmd "siteSetAutodownloadoptional", [@tag.find("#checkbox-autodownloadoptional").is(":checked")]
|
||||
|
||||
# Change identity button
|
||||
@tag.find("#button-identity").off("click touchend").on "click touchend", =>
|
||||
wrapper.ws.cmd "certSelect"
|
||||
@wrapper.ws.cmd "certSelect"
|
||||
return false
|
||||
|
||||
# Owned checkbox
|
||||
@tag.find("#checkbox-owned").off("click touchend").on "click touchend", =>
|
||||
wrapper.ws.cmd "siteSetOwned", [@tag.find("#checkbox-owned").is(":checked")]
|
||||
@wrapper.ws.cmd "siteSetOwned", [@tag.find("#checkbox-owned").is(":checked")]
|
||||
|
||||
# Save settings
|
||||
@tag.find("#button-settings").off("click touchend").on "click touchend", =>
|
||||
wrapper.ws.cmd "fileGet", "content.json", (res) =>
|
||||
@wrapper.ws.cmd "fileGet", "content.json", (res) =>
|
||||
data = JSON.parse(res)
|
||||
data["title"] = $("#settings-title").val()
|
||||
data["description"] = $("#settings-description").val()
|
||||
json_raw = unescape(encodeURIComponent(JSON.stringify(data, undefined, '\t')))
|
||||
wrapper.ws.cmd "fileWrite", ["content.json", btoa(json_raw), true], (res) =>
|
||||
@wrapper.ws.cmd "fileWrite", ["content.json", btoa(json_raw), true], (res) =>
|
||||
if res != "ok" # fileWrite failed
|
||||
wrapper.notifications.add "file-write", "error", "File write error: #{res}"
|
||||
@wrapper.notifications.add "file-write", "error", "File write error: #{res}"
|
||||
else
|
||||
wrapper.notifications.add "file-write", "done", "Site settings saved!", 5000
|
||||
if wrapper.site_info.privatekey
|
||||
wrapper.ws.cmd "siteSign", {privatekey: "stored", inner_path: "content.json", update_changed_files: true}
|
||||
@wrapper.notifications.add "file-write", "done", "Site settings saved!", 5000
|
||||
if @wrapper.site_info.privatekey
|
||||
@wrapper.ws.cmd "siteSign", {privatekey: "stored", inner_path: "content.json", update_changed_files: true}
|
||||
@updateHtmlTag()
|
||||
return false
|
||||
|
||||
|
@ -364,26 +356,26 @@ class Sidebar extends Class
|
|||
menu.addItem "Sign", =>
|
||||
inner_path = @tag.find("#input-contents").val()
|
||||
|
||||
wrapper.ws.cmd "fileRules", {inner_path: inner_path}, (res) =>
|
||||
if wrapper.site_info.privatekey or wrapper.site_info.auth_address in res.signers
|
||||
@wrapper.ws.cmd "fileRules", {inner_path: inner_path}, (res) =>
|
||||
if @wrapper.site_info.privatekey or @wrapper.site_info.auth_address in res.signers
|
||||
# Privatekey stored in users.json
|
||||
wrapper.ws.cmd "siteSign", {privatekey: "stored", inner_path: inner_path, update_changed_files: true}, (res) =>
|
||||
@wrapper.ws.cmd "siteSign", {privatekey: "stored", inner_path: inner_path, update_changed_files: true}, (res) =>
|
||||
if res == "ok"
|
||||
wrapper.notifications.add "sign", "done", "#{inner_path} Signed!", 5000
|
||||
@wrapper.notifications.add "sign", "done", "#{inner_path} Signed!", 5000
|
||||
|
||||
else
|
||||
# Ask the user for privatekey
|
||||
wrapper.displayPrompt "Enter your private key:", "password", "Sign", "", (privatekey) => # Prompt the private key
|
||||
wrapper.ws.cmd "siteSign", {privatekey: privatekey, inner_path: inner_path, update_changed_files: true}, (res) =>
|
||||
@wrapper.displayPrompt "Enter your private key:", "password", "Sign", "", (privatekey) => # Prompt the private key
|
||||
@wrapper.ws.cmd "siteSign", {privatekey: privatekey, inner_path: inner_path, update_changed_files: true}, (res) =>
|
||||
if res == "ok"
|
||||
wrapper.notifications.add "sign", "done", "#{inner_path} Signed!", 5000
|
||||
@wrapper.notifications.add "sign", "done", "#{inner_path} Signed!", 5000
|
||||
|
||||
@tag.find(".contents + .flex").removeClass "active"
|
||||
menu.hide()
|
||||
|
||||
menu.addItem "Publish", =>
|
||||
inner_path = @tag.find("#input-contents").val()
|
||||
wrapper.ws.cmd "sitePublish", {"inner_path": inner_path, "sign": false}
|
||||
@wrapper.ws.cmd "sitePublish", {"inner_path": inner_path, "sign": false}
|
||||
|
||||
@tag.find(".contents + .flex").removeClass "active"
|
||||
menu.hide()
|
||||
|
@ -399,24 +391,25 @@ class Sidebar extends Class
|
|||
return false
|
||||
|
||||
$("body").on "click", =>
|
||||
@tag.find(".contents + .flex").removeClass "active"
|
||||
if @tag
|
||||
@tag.find(".contents + .flex").removeClass "active"
|
||||
|
||||
@tag.find("#button-sign-publish").off("click touchend").on "click touchend", =>
|
||||
inner_path = @tag.find("#input-contents").val()
|
||||
|
||||
wrapper.ws.cmd "fileRules", {inner_path: inner_path}, (res) =>
|
||||
if wrapper.site_info.privatekey or wrapper.site_info.auth_address in res.signers
|
||||
@wrapper.ws.cmd "fileRules", {inner_path: inner_path}, (res) =>
|
||||
if @wrapper.site_info.privatekey or @wrapper.site_info.auth_address in res.signers
|
||||
# Privatekey stored in users.json
|
||||
wrapper.ws.cmd "sitePublish", {privatekey: "stored", inner_path: inner_path, sign: true}, (res) =>
|
||||
@wrapper.ws.cmd "sitePublish", {privatekey: "stored", inner_path: inner_path, sign: true}, (res) =>
|
||||
if res == "ok"
|
||||
wrapper.notifications.add "sign", "done", "#{inner_path} Signed and published!", 5000
|
||||
@wrapper.notifications.add "sign", "done", "#{inner_path} Signed and published!", 5000
|
||||
|
||||
else
|
||||
# Ask the user for privatekey
|
||||
wrapper.displayPrompt "Enter your private key:", "password", "Sign", "", (privatekey) => # Prompt the private key
|
||||
wrapper.ws.cmd "sitePublish", {privatekey: privatekey, inner_path: inner_path, sign: true}, (res) =>
|
||||
@wrapper.displayPrompt "Enter your private key:", "password", "Sign", "", (privatekey) => # Prompt the private key
|
||||
@wrapper.ws.cmd "sitePublish", {privatekey: privatekey, inner_path: inner_path, sign: true}, (res) =>
|
||||
if res == "ok"
|
||||
wrapper.notifications.add "sign", "done", "#{inner_path} Signed and published!", 5000
|
||||
@wrapper.notifications.add "sign", "done", "#{inner_path} Signed and published!", 5000
|
||||
|
||||
return false
|
||||
|
||||
|
@ -438,7 +431,7 @@ class Sidebar extends Class
|
|||
@unloadGlobe()
|
||||
|
||||
# We dont need site info anymore
|
||||
wrapper.setSiteInfo = @original_set_site_info
|
||||
@wrapper.setSiteInfo = @original_set_site_info
|
||||
|
||||
|
||||
loadGlobe: =>
|
||||
|
@ -456,7 +449,7 @@ class Sidebar extends Class
|
|||
img = new Image();
|
||||
img.src = "/uimedia/globe/world.jpg";
|
||||
img.onload = =>
|
||||
wrapper.ws.cmd "sidebarGetPeers", [], (globe_data) =>
|
||||
@wrapper.ws.cmd "sidebarGetPeers", [], (globe_data) =>
|
||||
if @globe
|
||||
@globe.scene.remove(@globe.points)
|
||||
@globe.addData( globe_data, {format: 'magnitude', name: "hello", animated: false} )
|
||||
|
@ -481,7 +474,10 @@ class Sidebar extends Class
|
|||
@globe = null
|
||||
|
||||
|
||||
wrapper = window.wrapper
|
||||
setTimeout ( ->
|
||||
window.sidebar = new Sidebar()
|
||||
window.sidebar = new Sidebar(wrapper)
|
||||
), 500
|
||||
|
||||
|
||||
window.transitionEnd = 'transitionend webkitTransitionEnd oTransitionEnd otransitionend'
|
||||
|
|
Loading…
Reference in a new issue