// THIS FILE IS AUTO-GENERATED FROM search.js // DO NOT EDIT. package ui import "time" func init() { Files.Add("search.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\nvar CamliSearch = {};\n\nfunction getSearchParams() {\n\tCamliSearch.query = \"\";\n\tCamliSearch.type = \"\";\n\tCamliSearch.fuzzy = \"\";\n\tCamliSearch.query = getQueryParam('q');\n\tCamliSearch.type = getQueryParam('t');\n\tCamliSearch.fuzzy = getQueryParam('f');\n\tif (CamliSearch.type == null) {\n\t\tCamliSearch.type = \"\";\n\t}\n\tif (CamliSearch.fuzzy == null) {\n\t\tCamliSearch.fuzzy = \"\";\n\t}\n}\n\nfunction hideAllResThings() {\n\tCamliSearch.titleRes.style.visibility = 'hidden';\n\tCamliSearch.btnNewCollec.disabled = true;\n\tCamliSearch.btnNewCollec.style.visibility = 'hidden';\n\tCamliSearch.formAddToCollec.style.visibility = 'hidden';\n}\n\nfunction handleFormGetTagged(e) {\n\te.stopPropagation();\n\te.preventDefault();\n\n\tvar input = document.getElementById(\"inputTag\");\n\n\tif (input.value == \"\") {\n\t\treturn;\n\t}\n\n\tvar tags = input.value.split(/\\s*,\\s*/);\n\tdocument.location.href = \"search.html?q=\" + tags[0] + \"&t=tag\"\n}\n\nfunction handleFormGetTitled(e) {\n\te.stopPropagation();\n\te.preventDefault();\n\n\tvar input = document.getElementById(\"inputTitle\");\n\n\tif (input.value == \"\") {\n\t\treturn;\n\t}\n\n\tvar titles = input.value.split(/\\s*,\\s*/);\n\tdocument.location.href = \"search.html?q=\" + titles[0] + \"&t=title\"\n}\n\nfunction handleFormGetAnyAttr(e) {\n\te.stopPropagation();\n\te.preventDefault();\n\n\tvar input = document.getElementById(\"inputAnyAttr\");\n\n\tif (input.value == \"\") {\n\t\treturn;\n\t}\n\n\tvar any = input.value.split(/\\s*,\\s*/);\n\tdocument.location.href = \"search.html?q=\" + any[0]\n}\n\nfunction doSearch() {\n\tvar sigcb = {};\n\tsigcb.success = function(sigconf) {\n\t\tvar tagcb = {};\n\t\ttagcb.success = function(pres) {\n\t\t\tshowSearchResult(pres, CamliSearch.type);\n\t\t};\n\t\ttagcb.fail = function(msg) {\n\t\t\talert(msg);\n\t\t};\n// TODO(mpl): add other kinds of searches (by filename for ex).\n\t\tswitch(CamliSearch.type) {\n\t\tcase \"tag\":\n\t\t\tcamliGetPermanodesWithAttr(sigconf.publicKeyBlobRef, \"tag\", CamliSearch.query, CamliSearch.fuzzy, tagcb);\n\t\t\tbreak;\n\t\tcase \"title\":\n\t\t\tcamliGetPermanodesWithAttr(sigconf.publicKeyBlobRef, \"title\", CamliSearch.query, \"true\", tagcb);\n\t\t\tbreak;\n\t\tcase \"\":\n\t\t\tcamliGetPermanodesWithAttr(sigconf.publicKeyBlobRef, \"\", CamliSearch.query, \"true\", tagcb);\n\t\t\tbreak;\n\t\t}\n\t};\n\tsigcb.fail = function() {\n\t\talert(\"sig disco failed\");\n\t}\n\tcamliSigDiscovery(sigcb);\n}\n\nfunction showSearchResult(pres, type) {\n\tshowPermanodes(pres, type);\n\tCamliSearch.query = \"\";\n\tCamliSearch.type = \"\";\n}\n\nfunction showPermanodes(searchRes, type) {\n\tvar div = document.getElementById(\"divRes\");\n\twhile (div.hasChildNodes()) {\n\t\tdiv.removeChild(div.lastChild);\n\t}\n\tvar results = searchRes.withAttr;\n\tif (results.length > 0) {\n\t\tvar checkall = document.createElement(\"input\");\n\t\tcheckall.id = \"checkall\";\n\t\tcheckall.type = \"checkbox\";\n\t\tcheckall.name = \"checkall\";\n\t\tcheckall.checked = false;\n\t\tcheckall.onclick = Function(\"checkAll();\");\n\t\tdiv.appendChild(checkall);\n\t\tdiv.appendChild(document.createElement(\"br\"));\n\t}\n\tfor (var i = 0; i < results.length; i++) {\n\t\tvar result = results[i];\n\t\tvar alink = document.createElement(\"a\");\n\t\talink.href = \"./?p=\" + result.permanode;\n\t\talink.innerText = camliBlobTitle(result.permanode, searchRes);\n\t\tvar cbox = document.createElement('input');\n\t\tcbox.type = \"checkbox\";\n\t\tcbox.name = \"checkbox\";\n\t\tcbox.value = result.permanode;\n\t\tdiv.appendChild(cbox);\n\t\tdiv.appendChild(alink);\n\t\tdiv.appendChild(document.createElement('br'));\n\t}\n\tif (results.length > 0) {\n\t\tswitch(type) {\n\t\tcase \"tag\":\n\t\t\tCamliSearch.titleRes.innerHTML = \"Tagged with \\\"\";\n\t\t\tbreak;\n\t\tcase \"title\":\n\t\t\tCamliSearch.titleRes.innerHTML = \"Titled with \\\"\";\n\t\t\tbreak;\n\t\tcase \"\":\n\t\t\tCamliSearch.titleRes.innerHTML = \"General search for \\\"\";\n\t\t\tbreak;\n\t\t}\n\t\tCamliSearch.titleRes.innerHTML += CamliSearch.query + \"\\\"\";\n\t\tCamliSearch.titleRes.style.visibility = 'visible';\n\t\tCamliSearch.btnNewCollec.disabled = false;\n\t\tCamliSearch.btnNewCollec.style.visibility = 'visible';\n\t\tCamliSearch.formAddToCollec.style.visibility = 'visible';\n\t} else {\n\t\thideAllResThings();\n\t}\n}\n\nfunction getTicked() {\n\tvar checkboxes = document.getElementsByName(\"checkbox\");\n\tCamliSearch.tickedMemb = new Array();\n\tvar j = 0;\n\tfor (var i = 0; i < checkboxes.length; i++) {\n\t\tif (checkboxes[i].checked) {\n\t\t\tCamliSearch.tickedMemb[j] = checkboxes[i].value;\n\t\t\tj++;\n\t\t}\n\t}\n}\n\nfunction checkAll() {\n\tvar checkall = document.getElementById(\"checkall\");\n\tvar checkboxes = document.getElementsByName('checkbox');\n\tfor (var i = 0; i < checkboxes.length; i++) {\n\t\tcheckboxes[i].checked = checkall.checked;\n\t}\n}\n\nfunction handleCreateNewCollection(e) {\n\taddToCollection(true)\n}\n\nfunction handleAddToCollection(e) {\n\te.stopPropagation();\n\te.preventDefault();\n\taddToCollection(false)\n}\n\nfunction addToCollection(createNew) {\n\tvar cnpcb = {};\n\tcnpcb.success = function(parent) {\n\t\tvar nRemain = CamliSearch.tickedMemb.length;\n\t\tvar naaccb = {};\n\t\tnaaccb.fail = function() {\n\t\t\tCamliSearch.btnNewCollec.disabled = true;\n\t\t\tthrow(\"failed to add member to collection\");\n\t\t}\n\t\tnaaccb.success = function() {\n\t\t\tnRemain--;\n\t\t\tif (nRemain == 0) {\n\t\t\t\tCamliSearch.btnNewCollec.disabled = true;\n\t\t\t\twindow.location = \"./?p=\" + parent;\n\t\t\t}\n\t\t}\n\t\ttry {\n\t\t\tfor (var i = 0; i < CamliSearch.tickedMemb.length; i++) {\n\t\t\t\tcamliNewAddAttributeClaim(parent, \"camliMember\", CamliSearch.tickedMemb[i], naaccb);\n\t\t\t}\n\t\t} catch(x) {\n\t\t\talert(x)\n\t\t}\n\t};\n\tcnpcb.fail = function() {\n\t\talert(\"failed to create permanode\");\n\t};\n\tgetTicked();\n\tif (CamliSearch.tickedMemb.length > 0) {\n\t\tif (createNew) {\n\t\t\tcamliCreateNewPermanode(cnpcb);\n\t\t} else {\n\t\t\tvar pn = document.getElementById(\"inputCollec\").value;\n//TODO(mpl): allow a collection title (instead of a hash) as input\n\t\t\tif (!isPlausibleBlobRef(pn)) {\n\t\t\t\talert(\"Not a valid collection permanode hash\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tvar returnPn = function(opts) {\n\t\t\t\topts = saneOpts(opts);\n\t\t\t\topts.success(pn);\n\t\t\t}\n\t\t\treturnPn(cnpcb);\n\t\t}\n\t} else {\n\t\talert(\"No selected object\")\n\t}\n}\n\nfunction indexOnLoad(e) {\n\n\tvar formTags = document.getElementById(\"formTags\");\n\tformTags.addEventListener(\"submit\", handleFormGetTagged);\n\tvar formTitles = document.getElementById(\"formTitles\");\n\tformTitles.addEventListener(\"submit\", handleFormGetTitled);\n\tvar formAnyAttr = document.getElementById(\"formAnyAttr\");\n\tformAnyAttr.addEventListener(\"submit\", handleFormGetAnyAttr);\n\tCamliSearch.titleRes = document.getElementById(\"titleRes\");\n\tCamliSearch.btnNewCollec = document.getElementById(\"btnNewCollec\");\n\tCamliSearch.btnNewCollec.addEventListener(\"click\", handleCreateNewCollection);\n\tCamliSearch.formAddToCollec = document.getElementById(\"formAddToCollec\");\n\tCamliSearch.formAddToCollec.addEventListener(\"submit\", handleAddToCollection);\n\thideAllResThings();\n\tgetSearchParams();\n\tif (CamliSearch.query != \"\") {\n\t\tdoSearch();\n\t}\n}\n\nwindow.addEventListener(\"load\", indexOnLoad);\n", time.Unix(0, 1323040624000000000)); }