2011-05-30 04:39:23 +00:00
|
|
|
/*
|
|
|
|
Copyright 2011 Google Inc.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Gets the |p| query parameter, assuming that it looks like a blobref.
|
2011-06-23 01:38:58 +00:00
|
|
|
|
2011-05-30 04:39:23 +00:00
|
|
|
function getPermanodeParam() {
|
2012-12-24 01:33:38 +00:00
|
|
|
var blobRef = Camli.getQueryParam('p');
|
|
|
|
return (blobRef && Camli.isPlausibleBlobRef(blobRef)) ? blobRef : null;
|
2011-05-30 04:39:23 +00:00
|
|
|
}
|
2011-05-30 20:36:17 +00:00
|
|
|
|
2011-06-01 06:25:24 +00:00
|
|
|
function handleFormTitleSubmit(e) {
|
2011-05-31 01:22:13 +00:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
|
2011-06-01 06:25:24 +00:00
|
|
|
var inputTitle = document.getElementById("inputTitle");
|
2011-06-23 01:38:58 +00:00
|
|
|
inputTitle.disabled = true;
|
2011-06-17 03:25:55 +00:00
|
|
|
var btnSaveTitle = document.getElementById("btnSaveTitle");
|
2011-06-23 01:38:58 +00:00
|
|
|
btnSaveTitle.disabled = true;
|
2011-05-31 01:22:13 +00:00
|
|
|
|
|
|
|
var startTime = new Date();
|
|
|
|
|
2011-05-30 23:32:25 +00:00
|
|
|
camliNewSetAttributeClaim(
|
|
|
|
getPermanodeParam(),
|
2011-06-01 06:25:24 +00:00
|
|
|
"title",
|
|
|
|
inputTitle.value,
|
2011-05-30 23:32:25 +00:00
|
|
|
{
|
2011-05-31 01:22:13 +00:00
|
|
|
success: function() {
|
|
|
|
var elapsedMs = new Date().getTime() - startTime.getTime();
|
|
|
|
setTimeout(function() {
|
2011-06-23 01:38:58 +00:00
|
|
|
inputTitle.disabled = false;
|
|
|
|
btnSaveTitle.disabled = false;
|
2011-07-02 17:36:32 +00:00
|
|
|
buildPermanodeUi();
|
2011-05-31 01:22:13 +00:00
|
|
|
}, Math.max(250 - elapsedMs, 0));
|
|
|
|
},
|
|
|
|
fail: function(msg) {
|
|
|
|
alert(msg);
|
2011-06-23 01:38:58 +00:00
|
|
|
inputTitle.disabled = false;
|
|
|
|
btnSaveTitle.disabled = false;
|
2011-05-31 01:22:13 +00:00
|
|
|
}
|
2011-05-30 23:32:25 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-06-01 06:25:24 +00:00
|
|
|
function handleFormTagsSubmit(e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
var input = document.getElementById("inputNewTag");
|
|
|
|
var btn = document.getElementById("btnAddTag");
|
2011-06-04 17:10:45 +00:00
|
|
|
|
|
|
|
if (input.value == "") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-06-23 01:38:58 +00:00
|
|
|
input.disabled = true;
|
|
|
|
btn.disabled = true;
|
2011-06-01 06:25:24 +00:00
|
|
|
|
|
|
|
var startTime = new Date();
|
|
|
|
|
2011-06-04 17:10:45 +00:00
|
|
|
var tags = input.value.split(/\s*,\s*/);
|
|
|
|
var nRemain = tags.length;
|
2011-06-01 06:25:24 +00:00
|
|
|
|
2011-06-04 17:10:45 +00:00
|
|
|
var oneDone = function() {
|
|
|
|
nRemain--;
|
|
|
|
if (nRemain == 0) {
|
|
|
|
var elapsedMs = new Date().getTime() - startTime.getTime();
|
|
|
|
setTimeout(function() {
|
2011-06-23 01:38:58 +00:00
|
|
|
input.value = '';
|
|
|
|
input.disabled = false;
|
|
|
|
btn.disabled = false;
|
|
|
|
buildPermanodeUi();
|
2011-06-04 17:10:45 +00:00
|
|
|
}, Math.max(250 - elapsedMs, 0));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
for (idx in tags) {
|
2011-06-17 03:25:55 +00:00
|
|
|
var tag = tags[idx];
|
2011-06-04 17:10:45 +00:00
|
|
|
camliNewAddAttributeClaim(
|
|
|
|
getPermanodeParam(),
|
2011-09-03 22:48:49 +00:00
|
|
|
"tag",
|
2011-06-04 17:10:45 +00:00
|
|
|
tag,
|
|
|
|
{
|
|
|
|
success: oneDone,
|
|
|
|
fail: function(msg) {
|
|
|
|
alert(msg);
|
|
|
|
oneDone();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2011-06-01 06:25:24 +00:00
|
|
|
}
|
|
|
|
|
2011-06-17 03:25:55 +00:00
|
|
|
function handleFormAccessSubmit(e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
var selectAccess = document.getElementById("selectAccess");
|
2011-06-23 01:38:58 +00:00
|
|
|
selectAccess.disabled = true;
|
2011-06-17 03:25:55 +00:00
|
|
|
var btnSaveAccess = document.getElementById("btnSaveAccess");
|
2011-06-23 01:38:58 +00:00
|
|
|
btnSaveAccess.disabled = true;
|
2011-06-17 03:25:55 +00:00
|
|
|
|
|
|
|
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() {
|
2011-06-23 01:38:58 +00:00
|
|
|
selectAccess.disabled = false;
|
|
|
|
btnSaveAccess.disabled = false;
|
2011-06-17 03:25:55 +00:00
|
|
|
}, Math.max(250 - elapsedMs, 0));
|
|
|
|
},
|
|
|
|
fail: function(msg) {
|
|
|
|
alert(msg);
|
2011-06-23 01:38:58 +00:00
|
|
|
selectAccess.disabled = false;
|
|
|
|
btnSaveAccess.disabled = false;
|
2011-06-17 03:25:55 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-06-03 21:16:00 +00:00
|
|
|
function deleteTagFunc(tag, strikeEle, removeEle) {
|
|
|
|
return function(e) {
|
2011-06-23 01:38:58 +00:00
|
|
|
strikeEle.innerHTML = "<del>" + strikeEle.innerHTML + "</del>";
|
2011-06-03 21:16:00 +00:00
|
|
|
camliNewDelAttributeClaim(
|
|
|
|
getPermanodeParam(),
|
2011-09-03 22:48:49 +00:00
|
|
|
"tag",
|
2011-06-03 21:16:00 +00:00
|
|
|
tag,
|
|
|
|
{
|
|
|
|
success: function() {
|
2011-06-23 01:38:58 +00:00
|
|
|
removeEle.parentNode.removeChild(removeEle);
|
2011-06-03 21:16:00 +00:00
|
|
|
},
|
|
|
|
fail: function(msg) {
|
|
|
|
alert(msg);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2011-07-02 17:36:32 +00:00
|
|
|
function onTypeChange() {
|
2011-06-07 17:23:11 +00:00
|
|
|
var sel = document.getElementById("type");
|
|
|
|
var dnd = document.getElementById("dnd");
|
2011-07-04 11:39:04 +00:00
|
|
|
var btnGallery = document.getElementById("btnGallery");
|
2011-06-07 17:23:11 +00:00
|
|
|
|
2011-06-09 01:59:56 +00:00
|
|
|
if (sel.value == "collection" || sel.value == "") {
|
2011-06-07 17:23:11 +00:00
|
|
|
dnd.style.display = "block";
|
2011-07-04 11:39:04 +00:00
|
|
|
btnGallery.style.visibility = 'visible';
|
2011-06-07 17:23:11 +00:00
|
|
|
} else {
|
2011-06-17 03:25:55 +00:00
|
|
|
dnd.style.display = "none";
|
2011-07-04 11:39:04 +00:00
|
|
|
btnGallery.style.visibility = 'hidden';
|
2011-06-07 17:23:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleFiles(files) {
|
|
|
|
for (var i = 0; i < files.length; i++) {
|
|
|
|
var file = files[i];
|
2011-06-09 22:00:20 +00:00
|
|
|
startFileUpload(file);
|
2011-06-07 17:23:11 +00:00
|
|
|
}
|
2011-06-09 22:00:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function startFileUpload(file) {
|
|
|
|
var dnd = document.getElementById("dnd");
|
|
|
|
var up = document.createElement("div");
|
2011-06-23 01:38:58 +00:00
|
|
|
up.className= 'camli-dnd-item';
|
2011-06-09 22:00:20 +00:00
|
|
|
dnd.appendChild(up);
|
|
|
|
var info = "name=" + file.name + " size=" + file.size + "; type=" + file.type;
|
2011-06-10 05:18:22 +00:00
|
|
|
|
|
|
|
var setStatus = function(status) {
|
|
|
|
up.innerHTML = info + " " + status;
|
|
|
|
};
|
|
|
|
setStatus("(scanning)");
|
|
|
|
|
2011-06-09 22:00:20 +00:00
|
|
|
var onFail = function(msg) {
|
2011-06-23 01:38:58 +00:00
|
|
|
up.innerHTML = info + " <strong>fail:</strong> ";
|
2011-06-09 22:00:20 +00:00
|
|
|
up.appendChild(document.createTextNode(msg));
|
|
|
|
};
|
|
|
|
|
2011-06-10 05:05:57 +00:00
|
|
|
var onGotFileSchemaRef = function(fileref) {
|
2011-06-23 01:38:58 +00:00
|
|
|
setStatus(" <strong>fileref: " + fileref + "</strong>");
|
2011-06-10 05:18:22 +00:00
|
|
|
camliCreateNewPermanode(
|
|
|
|
{
|
|
|
|
success: function(filepn) {
|
|
|
|
var doneWithAll = function() {
|
|
|
|
setStatus("- done");
|
2011-06-23 01:38:58 +00:00
|
|
|
buildPermanodeUi();
|
2011-06-10 05:18:22 +00:00
|
|
|
};
|
2011-06-11 07:53:13 +00:00
|
|
|
var addMemberToParent = function() {
|
2011-06-10 05:18:22 +00:00
|
|
|
setStatus("adding member");
|
2011-06-11 07:27:17 +00:00
|
|
|
camliNewAddAttributeClaim(getPermanodeParam(), "camliMember", filepn, { success: doneWithAll, fail: onFail });
|
2011-06-10 05:18:22 +00:00
|
|
|
};
|
|
|
|
var makePermanode = function() {
|
|
|
|
setStatus("making permanode");
|
2011-06-11 07:53:13 +00:00
|
|
|
camliNewSetAttributeClaim(filepn, "camliContent", fileref, { success: addMemberToParent, fail: onFail });
|
2011-06-10 05:18:22 +00:00
|
|
|
};
|
|
|
|
makePermanode();
|
|
|
|
},
|
|
|
|
fail: onFail
|
|
|
|
});
|
2011-06-09 22:00:20 +00:00
|
|
|
};
|
|
|
|
|
2012-12-06 23:58:42 +00:00
|
|
|
camliUploadFile(file, {
|
|
|
|
onContentsRef: function(contentsRef) {
|
2011-06-10 05:18:22 +00:00
|
|
|
setStatus("(checking for dup of " + contentsRef + ")");
|
2012-12-06 23:58:42 +00:00
|
|
|
},
|
2013-01-20 23:32:15 +00:00
|
|
|
success: onGotFileSchemaRef,
|
2012-12-06 23:58:42 +00:00
|
|
|
fail: onFail
|
|
|
|
});
|
2011-06-07 17:23:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function onFileFormSubmit(e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
2012-12-06 22:32:45 +00:00
|
|
|
handleFiles(document.getElementById("fileInput").files);
|
2011-06-07 17:23:11 +00:00
|
|
|
}
|
|
|
|
|
2012-12-06 22:32:45 +00:00
|
|
|
function $(id) { return document.getElementById(id) }
|
|
|
|
|
2011-06-07 17:23:11 +00:00
|
|
|
function onFileInputChange(e) {
|
2012-12-06 22:32:45 +00:00
|
|
|
var s = "";
|
|
|
|
var files = $("fileInput").files;
|
|
|
|
for (var i = 0; i < files.length; i++) {
|
|
|
|
var file = files[i];
|
|
|
|
s += "<p>" + file.name + "</p>";
|
|
|
|
}
|
|
|
|
var fl = $("filelist");
|
|
|
|
fl.innerHTML = s;
|
2011-06-07 17:23:11 +00:00
|
|
|
}
|
|
|
|
|
2012-12-06 22:19:15 +00:00
|
|
|
function setupFilesHandlers() {
|
2011-06-07 17:23:11 +00:00
|
|
|
var dnd = document.getElementById("dnd");
|
|
|
|
document.getElementById("fileForm").addEventListener("submit", onFileFormSubmit);
|
|
|
|
document.getElementById("fileInput").addEventListener("change", onFileInputChange);
|
|
|
|
|
2011-06-23 01:38:58 +00:00
|
|
|
var stop = function(e) {
|
|
|
|
this.classList && this.classList.add('camli-dnd-over');
|
2011-06-07 17:23:11 +00:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
};
|
|
|
|
dnd.addEventListener("dragenter", stop, false);
|
|
|
|
dnd.addEventListener("dragover", stop, false);
|
|
|
|
|
2011-06-23 01:38:58 +00:00
|
|
|
|
|
|
|
dnd.addEventListener("dragleave", function() {
|
|
|
|
this.classList.remove('camli-dnd-over');
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
var drop = function(e) {
|
|
|
|
this.classList.remove('camli-dnd-over');
|
2011-06-07 17:23:11 +00:00
|
|
|
stop(e);
|
|
|
|
var dt = e.dataTransfer;
|
|
|
|
var files = dt.files;
|
|
|
|
document.getElementById("info").innerHTML = "";
|
|
|
|
handleFiles(files);
|
|
|
|
};
|
|
|
|
dnd.addEventListener("drop", drop, false);
|
|
|
|
}
|
|
|
|
|
2011-06-23 01:38:58 +00:00
|
|
|
|
|
|
|
// member: child permanode
|
|
|
|
function deleteMember(member, strikeEle, removeEle) {
|
|
|
|
return function(e) {
|
|
|
|
strikeEle.innerHTML = "<del>" + strikeEle.innerHTML + "</del>";
|
|
|
|
camliNewDelAttributeClaim(
|
|
|
|
getPermanodeParam(),
|
|
|
|
"camliMember",
|
|
|
|
member,
|
|
|
|
{
|
|
|
|
success: function() {
|
|
|
|
removeEle.parentNode.removeChild(removeEle);
|
|
|
|
},
|
|
|
|
fail: function(msg) {
|
|
|
|
alert(msg);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2011-06-12 17:01:56 +00:00
|
|
|
// pn: child permanode
|
2011-06-23 01:38:58 +00:00
|
|
|
// des: describe response of root permanode
|
|
|
|
function addMember(pn, des) {
|
2011-06-11 07:53:13 +00:00
|
|
|
var membersDiv = document.getElementById("members");
|
|
|
|
var ul;
|
|
|
|
if (membersDiv.innerHTML == "") {
|
|
|
|
membersDiv.appendChild(document.createTextNode("Members:"));
|
|
|
|
ul = document.createElement("ul");
|
|
|
|
membersDiv.appendChild(ul);
|
|
|
|
} else {
|
|
|
|
ul = membersDiv.firstChild.nextSibling;
|
|
|
|
}
|
|
|
|
var li = document.createElement("li");
|
|
|
|
var a = document.createElement("a");
|
|
|
|
a.href = "./?p=" + pn;
|
2013-02-08 17:27:23 +00:00
|
|
|
Camli.setTextContent(a, camliBlobTitle(pn, des.meta));
|
2011-06-23 01:38:58 +00:00
|
|
|
|
|
|
|
var del = document.createElement("span");
|
|
|
|
del.className = 'camli-del';
|
2013-01-20 21:14:18 +00:00
|
|
|
Camli.setTextContent(del, "x");
|
2011-06-23 01:38:58 +00:00
|
|
|
del.addEventListener("click", deleteMember(pn, a, li));
|
|
|
|
|
|
|
|
li.appendChild(a);
|
|
|
|
li.appendChild(del);
|
2011-06-11 07:53:13 +00:00
|
|
|
ul.appendChild(li);
|
|
|
|
}
|
|
|
|
|
2011-06-23 01:38:58 +00:00
|
|
|
function buildPermanodeUi() {
|
|
|
|
camliDescribeBlob(getPermanodeParam(), {
|
2012-11-09 21:29:41 +00:00
|
|
|
thumbnails: 200, // requested size
|
2011-06-23 01:38:58 +00:00
|
|
|
success: onBlobDescribed,
|
|
|
|
failure: function(msg) {
|
|
|
|
alert("failed to get blob description: " + msg);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-06-12 16:43:42 +00:00
|
|
|
function onBlobDescribed(jres) {
|
|
|
|
var permanode = getPermanodeParam();
|
2013-02-08 17:27:23 +00:00
|
|
|
if (!jres.meta[permanode]) {
|
2011-06-12 16:43:42 +00:00
|
|
|
alert("didn't get blob " + permanode);
|
|
|
|
return;
|
|
|
|
}
|
2013-02-08 17:27:23 +00:00
|
|
|
var permanodeObject = jres.meta[permanode].permanode;
|
2011-06-12 16:43:42 +00:00
|
|
|
if (!permanodeObject) {
|
|
|
|
alert("blob " + permanode + " isn't a permanode");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-20 21:14:18 +00:00
|
|
|
Camli.setTextContent(document.getElementById("debugattrs"), JSON.stringify(permanodeObject.attr, null, 2));
|
2011-07-02 17:36:32 +00:00
|
|
|
|
|
|
|
var attr = function(name) {
|
|
|
|
if (!(name in permanodeObject.attr)) {
|
2013-01-20 23:32:15 +00:00
|
|
|
return null;
|
2011-07-02 17:36:32 +00:00
|
|
|
}
|
|
|
|
if (permanodeObject.attr[name].length == 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return permanodeObject.attr[name][0];
|
|
|
|
};
|
|
|
|
|
|
|
|
var disablePublish = false;
|
|
|
|
|
|
|
|
var selType = document.getElementById("type");
|
|
|
|
if (attr("camliRoot")) {
|
|
|
|
selType.value = "root";
|
|
|
|
disablePublish = true; // can't give a URL to a root with a claim
|
2011-07-03 22:24:58 +00:00
|
|
|
} else if (attr("camliContent")) {
|
|
|
|
selType.value = "file";
|
|
|
|
} else if (attr("camliMember")) {
|
|
|
|
selType.value = "collection";
|
2011-07-02 17:36:32 +00:00
|
|
|
}
|
2011-07-03 22:24:58 +00:00
|
|
|
onTypeChange();
|
2011-07-02 17:36:32 +00:00
|
|
|
|
|
|
|
document.getElementById("selectPublishRoot").disabled = disablePublish;
|
|
|
|
document.getElementById("publishSuffix").disabled = disablePublish;
|
|
|
|
document.getElementById("btnSavePublish").disabled = disablePublish;
|
|
|
|
|
2011-06-12 16:43:42 +00:00
|
|
|
var inputTitle = document.getElementById("inputTitle");
|
2011-07-02 17:36:32 +00:00
|
|
|
inputTitle.value = attr("title") ? attr("title") : "";
|
2011-06-23 01:38:58 +00:00
|
|
|
inputTitle.disabled = false;
|
2011-06-12 16:43:42 +00:00
|
|
|
|
|
|
|
var spanTags = document.getElementById("spanTags");
|
|
|
|
while (spanTags.firstChild) {
|
|
|
|
spanTags.removeChild(spanTags.firstChild);
|
|
|
|
}
|
|
|
|
|
2011-06-23 01:38:58 +00:00
|
|
|
document.getElementById('members').innerHTML = '';
|
2011-06-12 16:43:42 +00:00
|
|
|
var members = permanodeObject.attr.camliMember;
|
|
|
|
if (members && members.length > 0) {
|
|
|
|
for (idx in members) {
|
|
|
|
var member = members[idx];
|
2011-06-23 01:38:58 +00:00
|
|
|
addMember(member, jres);
|
2011-06-12 16:43:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var camliContent = permanodeObject.attr.camliContent;
|
|
|
|
if (camliContent && camliContent.length > 0) {
|
|
|
|
camliContent = camliContent[camliContent.length-1];
|
|
|
|
var c = document.getElementById("content");
|
|
|
|
c.innerHTML = "";
|
2013-01-17 23:49:08 +00:00
|
|
|
var alink = document.createElement("a");
|
|
|
|
alink.href = "./?b=" + camliContent;
|
|
|
|
var img = document.createElement("img");
|
2013-02-08 17:27:23 +00:00
|
|
|
var br = jres.meta[permanode];
|
2013-01-17 23:49:08 +00:00
|
|
|
img.src = br.thumbnailSrc;
|
|
|
|
img.height = br.thumbnailHeight;
|
|
|
|
img.width = br.thumbnailWidth;
|
|
|
|
alink.appendChild(img);
|
|
|
|
c.appendChild(alink);
|
|
|
|
var title = document.createElement("p");
|
2013-02-08 17:27:23 +00:00
|
|
|
Camli.setTextContent(title, camliBlobTitle(br.blobRef, jres.meta));
|
2013-01-17 23:49:08 +00:00
|
|
|
title.className = 'camli-ui-thumbtitle';
|
|
|
|
c.appendChild(title);
|
2011-06-12 16:43:42 +00:00
|
|
|
}
|
|
|
|
|
2011-09-03 22:48:49 +00:00
|
|
|
var tags = permanodeObject.attr.tag;
|
2011-06-12 16:43:42 +00:00
|
|
|
for (idx in tags) {
|
|
|
|
var tag = tags[idx];
|
|
|
|
|
2011-06-23 01:38:58 +00:00
|
|
|
var tagSpan = document.createElement("span");
|
|
|
|
tagSpan.className = 'camli-tag-c';
|
|
|
|
var tagTextEl = document.createElement("span");
|
|
|
|
tagTextEl.className = 'camli-tag-text';
|
2013-01-20 21:14:18 +00:00
|
|
|
Camli.setTextContent(tagTextEl, tag);
|
2011-06-23 01:38:58 +00:00
|
|
|
tagSpan.appendChild(tagTextEl);
|
|
|
|
|
|
|
|
var tagDel = document.createElement("span");
|
|
|
|
tagDel.className = 'camli-del';
|
2013-01-20 21:14:18 +00:00
|
|
|
Camli.setTextContent(tagDel, "x");
|
2011-06-23 01:38:58 +00:00
|
|
|
tagDel.addEventListener("click", deleteTagFunc(tag, tagTextEl, tagSpan));
|
|
|
|
|
|
|
|
tagSpan.appendChild(tagDel);
|
2011-06-12 16:43:42 +00:00
|
|
|
spanTags.appendChild(tagSpan);
|
|
|
|
}
|
|
|
|
|
2011-06-17 03:25:55 +00:00
|
|
|
var selectAccess = document.getElementById("selectAccess");
|
|
|
|
var access = permanodeObject.attr.camliAccess;
|
|
|
|
selectAccess.value = (access && access.length) ? access[0] : "private";
|
2011-06-23 01:38:58 +00:00
|
|
|
selectAccess.disabled = false;
|
2011-06-17 03:25:55 +00:00
|
|
|
|
|
|
|
var btnSaveTitle = document.getElementById("btnSaveTitle");
|
2011-06-23 01:38:58 +00:00
|
|
|
btnSaveTitle.disabled = false;
|
2011-06-17 03:25:55 +00:00
|
|
|
|
|
|
|
var btnSaveAccess = document.getElementById("btnSaveAccess");
|
2011-06-23 01:38:58 +00:00
|
|
|
btnSaveAccess.disabled = false;
|
2011-06-12 16:43:42 +00:00
|
|
|
}
|
|
|
|
|
2011-06-24 17:34:10 +00:00
|
|
|
function setupRootsDropdown() {
|
|
|
|
var selRoots = document.getElementById("selectPublishRoot");
|
|
|
|
if (!Camli.config.publishRoots) {
|
|
|
|
console.log("no publish roots");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (var rootName in Camli.config.publishRoots) {
|
|
|
|
var opt = document.createElement("option");
|
|
|
|
opt.setAttribute("value", rootName);
|
|
|
|
opt.appendChild(document.createTextNode(Camli.config.publishRoots[rootName].prefix[0]));
|
|
|
|
selRoots.appendChild(opt);
|
|
|
|
}
|
|
|
|
document.getElementById("btnSavePublish").addEventListener("click", onBtnSavePublish);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onBtnSavePublish(e) {
|
|
|
|
var selRoots = document.getElementById("selectPublishRoot");
|
|
|
|
var suffix = document.getElementById("publishSuffix");
|
2011-06-17 04:18:04 +00:00
|
|
|
|
2011-06-24 17:34:10 +00:00
|
|
|
var ourPermanode = getPermanodeParam();
|
|
|
|
if (!ourPermanode) {
|
|
|
|
return;
|
2011-06-17 04:18:04 +00:00
|
|
|
}
|
|
|
|
|
2011-06-24 17:34:10 +00:00
|
|
|
var publishRoot = selRoots.value;
|
|
|
|
if (!publishRoot) {
|
|
|
|
alert("no publish root selected");
|
|
|
|
return;
|
2013-01-20 23:32:15 +00:00
|
|
|
}
|
2011-06-24 17:34:10 +00:00
|
|
|
var pathSuffix = suffix.value;
|
|
|
|
if (!pathSuffix) {
|
|
|
|
alert("no path suffix specified");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
selRoots.disabled = true;
|
|
|
|
suffix.disabled = true;
|
|
|
|
|
|
|
|
var enabled = function() {
|
|
|
|
selRoots.disabled = false;
|
|
|
|
suffix.disabled = false;
|
|
|
|
};
|
2011-06-17 04:18:04 +00:00
|
|
|
|
2011-06-24 17:34:10 +00:00
|
|
|
// Step 1: resolve selRoots.value -> blobref of the root's permanode.
|
|
|
|
// Step 2: set attribute on the root's permanode, or a sub-permanode
|
|
|
|
// if multiple path components in suffix:
|
|
|
|
// "camliPath:<suffix>" => permanode-of-ourselves
|
|
|
|
|
2013-01-09 03:40:27 +00:00
|
|
|
var sigconf = Camli.config.signing;
|
|
|
|
var savcb = {};
|
|
|
|
savcb.success = function(pnres) {
|
|
|
|
if (!pnres.permanode) {
|
|
|
|
alert("failed to publish root's permanode");
|
|
|
|
enabled();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var attrcb = {};
|
|
|
|
attrcb.success = function() {
|
|
|
|
console.log("success.");
|
|
|
|
enabled();
|
|
|
|
selRoots.value = "";
|
|
|
|
suffix.value = "";
|
|
|
|
buildPathsList();
|
2011-06-24 17:34:10 +00:00
|
|
|
};
|
2013-01-09 03:40:27 +00:00
|
|
|
attrcb.fail = function() {
|
|
|
|
alert("failed to set attribute");
|
2011-06-24 17:34:10 +00:00
|
|
|
enabled();
|
|
|
|
};
|
2013-01-09 03:40:27 +00:00
|
|
|
camliNewSetAttributeClaim(pnres.permanode, "camliPath:" + pathSuffix, ourPermanode, attrcb);
|
2011-06-24 17:34:10 +00:00
|
|
|
};
|
2013-01-09 03:40:27 +00:00
|
|
|
savcb.fail = function() {
|
|
|
|
alert("failed to find publish root's permanode");
|
2011-06-24 17:34:10 +00:00
|
|
|
enabled();
|
2013-01-09 03:40:27 +00:00
|
|
|
};
|
|
|
|
camliPermanodeOfSignerAttrValue(sigconf.publicKeyBlobRef, "camliRoot", publishRoot, savcb);
|
2011-06-17 04:18:04 +00:00
|
|
|
}
|
|
|
|
|
2011-06-26 00:50:38 +00:00
|
|
|
function buildPathsList() {
|
|
|
|
var ourPermanode = getPermanodeParam();
|
|
|
|
if (!ourPermanode) {
|
|
|
|
return;
|
|
|
|
}
|
2013-01-09 03:40:27 +00:00
|
|
|
var sigconf = Camli.config.signing;
|
|
|
|
|
|
|
|
var findpathcb = {};
|
|
|
|
findpathcb.success = function(jres) {
|
|
|
|
var div = document.getElementById("existingPaths");
|
|
|
|
|
|
|
|
// TODO: there can be multiple paths in this list, but the HTML
|
|
|
|
// UI only shows one. The UI should show all, and when adding a new one
|
|
|
|
// prompt users whether they want to add to or replace the existing one.
|
|
|
|
// For now we just update the UI to show one.
|
|
|
|
// alert(JSON.stringify(jres, null, 2));
|
|
|
|
if (jres.paths && jres.paths.length > 0) {
|
|
|
|
div.innerHTML = "Existing paths for this permanode:";
|
|
|
|
var ul = document.createElement("ul");
|
|
|
|
div.appendChild(ul);
|
|
|
|
for (var idx in jres.paths) {
|
|
|
|
var path = jres.paths[idx];
|
|
|
|
var li = document.createElement("li");
|
|
|
|
var span = document.createElement("span");
|
|
|
|
li.appendChild(span);
|
|
|
|
|
|
|
|
var blobLink = document.createElement("a");
|
|
|
|
blobLink.href = ".?p=" + path.baseRef;
|
2013-01-20 21:14:18 +00:00
|
|
|
Camli.setTextContent(blobLink, path.baseRef);
|
2013-01-09 03:40:27 +00:00
|
|
|
span.appendChild(blobLink);
|
|
|
|
|
|
|
|
span.appendChild(document.createTextNode(" - "));
|
|
|
|
|
|
|
|
var pathLink = document.createElement("a");
|
|
|
|
pathLink.href = "";
|
2013-01-20 21:14:18 +00:00
|
|
|
Camli.setTextContent(pathLink, path.suffix);
|
2013-01-09 03:40:27 +00:00
|
|
|
for (var key in Camli.config.publishRoots) {
|
|
|
|
var root = Camli.config.publishRoots[key];
|
|
|
|
if (root.currentPermanode == path.baseRef) {
|
|
|
|
// Prefix should include a trailing slash.
|
|
|
|
pathLink.href = root.prefix[0] + path.suffix;
|
|
|
|
// TODO: Check if we're the latest permanode
|
|
|
|
// for this path and display some "old" notice
|
|
|
|
// if not.
|
|
|
|
break;
|
2011-07-01 21:31:41 +00:00
|
|
|
}
|
2013-01-09 03:40:27 +00:00
|
|
|
}
|
|
|
|
span.appendChild(pathLink);
|
2011-07-01 19:18:26 +00:00
|
|
|
|
2013-01-09 03:40:27 +00:00
|
|
|
var del = document.createElement("span");
|
|
|
|
del.className = "camli-del";
|
2013-01-20 21:14:18 +00:00
|
|
|
Camli.setTextContent(del, "x");
|
2013-01-09 03:40:27 +00:00
|
|
|
del.addEventListener("click", deletePathFunc(path.baseRef, path.suffix, span));
|
|
|
|
span.appendChild(del);
|
2011-07-01 19:18:26 +00:00
|
|
|
|
2013-01-09 03:40:27 +00:00
|
|
|
ul.appendChild(li);
|
2011-06-26 00:50:38 +00:00
|
|
|
}
|
2013-01-09 03:40:27 +00:00
|
|
|
} else {
|
|
|
|
div.innerHTML = "";
|
|
|
|
}
|
2011-06-26 00:50:38 +00:00
|
|
|
};
|
2013-01-09 03:40:27 +00:00
|
|
|
camliPathsOfSignerTarget(sigconf.publicKeyBlobRef, ourPermanode, findpathcb);
|
2011-06-26 00:50:38 +00:00
|
|
|
}
|
|
|
|
|
2011-07-01 19:18:26 +00:00
|
|
|
function deletePathFunc(sourcePermanode, path, strikeEle) {
|
|
|
|
return function(e) {
|
|
|
|
strikeEle.innerHTML = "<del>" + strikeEle.innerHTML + "</del>";
|
|
|
|
camliNewDelAttributeClaim(
|
|
|
|
sourcePermanode,
|
|
|
|
"camliPath:" + path,
|
|
|
|
getPermanodeParam(),
|
|
|
|
{
|
|
|
|
success: function() {
|
|
|
|
buildPathsList();
|
|
|
|
},
|
|
|
|
fail: function(msg) {
|
|
|
|
alert(msg);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2011-07-04 11:39:04 +00:00
|
|
|
function btnGoToGallery(e) {
|
|
|
|
var permanode = getPermanodeParam();
|
|
|
|
if (permanode) {
|
2012-10-29 10:49:38 +00:00
|
|
|
window.open('./?g=' + permanode, 'Gallery')
|
|
|
|
}
|
2011-07-04 11:39:04 +00:00
|
|
|
}
|
|
|
|
|
2012-12-06 22:19:15 +00:00
|
|
|
function permanodePageOnLoad() {
|
2011-05-30 23:32:25 +00:00
|
|
|
var permanode = getPermanodeParam();
|
|
|
|
if (permanode) {
|
2011-06-12 16:43:42 +00:00
|
|
|
document.getElementById('permanode').innerHTML = "<a href='./?p=" + permanode + "'>" + permanode + "</a>";
|
2011-06-01 06:25:24 +00:00
|
|
|
document.getElementById('permanodeBlob').innerHTML = "<a href='./?b=" + permanode + "'>view blob</a>";
|
2011-05-30 23:32:25 +00:00
|
|
|
}
|
|
|
|
|
2011-06-01 06:25:24 +00:00
|
|
|
var formTitle = document.getElementById("formTitle");
|
|
|
|
formTitle.addEventListener("submit", handleFormTitleSubmit);
|
|
|
|
var formTags = document.getElementById("formTags");
|
|
|
|
formTags.addEventListener("submit", handleFormTagsSubmit);
|
2011-06-17 03:25:55 +00:00
|
|
|
var formAccess = document.getElementById("formAccess");
|
|
|
|
formAccess.addEventListener("submit", handleFormAccessSubmit);
|
|
|
|
|
2011-06-07 17:23:11 +00:00
|
|
|
var selectType = document.getElementById("type");
|
|
|
|
selectType.addEventListener("change", onTypeChange);
|
2011-07-04 11:39:04 +00:00
|
|
|
var btnGallery = document.getElementById("btnGallery");
|
|
|
|
btnGallery.addEventListener("click", btnGoToGallery);
|
2011-06-07 17:23:11 +00:00
|
|
|
|
2011-06-24 17:34:10 +00:00
|
|
|
setupRootsDropdown();
|
2011-06-07 17:23:11 +00:00
|
|
|
setupFilesHandlers();
|
|
|
|
|
2011-06-23 01:38:58 +00:00
|
|
|
buildPermanodeUi();
|
2011-06-26 00:50:38 +00:00
|
|
|
buildPathsList();
|
2011-06-12 16:43:42 +00:00
|
|
|
}
|
2011-06-03 21:16:00 +00:00
|
|
|
|
2011-06-12 16:43:42 +00:00
|
|
|
window.addEventListener("load", permanodePageOnLoad);
|