Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
56 lines (49 sloc) 1.95 KB
<html>
<head>
<script src='/_ah/channel/jsapi'></script>
</head>
<body>
<script type='text/javascript'>
var connected;
add_link = function() {
var link = encodeURIComponent(document.getElementById('link_input').value);
var namespace = encodeURIComponent(document.getElementById('name_input').value);
var comment = encodeURIComponent(document.getElementById('comment_input').value);
sendMessage('/links/add?link=' + link + '&name={{device_name}}&receiver=' + namespace)
}
markRead = function(link) {
sendMessage('/links/mark_read?links=' + encodeURIComponent(JSON.stringify([link])));
document.getElementById(link).style.display = 'none';
}
update_links = function(link) {
var link_list = document.getElementById('links');
link_list.innerHTML += "<li id=\""+link.id+"\"><a href=\""+link.url+"\" target=\"_blank\">"+link.url+"</a> from "+link.sender+" <a href=\"#\" onClick=\"markRead("+link.id+");\">[x]</a></li>\n";
}
sendMessage = function(path) {
var xhr = new XMLHttpRequest();
xhr.open('POST', path, true);
xhr.send();
}
var token = '{{ channel_id }}';
var channel = new goog.appengine.Channel(token);
var socket = channel.open();
socket.onopen = function() {
window.setTimeout(function() {sendMessage('/channels/connected/{{device_name}}')}, 100);
}
socket.onmessage = function(evt) {
console.log(evt.data);
var o = JSON.parse(evt.data);
if (o.links) {
for(link in o.links)
update_links(o.links[link]);
}
}
</script>
<h1>{{ device }}</h1>
URL: <input id='link_input' type='text'><br />
Target: <input id="name_input" type="text"><br />
Comment: <textarea id="comment_input"></textarea> <input type="button" onclick='add_link()' value="Add" />
<ul id='links'>
</ul>
</body>
</html>