TeaWeb/shared/js/ui/modal/ModalQuery.ts

89 lines
3.8 KiB
TypeScript
Raw Normal View History

2019-04-04 21:47:52 +02:00
/// <reference path="../../ui/elements/modal.ts" />
/// <reference path="../../ConnectionHandler.ts" />
/// <reference path="../../proto.ts" />
namespace Modals {
2019-04-04 21:47:52 +02:00
export function spawnQueryCreate(connection: ConnectionHandler, callback_created?: (user, pass) => any) {
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];
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;
}
};
2019-04-04 21:47:52 +02:00
connection.serverConnection.command_handler_boss().register_single_handler(single_handler);
connection.serverConnection.send_command("querycreate", {
client_login_name: name
2018-12-23 17:41:14 +01:00
}).catch(error => {
2019-04-04 21:47:52 +02:00
connection.serverConnection.command_handler_boss().remove_single_handler(single_handler);
2019-02-23 14:27:58 +01:00
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();
});
modal.close();
//TODO create account
});
return template;
},
footer: undefined,
width: 750
});
modal.open();
}
export function spawnQueryCreated(credentials: {
username: string,
password: string
Implemented the Material Design and fixed some bugs (#33) * cleaned up some files * Fundamental style update * Redesigned some style * fixed hostbanner popup * Removed old identity stuff * fixed close listener * Fixed changelog date * fixed release chat icons * fixed url * Fixed hostbanner * Uploaded missing images * Improved update handling * Improved script files * Fixed loading error and icon error * fixed Yes/No modal * Fixed loader issues with MS Edge * fixed modal style bug * Fixed control bar overflow for small devices * Improved error handling on identity creation * Logging generate error to terminal * fixed possible php error * fixed some possible loading errors when other files have'nt been already loaded. * removed debug message * Changed emsrcypten flags * Improved codec error handling * removed webassembly as required dependency * Improved and fixed channel tree issues * Improved the sliders * Removed unneeded files * fixed loader versions cache * second slight performance improved (dont animate elements anymore if they are not shown) * Fixed query visibility setting * not showing useless client infos for query clients * Added an auto reconnect system * Added a canceled message and increased reconnect interval * removed implemented todo * fixed repetitive channel names * Reworked the channel tree selected lines * Fixed channel tree names * Fixed name alignment * fixed the native client * added min width to the server select groups to avoid a disappearing effect on shrink * fixed bugged downloaded icons
2019-02-17 16:08:10 +01:00
}, just_created: boolean) {
let modal;
modal = createModal({
Implemented the Material Design and fixed some bugs (#33) * cleaned up some files * Fundamental style update * Redesigned some style * fixed hostbanner popup * Removed old identity stuff * fixed close listener * Fixed changelog date * fixed release chat icons * fixed url * Fixed hostbanner * Uploaded missing images * Improved update handling * Improved script files * Fixed loading error and icon error * fixed Yes/No modal * Fixed loader issues with MS Edge * fixed modal style bug * Fixed control bar overflow for small devices * Improved error handling on identity creation * Logging generate error to terminal * fixed possible php error * fixed some possible loading errors when other files have'nt been already loaded. * removed debug message * Changed emsrcypten flags * Improved codec error handling * removed webassembly as required dependency * Improved and fixed channel tree issues * Improved the sliders * Removed unneeded files * fixed loader versions cache * second slight performance improved (dont animate elements anymore if they are not shown) * Fixed query visibility setting * not showing useless client infos for query clients * Added an auto reconnect system * Added a canceled message and increased reconnect interval * removed implemented todo * fixed repetitive channel names * Reworked the channel tree selected lines * Fixed channel tree names * Fixed name alignment * fixed the native client * added min width to the server select groups to avoid a disappearing effect on shrink * fixed bugged downloaded icons
2019-02-17 16:08:10 +01:00
header: just_created ? tr("Server query credentials") : tr("New server query credentials"),
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();
}
}