2017-05-18 20:08:54 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const $ = require("jquery");
|
|
|
|
const socket = require("../socket");
|
|
|
|
|
|
|
|
socket.on("sync_sort", function(data) {
|
|
|
|
const type = data.type;
|
|
|
|
const order = data.order;
|
2018-04-26 09:06:01 +00:00
|
|
|
const container = $(".networks");
|
|
|
|
const network = container.find(`.network[data-uuid="${data.target}"]`);
|
2017-05-18 20:08:54 +00:00
|
|
|
|
|
|
|
if (type === "networks") {
|
|
|
|
$.each(order, function(index, value) {
|
2018-05-01 08:18:39 +00:00
|
|
|
const position = $(container.children(".network")[index]);
|
2017-05-18 20:08:54 +00:00
|
|
|
|
2018-07-19 10:46:30 +00:00
|
|
|
if (Number(position.attr("data-id")) === value) { // Network in correct place
|
2017-05-18 20:08:54 +00:00
|
|
|
return true; // No point in continuing
|
|
|
|
}
|
|
|
|
|
2018-04-26 09:06:01 +00:00
|
|
|
network.insertBefore(position);
|
2017-05-18 20:08:54 +00:00
|
|
|
});
|
|
|
|
} else if (type === "channels") {
|
|
|
|
$.each(order, function(index, value) {
|
|
|
|
if (index === 0) { // Shouldn't attempt to move lobby
|
|
|
|
return true; // same as `continue` -> skip to next item
|
|
|
|
}
|
|
|
|
|
2018-05-01 08:18:39 +00:00
|
|
|
const position = $(network.children(".chan")[index]); // Target channel at position
|
2017-05-18 20:08:54 +00:00
|
|
|
|
2018-07-19 10:46:30 +00:00
|
|
|
if (Number(position.attr("data-id")) === value) { // Channel in correct place
|
2017-05-18 20:08:54 +00:00
|
|
|
return true; // No point in continuing
|
|
|
|
}
|
|
|
|
|
|
|
|
const channel = network.find(".chan[data-id=" + value + "]"); // Channel at position
|
|
|
|
|
2018-04-26 09:06:01 +00:00
|
|
|
channel.insertBefore(position);
|
2017-05-18 20:08:54 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|