From b1e1193ca6d7b7389d48c734b07a5bb6c0b74540 Mon Sep 17 00:00:00 2001 From: Daniel Erat Date: Thu, 16 Jun 2011 20:25:55 -0700 Subject: [PATCH] ui: Add support for setting camliAccess attr on permanodes. The attribute can be set to "public" to share to everyone or deleted to keep the permanode private. Change-Id: I075dd7cc5fb6c3726083ae065282178dd7ae99a3 --- server/go/camlistored/ui/permanode.html | 32 +++++++---- server/go/camlistored/ui/permanode.js | 71 ++++++++++++++++++++----- 2 files changed, 80 insertions(+), 23 deletions(-) diff --git a/server/go/camlistored/ui/permanode.html b/server/go/camlistored/ui/permanode.html index cb9bb4a27..59ea17162 100644 --- a/server/go/camlistored/ui/permanode.html +++ b/server/go/camlistored/ui/permanode.html @@ -23,30 +23,40 @@ div.fileupload {

Title: -

+

Tags:

+
+

Access: + + +

+
+

Type: - -

+ +

- +
diff --git a/server/go/camlistored/ui/permanode.js b/server/go/camlistored/ui/permanode.js index 9990de9e3..a9c52f059 100644 --- a/server/go/camlistored/ui/permanode.js +++ b/server/go/camlistored/ui/permanode.js @@ -26,8 +26,8 @@ function handleFormTitleSubmit(e) { var inputTitle = document.getElementById("inputTitle"); inputTitle.disabled = "disabled"; - var btnSave = document.getElementById("btnSave"); - btnSave.disabled = "disabled"; + var btnSaveTitle = document.getElementById("btnSaveTitle"); + btnSaveTitle.disabled = "disabled"; var startTime = new Date(); @@ -40,13 +40,13 @@ function handleFormTitleSubmit(e) { var elapsedMs = new Date().getTime() - startTime.getTime(); setTimeout(function() { inputTitle.disabled = null; - btnSave.disabled = null; + btnSaveTitle.disabled = null; }, Math.max(250 - elapsedMs, 0)); }, fail: function(msg) { alert(msg); inputTitle.disabled = null; - btnSave.disabled = null; + btnSaveTitle.disabled = null; } }); } @@ -81,7 +81,7 @@ function handleFormTagsSubmit(e) { } }; for (idx in tags) { - var tag = tags[idx]; + var tag = tags[idx]; camliNewAddAttributeClaim( getPermanodeParam(), "tag", @@ -96,6 +96,44 @@ function handleFormTagsSubmit(e) { } } +function handleFormAccessSubmit(e) { + e.stopPropagation(); + e.preventDefault(); + + var selectAccess = document.getElementById("selectAccess"); + selectAccess.disabled = "disabled"; + var btnSaveAccess = document.getElementById("btnSaveAccess"); + btnSaveAccess.disabled = "disabled"; + + var operation = camliNewDelAttributeClaim; + var value = ""; + if (selectAccess.value != "private") { + operation = camliNewSetAttributeClaim; + value = selectAccess.value; + } + + var startTime = new Date(); + + operation( + getPermanodeParam(), + "camliAccess", + value, + { + success: function() { + var elapsedMs = new Date().getTime() - startTime.getTime(); + setTimeout(function() { + selectAccess.disabled = null; + btnSaveAccess.disabled = null; + }, Math.max(250 - elapsedMs, 0)); + }, + fail: function(msg) { + alert(msg); + selectAccess.disabled = null; + btnSaveAccess.disabled = null; + } + }); +} + function deleteTagFunc(tag, strikeEle, removeEle) { return function(e) { strikeEle.innerHTML = "" + strikeEle.innerHTML + ""; @@ -121,9 +159,8 @@ function onTypeChange(e) { if (sel.value == "collection" || sel.value == "") { dnd.style.display = "block"; } else { - dnd.style.display = "none"; + dnd.style.display = "none"; } - } var lastFiles; @@ -205,7 +242,7 @@ function onFileInputChange(e) { handleFiles(document.getElementById("fileInput").files); } -function setupFilesHandlers(e) { +function setupFilesHandlers(e) { var dnd = document.getElementById("dnd"); document.getElementById("fileForm").addEventListener("submit", onFileFormSubmit); document.getElementById("fileInput").addEventListener("change", onFileInputChange); @@ -294,7 +331,7 @@ function onBlobDescribed(jres) { var tags = permanodeObject.attr.tag; for (idx in tags) { var tagSpan = document.createElement("span"); - + if (idx > 0) { tagSpan.appendChild(document.createTextNode(", ")); } @@ -313,8 +350,16 @@ function onBlobDescribed(jres) { spanTags.appendChild(tagSpan); } - var btnSave = document.getElementById("btnSave"); - btnSave.disabled = null; + var selectAccess = document.getElementById("selectAccess"); + var access = permanodeObject.attr.camliAccess; + selectAccess.value = (access && access.length) ? access[0] : "private"; + selectAccess.disabled = null; + + var btnSaveTitle = document.getElementById("btnSaveTitle"); + btnSaveTitle.disabled = null; + + var btnSaveAccess = document.getElementById("btnSaveAccess"); + btnSaveAccess.disabled = null; } function permanodePageOnLoad (e) { @@ -328,7 +373,9 @@ function permanodePageOnLoad (e) { formTitle.addEventListener("submit", handleFormTitleSubmit); var formTags = document.getElementById("formTags"); formTags.addEventListener("submit", handleFormTagsSubmit); - + var formAccess = document.getElementById("formAccess"); + formAccess.addEventListener("submit", handleFormAccessSubmit); + var selectType = document.getElementById("type"); selectType.addEventListener("change", onTypeChange);