hopglass/lib/simplenodelist.js

63 lines
1.6 KiB
JavaScript
Raw Normal View History

define(["moment"], function (moment) {
2015-03-25 19:45:21 +01:00
return function(config, field, router, title) {
var self = this
var el
2015-03-29 16:14:10 +02:00
self.render = function (d) {
el = document.createElement("div")
d.appendChild(el)
}
self.setData = function (list) {
2015-03-29 16:14:10 +02:00
if (list.length === 0)
return
var h2 = document.createElement("h2")
h2.textContent = title
el.appendChild(h2)
var table = document.createElement("table")
el.appendChild(table)
var tbody = document.createElement("tbody")
list.forEach( function (d) {
var time = moment(d[field]).fromNow()
var row = document.createElement("tr")
var td1 = document.createElement("td")
var a = document.createElement("a")
a.classList.add("hostname")
a.classList.add(d.flags.online ? "online" : "offline")
a.textContent = d.nodeinfo.hostname
a.href = "#"
2015-03-25 19:45:21 +01:00
a.onclick = router.node(d)
td1.appendChild(a)
if (has_location(d)) {
var span = document.createElement("span")
span.classList.add("icon")
span.classList.add("ion-location")
td1.appendChild(span)
}
if ("owner" in d.nodeinfo && config.showContact) {
var contact = d.nodeinfo.owner.contact
td1.appendChild(document.createTextNode(" " + contact + ""))
}
var td2 = document.createElement("td")
td2.textContent = time
row.appendChild(td1)
row.appendChild(td2)
tbody.appendChild(row)
})
table.appendChild(tbody)
el.appendChild(table)
}
return self
}
})