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

60 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-05-18 20:08:54 +00:00
"use strict";
const $ = require("jquery");
const socket = require("../socket");
const templates = require("../../views");
2017-05-18 20:08:54 +00:00
const sidebar = $("#sidebar");
const utils = require("../utils");
2018-07-08 13:42:54 +00:00
const {vueApp} = require("../vue");
2017-05-18 20:08:54 +00:00
socket.on("network", function(data) {
2018-07-12 18:33:52 +00:00
const network = data.networks[0];
2017-05-18 20:08:54 +00:00
2018-07-12 19:06:17 +00:00
network.isJoinChannelShown = false;
network.isCollapsed = false;
2018-07-12 18:33:52 +00:00
for (const channel of network.channels) {
if (channel.type === "channel") {
channel.usersOutdated = true;
}
}
vueApp.networks.push(network);
2018-07-12 18:33:52 +00:00
vueApp.$nextTick(() => {
sidebar.find(".chan")
.last()
.trigger("click");
});
2017-05-18 20:08:54 +00:00
$("#connect")
.find(".btn")
2017-09-12 12:52:16 +00:00
.prop("disabled", false);
2017-05-18 20:08:54 +00:00
});
socket.on("network_changed", function(data) {
vueApp.networks.find((n) => n.uuid === data.network).serverOptions = data.serverOptions;
2017-05-18 20:08:54 +00:00
});
socket.on("network:status", function(data) {
const network = vueApp.networks.find((n) => n.uuid === data.network);
network.status.connected = data.connected;
network.status.secure = data.secure;
});
socket.on("network:info", function(data) {
$("#connect")
.html(templates.windows.connect(data))
.find("form").on("submit", function() {
const uuid = $(this).find("input[name=uuid]").val();
const newName = $(this).find("#connect\\:name").val();
sidebar.find(`.network[data-uuid="${uuid}"] .chan.lobby .name`)
.attr("title", newName)
.text(newName)
.click();
});
2018-05-10 18:37:10 +00:00
utils.togglePasswordField("#connect .reveal-password");
});