2011-05-30 20:36:17 +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.
|
|
|
|
*/
|
|
|
|
|
2011-07-10 12:31:25 +00:00
|
|
|
// CamliHome namespace to contain the global vars
|
|
|
|
var CamliHome = {};
|
|
|
|
|
2011-05-30 20:36:17 +00:00
|
|
|
function btnCreateNewPermanode(e) {
|
|
|
|
camliCreateNewPermanode(
|
|
|
|
{
|
2011-06-04 23:35:48 +00:00
|
|
|
success: function(blobref) {
|
2011-05-30 20:36:17 +00:00
|
|
|
window.location = "./?p=" + blobref;
|
2011-06-04 23:35:48 +00:00
|
|
|
},
|
2011-05-30 20:36:17 +00:00
|
|
|
fail: function(msg) {
|
2011-06-04 23:35:48 +00:00
|
|
|
alert("create permanode failed: " + msg);
|
2011-05-30 20:36:17 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-08-06 13:26:40 +00:00
|
|
|
function handleFormSearch(e) {
|
2011-07-02 15:15:00 +00:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
|
2011-08-06 13:26:40 +00:00
|
|
|
var input = document.getElementById("inputSearch");
|
|
|
|
var btn = document.getElementById("btnSearch");
|
2011-07-02 15:15:00 +00:00
|
|
|
|
|
|
|
if (input.value == "") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-06 13:26:40 +00:00
|
|
|
var query = input.value.split(/\s*,\s*/);
|
2011-12-04 23:23:50 +00:00
|
|
|
window.location = "./search.html?q=" + query[0] + "&t=tag";
|
2011-07-06 20:09:54 +00:00
|
|
|
}
|
|
|
|
|
2011-06-04 23:35:48 +00:00
|
|
|
function indexOnLoad(e) {
|
2012-10-10 14:04:03 +00:00
|
|
|
var btnNew = document.getElementById("btnNew");
|
2011-05-30 20:36:17 +00:00
|
|
|
if (!btnNew) {
|
|
|
|
alert("missing btnNew");
|
|
|
|
}
|
|
|
|
btnNew.addEventListener("click", btnCreateNewPermanode);
|
2011-06-04 23:35:48 +00:00
|
|
|
camliGetRecentlyUpdatedPermanodes({ success: indexBuildRecentlyUpdatedPermanodes });
|
2012-10-10 14:04:03 +00:00
|
|
|
var formSearch = document.getElementById("formSearch");
|
|
|
|
if (!formSearch) {
|
|
|
|
alert("missing formSearch");
|
|
|
|
}
|
2011-08-06 13:26:40 +00:00
|
|
|
formSearch.addEventListener("submit", handleFormSearch);
|
2011-06-06 16:07:23 +00:00
|
|
|
|
2012-12-24 01:19:59 +00:00
|
|
|
if (Camli && Camli.config && Camli.config.uploadHelper) {
|
2011-06-06 16:07:23 +00:00
|
|
|
var uploadForm = document.getElementById("uploadform");
|
2012-12-24 01:19:59 +00:00
|
|
|
uploadForm.action = Camli.config.uploadHelper;
|
2011-06-06 16:07:23 +00:00
|
|
|
document.getElementById("fileinput").disabled = false;
|
|
|
|
document.getElementById("filesubmit").disabled = false;
|
|
|
|
}
|
2011-07-02 15:15:00 +00:00
|
|
|
}
|
2011-06-06 16:07:23 +00:00
|
|
|
|
2011-06-04 23:35:48 +00:00
|
|
|
function indexBuildRecentlyUpdatedPermanodes(searchRes) {
|
2012-10-29 10:49:38 +00:00
|
|
|
var ul = document.getElementById("recent");
|
|
|
|
ul.innerHTML = "";
|
2011-06-12 07:20:57 +00:00
|
|
|
for (var i = 0; i < searchRes.recent.length; i++) {
|
|
|
|
var result = searchRes.recent[i];
|
2012-10-29 10:49:38 +00:00
|
|
|
var li = document.createElement("li");
|
2011-06-04 23:35:48 +00:00
|
|
|
var alink = document.createElement("a");
|
|
|
|
alink.href = "./?p=" + result.blobref;
|
2013-01-20 21:14:18 +00:00
|
|
|
Camli.setTextContent(alink, camliBlobTitle(result.blobref, searchRes));
|
2012-10-29 10:49:38 +00:00
|
|
|
li.appendChild(alink);
|
|
|
|
ul.appendChild(li);
|
2011-06-04 23:35:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener("load", indexOnLoad);
|