fixed some errors

canary
WolverinDEV 2019-02-23 14:27:58 +01:00
parent 9b52f0a858
commit e4b7ac02a6
5 changed files with 53 additions and 31 deletions

View File

@ -25,6 +25,7 @@ namespace Modals {
export interface BanListManager {
addbans : (ban: BanEntry[]) => void;
clear : (ban?: any) => void;
modal: Modal;
}
export function openBanList(client: TSClient) {
@ -84,8 +85,10 @@ namespace Modals {
});
});
update = () => {
client.serverConnection.commandHandler["notifybanlist"] = json => {
const single_handler: connection.SingleCommandHandler = {
command: "notifybanlist",
function: command => {
const json = command.arguments;
console.log(tr("Got banlist: %o"), json);
let bans: BanEntry[] = [];
@ -136,7 +139,15 @@ namespace Modals {
}
modal.addbans(bans);
};
return false;
}
};
client.serverConnection.command_handler_boss().register_single_handler(single_handler);
modal.modal.close_listener.push(() => {
client.serverConnection.command_handler_boss().remove_single_handler(single_handler);
});
update = () => {
//TODO test permission
modal.clear();
@ -208,6 +219,7 @@ namespace Modals {
modal.htmlTag.find(".entry-container .entries").children().detach();
update_function();
};
result.modal = modal;
return result;
}

View File

@ -745,7 +745,7 @@ namespace Modals {
const resolve_client = () => {
let client_uid = tag_select_uid.val() as string;
globalClient.serverConnection.helper.info_from_uid(client_uid).then(result => {
globalClient.serverConnection.command_helper.info_from_uid(client_uid).then(result => {
if(!result || result.length == 0) return Promise.reject("invalid data");
tag_select_uid.attr('pattern', null).removeClass('is-invalid');
@ -888,7 +888,7 @@ namespace Modals {
const resolve_client = () => {
let client_uid = tag_select_uid.val() as string;
globalClient.serverConnection.helper.info_from_uid(client_uid).then(result => {
globalClient.serverConnection.command_helper.info_from_uid(client_uid).then(result => {
if(!result || result.length == 0) return Promise.reject("invalid data");
tag_select_uid.attr('pattern', null).removeClass('is-invalid');

View File

@ -176,7 +176,7 @@ namespace Modals {
const update_songs = () => {
set_song_info(tr("loading song list"));
client.serverConnection.helper.request_playlist_songs(playlist.playlist_id).then(result => {
client.serverConnection.command_helper.request_playlist_songs(playlist.playlist_id).then(result => {
const entries_tag = song_tag.find(".song-list-entries");
const entry_template = $("#tmpl_playlist_edit-song_entry");
entries_tag.empty();
@ -297,7 +297,7 @@ namespace Modals {
function apply_properties(tag: JQuery, client: TSClient, playlist: Playlist, change_property: (key: string, value: string) => any, callback_current_song: (id: number) => any) {
const owns_playlist = playlist.playlist_owner_dbid == client.getClient().properties.client_database_id;
client.serverConnection.helper.request_playlist_info(playlist.playlist_id).then(info => {
client.serverConnection.command_helper.request_playlist_info(playlist.playlist_id).then(info => {
tag.find(".property-owner input")
.val(info.playlist_owner_name + " (" + info.playlist_owner_dbid + ")");

View File

@ -43,7 +43,7 @@ namespace Modals {
update_selected();
try {
available_playlists = await client.serverConnection.helper.request_playlist_list();
available_playlists = await client.serverConnection.command_helper.request_playlist_list();
} catch(error) {
info_tag.text("failed to query playlist list.");
//FIXME error handling?
@ -92,24 +92,29 @@ namespace Modals {
template.find(".footer .buttons .button-refresh").on('click', update_list);
template.find(".button-playlist-create").on('click', event => {
const notify_handler = json => {
client.serverConnection.commandHandler.unset_handler("notifyplaylistcreated", notify_handler);
update_list().then(() => {
spawnYesNo(tr("Playlist created successful"), tr("The playlist has been successfully created.<br>Should we open the editor?"), result => {
if(result) {
for(const playlist of available_playlists) {
if(playlist.playlist_id == json[0]["playlist_id"]) {
spawnPlaylistEdit(client, playlist).close_listener.push(update_list);
return;
const single_handler: connection.SingleCommandHandler = {
function: command => {
const json = command.arguments;
update_list().then(() => {
spawnYesNo(tr("Playlist created successful"), tr("The playlist has been successfully created.<br>Should we open the editor?"), result => {
if(result) {
for(const playlist of available_playlists) {
if(playlist.playlist_id == json[0]["playlist_id"]) {
spawnPlaylistEdit(client, playlist).close_listener.push(update_list);
return;
}
}
}
}
});
});
});
return true;
},
command: "notifyplaylistcreated"
};
client.serverConnection.commandHandler.set_handler("notifyplaylistcreated", notify_handler);
client.serverConnection.command_handler_boss().register_single_handler(single_handler);
client.serverConnection.send_command("playlistcreate").catch(error => {
client.serverConnection.commandHandler.unset_handler("notifyplaylistcreated", notify_handler);
client.serverConnection.command_handler_boss().remove_single_handler(single_handler);
if(error instanceof CommandResult)
error = error.extra_message || error.message;
createErrorModal(tr("Unable to create playlist"), tr("Failed to create playlist<br>Message: ") + error).open();

View File

@ -20,21 +20,26 @@ namespace Modals {
}
//client_login_password
globalClient.serverConnection.commandHandler["notifyquerycreated"] = json => {
json = json[0];
const single_handler: connection.SingleCommandHandler = {
function: command => {
const json = command.arguments[0];
spawnQueryCreated({
username: name,
password: json.client_login_password
}, true);
spawnQueryCreated({
username: name,
password: json.client_login_password
}, true);
if(callback_created)
callback_created(name, json.client_login_password);
if(callback_created)
callback_created(name, json.client_login_password);
return true;
}
};
globalClient.serverConnection.sendCommand("querycreate", {
globalClient.serverConnection.command_handler_boss().register_single_handler(single_handler);
globalClient.serverConnection.send_command("querycreate", {
client_login_name: name
}).catch(error => {
globalClient.serverConnection.command_handler_boss().remove_single_handler(single_handler);
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();