Files
@ b11cb99ccd57
Branch filter:
Location: libtransport.git/spectrum_manager/src/html/js/app.js - annotation
b11cb99ccd57
7.5 KiB
text/javascript
Web interface: Fix leaving the room with hash in the name
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | 0363e74dd628 0363e74dd628 0363e74dd628 0363e74dd628 0363e74dd628 0363e74dd628 0363e74dd628 0363e74dd628 0363e74dd628 0363e74dd628 0363e74dd628 0363e74dd628 0363e74dd628 0363e74dd628 b8926b4f0c3b af6c160261c2 5ecc7ccfd79e 5ecc7ccfd79e 5ecc7ccfd79e 5ecc7ccfd79e 5ecc7ccfd79e 5ecc7ccfd79e 5ecc7ccfd79e 5ecc7ccfd79e 5ecc7ccfd79e 5ecc7ccfd79e 5ecc7ccfd79e 5ecc7ccfd79e 5ecc7ccfd79e 5ecc7ccfd79e 5ecc7ccfd79e 5ecc7ccfd79e 5ecc7ccfd79e 5ecc7ccfd79e d0d08adf5a6e d0d08adf5a6e d0d08adf5a6e f6cb536eb021 f6cb536eb021 f6cb536eb021 5ecc7ccfd79e f6cb536eb021 af6c160261c2 f6cb536eb021 f6cb536eb021 d0d08adf5a6e d0d08adf5a6e d0d08adf5a6e d0d08adf5a6e f6cb536eb021 4e8042885f2c 4e8042885f2c 4e8042885f2c 0363e74dd628 4e8042885f2c 4e8042885f2c 4e8042885f2c d0d08adf5a6e f6cb536eb021 f6cb536eb021 f6cb536eb021 5ecc7ccfd79e f6cb536eb021 f6cb536eb021 f6cb536eb021 f6cb536eb021 f6cb536eb021 f6cb536eb021 5ecc7ccfd79e 5ecc7ccfd79e b8926b4f0c3b f6cb536eb021 0363e74dd628 0363e74dd628 0363e74dd628 0363e74dd628 0363e74dd628 7ac5cbe5e18c 0363e74dd628 0363e74dd628 0363e74dd628 0363e74dd628 0363e74dd628 b11cb99ccd57 0363e74dd628 0363e74dd628 0363e74dd628 0363e74dd628 0363e74dd628 0363e74dd628 0363e74dd628 0363e74dd628 0363e74dd628 7ac5cbe5e18c 0363e74dd628 0363e74dd628 0363e74dd628 0363e74dd628 0363e74dd628 0363e74dd628 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 4e8042885f2c 4e8042885f2c 4e8042885f2c 4e8042885f2c 4e8042885f2c 4e8042885f2c 4e8042885f2c 4e8042885f2c 4e8042885f2c 4e8042885f2c 4e8042885f2c 144ccb07e8e2 4e8042885f2c 4e8042885f2c 4e8042885f2c 4e8042885f2c 4e8042885f2c 4e8042885f2c 4e8042885f2c 4e8042885f2c 4e8042885f2c 4e8042885f2c 4e8042885f2c 4e8042885f2c 0363e74dd628 4e8042885f2c 4e8042885f2c 4e8042885f2c 4e8042885f2c 0363e74dd628 4e8042885f2c 4e8042885f2c 4e8042885f2c f6cb536eb021 f6cb536eb021 f6cb536eb021 91fae24a0978 91fae24a0978 91fae24a0978 91fae24a0978 91fae24a0978 91fae24a0978 91fae24a0978 91fae24a0978 91fae24a0978 91fae24a0978 91fae24a0978 91fae24a0978 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 91fae24a0978 91fae24a0978 f6cb536eb021 af6c160261c2 f6cb536eb021 f6cb536eb021 bff117e4ef23 bff117e4ef23 bff117e4ef23 bff117e4ef23 bff117e4ef23 bff117e4ef23 bff117e4ef23 bff117e4ef23 bff117e4ef23 bff117e4ef23 bff117e4ef23 bff117e4ef23 bff117e4ef23 bff117e4ef23 bff117e4ef23 bff117e4ef23 f6cb536eb021 f6cb536eb021 f6cb536eb021 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 2eccba069825 2eccba069825 2eccba069825 6fdc1635e434 6fdc1635e434 2eccba069825 2eccba069825 2eccba069825 2eccba069825 2eccba069825 2eccba069825 2eccba069825 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 6fdc1635e434 | function getQueryParams(qs) {
qs = qs.split('+').join(' ');
var params = {},
tokens,
re = /[?&]?([^=]+)=([^&]*)/g;
while (tokens = re.exec(qs)) {
params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]);
}
return params;
}
function show_instances() {
$.get($.cookie("base_location") + "api/v1/instances", function(data) {
$("#main_content").html("<h2>List of Spectrum 2 instances</h2><table id='main_result'><tr><th>Name<th>Status</th><th>Actions</th></tr>");
var admin = $.cookie("admin") == "1";
$.each(data.instances, function(i, instance) {
if (instance.running) {
if (admin) {
var command = instance.running ? "stop" : "start";
}
else {
var command = instance.registered ? "unregister" : "register";
if (instance.registered) {
instance.status += "<br/>Registered as " + instance.username;
}
}
}
else if (admin) {
var command = "start";
}
else {
var command = "";
}
var row = '<tr>'
row += '<td>' + instance.name + '</td>'
row += '<td>' + instance.status + '</td>'
if (command == 'register') {
row += '<td><a class="button_command" href="' + $.cookie("base_location") + 'instances/register.shtml?id=' + instance.id + '">' + command + '</a>' + '</td></tr>';
$("#main_result > tbody:last-child").append(row);
}
else if (command == "") {
row += '<td></td></tr>';
$("#main_result > tbody:last-child").append(row);
}
else {
row += '<td>';
if (command == 'unregister' && instance.frontend == "slack") {
row += '<a href="' + $.cookie("base_location") + 'instances/join_room.shtml?id=' + instance.id + '">Join room</a> | ';
row += '<a href="' + $.cookie("base_location") + 'instances/list_rooms.shtml?id=' + instance.id + '">List joined rooms</a> | ';
}
row += '<a class="button_command" href="' + $.cookie("base_location") + 'api/v1/instances/' + command + '/' + instance.id + '">' + command + '</a>';
row += '</td></tr>';
$("#main_result > tbody:last-child").append(row);
$(".button_command").click(function(e) {
e.preventDefault();
$(this).parent().empty().progressbar( {value: false} ).css('height', '1em');
var url = $(this).attr('href');
$.get(url, function(data) {
show_instances();
});
})
}
});
});
}
function show_list_rooms() {
var query = getQueryParams(document.location.search);
$.get($.cookie("base_location") + "api/v1/instances/list_rooms/" + query.id, function(data) {
$("#main_content").html("<h2>Joined rooms</h2><table id='main_result'><tr><th>" + data.frontend_room_label + "</th><th>" + data.legacy_room_label + "</th><th>" + data.legacy_server_label + "</th><th>" + data.name_label + "</th><th>Actions</th></tr>");
$.each(data.rooms, function(i, room) {
var row = '<tr>';
row += '<td>' + room.frontend_room + '</td>';
row += '<td>' + room.legacy_room + '</td>';
row += '<td>' + room.legacy_server + '</td>';
row += '<td>' + room.name + '</td>';
row += '<td><a class="button_command" href="' + $.cookie("base_location") + 'api/v1/instances/leave_room/' + query.id + '?frontend_room=' + encodeURIComponent(room.frontend_room) + '">Leave</a></td>';
row += '</tr>';
$("#main_result > tbody:last-child").append(row);
$(".button_command").click(function(e) {
e.preventDefault();
$(this).parent().empty().progressbar( {value: false} ).css('height', '1em');
var url = $(this).attr('href');
$.get(url, function(data) {
show_list_rooms();
});
})
});
});
}
function show_users() {
var admin = $.cookie("admin") == "1";
if (!admin) {
$("#main_content").html("<h2>List of Spectrum 2 users</h2><p>Only administrator can list the users.</p>");
return;
}
$.get($.cookie("base_location") + "api/v1/users", function(data) {
$("#main_content").html("<h2>List of Spectrum 2 users</h2><p>You can add new users <a href=\"register.shtml?back_to_list=1\">here</a>.</p><table id='main_result'><tr><th>Name<th>Actions</th></tr>");
$.each(data.users, function(i, user) {
var row = '<tr>'
row += '<td>' + user.username + '</td>'
row += '<td><a class="button_command" href="' + $.cookie("base_location") + 'api/v1/users/remove/' + user.username + '">remove</a></td></tr>';
$("#main_result > tbody:last-child").append(row);
$(".button_command").click(function(e) {
e.preventDefault();
$(this).parent().empty().progressbar( {value: false} ).css('height', '1em');
var url = $(this).attr('href');
$.get(url, function(data) {
show_users();
});
})
});
});
}
function fill_instances_join_room_form() {
var query = getQueryParams(document.location.search);
$("#instance").attr("value", query.id);
$(".button_command").click(function(e) {
e.preventDefault();
$(this).parent().empty().progressbar( {value: false} ).css('height', '1em');
var postdata ={
"name": $("#name").val(),
"legacy_room": $("#legacy_room").val(),
"legacy_server": $("#legacy_server").val(),
"frontend_room": $("#frontend_room").val()
};
$.post($.cookie("base_location") + "api/v1/instances/join_room/" + $("#instance").val(), postdata, function(data) {
window.location.replace("index.shtml");
});
})
$.get($.cookie("base_location") + "api/v1/instances/join_room_form/" + query.id, function(data) {
$("#name_desc").html(data.name_label + ":");
$("#legacy_room_desc").html(data.legacy_room_label + ":");
$("#legacy_server_desc").html(data.legacy_server_label + ":");
$("#frontend_room_desc").html(data.frontend_room_label + ":");
$("#name").attr("placeholder", data.name_label + ":");
$("#legacy_room").attr("placeholder", data.legacy_room_label + ":");
$("#legacy_server").attr("placeholder", data.legacy_server_label + ":");
$("#frontend_room").attr("placeholder", data.frontend_room_label + ":");
});
}
function fill_instances_register_form() {
var query = getQueryParams(document.location.search);
$("#instance").attr("value", query.id);
$(".button_command").click(function(e) {
e.preventDefault();
$(this).parent().empty().progressbar( {value: false} ).css('height', '1em');
var postdata ={
"jid": $("#jid").val(),
"uin": $("#uin").val(),
"password": $("#password").val()
};
$.post($.cookie("base_location") + "api/v1/instances/register/" + $("#instance").val(), postdata, function(data) {
if (data.oauth2_url) {
window.location.replace(data.oauth2_url);
}
else {
window.location.replace("index.shtml");
}
});
})
$.get($.cookie("base_location") + "api/v1/instances/register_form/" + query.id, function(data) {
$("#jid_desc").html(data.username_label + ":");
$("#jid").attr("placeholder", data.username_label);
if (data.legacy_username_label.length == 0) {
$('#uin_label').hide();
}
else {
$("#uin_desc").html(data.legacy_username_label + ":");
$("#uin").attr("placeholder", data.legacy_username_label);
}
if (data.password_label.length == 0) {
$('#password_label').hide();
}
else {
$("#password_desc").html(data.password_label + ":");
$("#password").attr("placeholder", data.password_label);
}
});
}
function fill_users_register_form() {
$(".button").click(function(e) {
e.preventDefault();
var postdata ={
"username": $("#username").val(),
"password": $("#password").val()
};
$.post("/api/v1/users/add", postdata, function(data) {
if (data.error) {
$('#error').text(data.message);
}
else {
var query = getQueryParams(document.location.search);
if (query.back_to_list == "1") {
window.location.replace("list.shtml");
}
else {
window.location.replace("../login/");
}
}
});
})
}
|