hardlounge/client/js/socket-events/sessions_list.js

38 lines
804 B
JavaScript
Raw Normal View History

2017-08-15 09:44:29 +00:00
"use strict";
const $ = require("jquery");
const Auth = require("../auth");
2017-08-15 09:44:29 +00:00
const socket = require("../socket");
const templates = require("../../views");
socket.on("sessions:list", function(data) {
data.sort((a, b) => b.lastUse - a.lastUse);
let html = "";
data.forEach((connection) => {
if (connection.current) {
$("#session-current").html(templates.session(connection));
return;
}
html += templates.session(connection);
});
if (html.length === 0) {
html = "<p><em>You are not currently logged in to any other device.</em></p>";
}
$("#session-list").html(html);
});
$("#settings").on("click", ".remove-session", function() {
const token = $(this).data("token");
2017-08-15 09:44:29 +00:00
if (token) {
socket.emit("sign-out", token);
} else {
socket.emit("sign-out");
Auth.signout();
}
2017-08-15 09:44:29 +00:00
});