Files.Add("permanode.js","/*\nCopyright 2011 Google Inc.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\n// Gets the |p| query parameter, assuming that it looks like a blobref.\n\nfunction getPermanodeParam() {\n var blobRef = getQueryParam('p');\n return (blobRef && isPlausibleBlobRef(blobRef)) ? blobRef : null;\n}\n\nfunction handleFormTitleSubmit(e) {\n e.stopPropagation();\n e.preventDefault();\n\n var inputTitle = document.getElementById(\"inputTitle\");\n inputTitle.disabled = true;\n var btnSaveTitle = document.getElementById(\"btnSaveTitle\");\n btnSaveTitle.disabled = true;\n\n var startTime = new Date();\n\n camliNewSetAttributeClaim(\n getPermanodeParam(),\n \"title\",\n inputTitle.value,\n {\n success: function() {\n var elapsedMs = new Date().getTime() - startTime.getTime();\n setTimeout(function() {\n inputTitle.disabled = false;\n btnSaveTitle.disabled = false;\n buildPermanodeUi();\n }, Math.max(250 - elapsedMs, 0));\n },\n fail: function(msg) {\n alert(msg);\n inputTitle.disabled = false;\n btnSaveTitle.disabled = false;\n }\n });\n}\n\nfunction handleFormTagsSubmit(e) {\n e.stopPropagation();\n e.preventDefault();\n\n var input = document.getElementById(\"inputNewTag\");\n var btn = document.getElementById(\"btnAddTag\");\n\n if (input.value == \"\") {\n return;\n }\n\n input.disabled = true;\n btn.disabled = true;\n\n var startTime = new Date();\n\n var tags = input.value.split(/\\s*,\\s*/);\n var nRemain = tags.length;\n\n var oneDone = function() {\n nRemain--;\n if (nRemain == 0) {\n var elapsedMs = new Date().getTime() - startTime.getTime();\n setTimeout(function() {\n input.value = '';\n input.disabled = false;\n btn.disabled = false;\n buildPermanodeUi();\n }, Math.max(250 - elapsedMs, 0));\n }\n };\n for (idx in tags) {\n var tag = tags[idx];\n camliNewAddAttributeClaim(\n getPermanodeParam(),\n \"tag\",\n tag,\n {\n success: oneDone,\n fail: function(msg) {\n alert(msg);\n oneDone();\n }\n });\n }\n}\n\nfunction handleFormAccessSubmit(e) {\n e.stopPropagation();\n e.preventDefault();\n\n var selectAccess = document.getElementById(\"selectAccess\");\n selectAccess.disabled = true;\n var btnSaveAccess = document.getElementById(\"btnSaveAccess\");\n btnSaveAccess.disabled = true;\n\n var operation = camliNewDelAttributeClaim;\n var value = \"\";\n if (selectAccess.value != \"private\") {\n operation = camliNewSetAttributeClaim;\n value = selectAccess.value;\n }\n\n var startTime = new Date();\n\n operation(\n getPermanodeParam(),\n \"camliAccess\",\nvalue,\n{\nsuccess:function(){\nvarelapsedMs=newDate().getTime()-startTime.getTime();\nsetTimeout(function(){\nselectAccess.disabled=false;\nbtnSaveAccess.disabled=false;\n},Math.max(250-elapsedMs,0));\n},\nfail:function(ms