2018-12-18 20:00:29 +01:00
|
|
|
/// <reference path="../../utils/modal.ts" />
|
|
|
|
/// <reference path="../../proto.ts" />
|
|
|
|
/// <reference path="../../client.ts" />
|
|
|
|
|
|
|
|
namespace Modals {
|
2018-12-23 17:41:14 +01:00
|
|
|
export function spawnQueryCreate(callback_created?: (user, pass) => any) {
|
2018-12-18 20:00:29 +01:00
|
|
|
let modal;
|
|
|
|
modal = createModal({
|
|
|
|
header: tr("Create a server query login"),
|
|
|
|
body: () => {
|
|
|
|
let template = $("#tmpl_query_create").renderTag();
|
|
|
|
template = $.spawn("div").append(template);
|
|
|
|
|
|
|
|
template.find(".button-close").on('click', event => modal.close());
|
|
|
|
template.find(".button-create").on('click', event => {
|
|
|
|
const name = template.find(".input-name").val() as string;
|
|
|
|
if(name.length < 3 || name.length > 64) {
|
|
|
|
createErrorModal(tr("Invalid username"), tr("Please enter a valid name!")).open();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//client_login_password
|
2019-02-23 14:27:58 +01:00
|
|
|
const single_handler: connection.SingleCommandHandler = {
|
|
|
|
function: command => {
|
|
|
|
const json = command.arguments[0];
|
2018-12-18 20:00:29 +01:00
|
|
|
|
2019-02-23 14:27:58 +01:00
|
|
|
spawnQueryCreated({
|
|
|
|
username: name,
|
|
|
|
password: json.client_login_password
|
|
|
|
}, true);
|
2018-12-23 17:41:14 +01:00
|
|
|
|
2019-02-23 14:27:58 +01:00
|
|
|
if(callback_created)
|
|
|
|
callback_created(name, json.client_login_password);
|
|
|
|
return true;
|
|
|
|
}
|
2018-12-18 20:00:29 +01:00
|
|
|
};
|
2019-02-23 14:27:58 +01:00
|
|
|
globalClient.serverConnection.command_handler_boss().register_single_handler(single_handler);
|
|
|
|
globalClient.serverConnection.send_command("querycreate", {
|
2018-12-18 20:00:29 +01:00
|
|
|
client_login_name: name
|
2018-12-23 17:41:14 +01:00
|
|
|
}).catch(error => {
|
2019-02-23 14:27:58 +01:00
|
|
|
globalClient.serverConnection.command_handler_boss().remove_single_handler(single_handler);
|
|
|
|
|
2018-12-23 17:41:14 +01:00
|
|
|
if(error instanceof CommandResult)
|
|
|
|
error = error.extra_message || error.message;
|
|
|
|
createErrorModal(tr("Unable to create account"), tr("Failed to create account<br>Message: ") + error).open();
|
2018-12-18 20:00:29 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
modal.close();
|
|
|
|
//TODO create account
|
|
|
|
});
|
|
|
|
return template;
|
|
|
|
},
|
|
|
|
footer: undefined,
|
|
|
|
width: 750
|
|
|
|
});
|
|
|
|
modal.open();
|
|
|
|
}
|
|
|
|
|
|
|
|
export function spawnQueryCreated(credentials: {
|
|
|
|
username: string,
|
|
|
|
password: string
|
2019-02-17 16:08:10 +01:00
|
|
|
}, just_created: boolean) {
|
2018-12-18 20:00:29 +01:00
|
|
|
let modal;
|
|
|
|
modal = createModal({
|
2019-02-17 16:08:10 +01:00
|
|
|
header: just_created ? tr("Server query credentials") : tr("New server query credentials"),
|
2018-12-18 20:00:29 +01:00
|
|
|
body: () => {
|
|
|
|
let template = $("#tmpl_query_created").renderTag(credentials);
|
|
|
|
template = $.spawn("div").append(template);
|
|
|
|
|
|
|
|
template.find(".button-close").on('click', event => modal.close());
|
|
|
|
template.find(".query_name").text(credentials.username);
|
|
|
|
template.find(".query_password").text(credentials.password);
|
|
|
|
|
|
|
|
template.find(".btn_copy_name").on('click', () => {
|
|
|
|
template.find(".query_name").select();
|
|
|
|
document.execCommand("copy");
|
|
|
|
});
|
|
|
|
template.find(".btn_copy_password").on('click', () => {
|
|
|
|
template.find(".query_password").select();
|
|
|
|
document.execCommand("copy");
|
|
|
|
});
|
|
|
|
return template;
|
|
|
|
},
|
|
|
|
footer: undefined,
|
|
|
|
width: 750
|
|
|
|
});
|
|
|
|
modal.open();
|
|
|
|
}
|
|
|
|
}
|