From e4b7ac02a694932b5fb555398ad838ea057bcca8 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sat, 23 Feb 2019 14:27:58 +0100 Subject: [PATCH] fixed some errors --- shared/js/ui/modal/ModalBanList.ts | 18 ++++++++++--- shared/js/ui/modal/ModalPermissionEdit.ts | 4 +-- shared/js/ui/modal/ModalPlaylistEdit.ts | 4 +-- shared/js/ui/modal/ModalPlaylistList.ts | 33 +++++++++++++---------- shared/js/ui/modal/ModalQuery.ts | 25 ++++++++++------- 5 files changed, 53 insertions(+), 31 deletions(-) diff --git a/shared/js/ui/modal/ModalBanList.ts b/shared/js/ui/modal/ModalBanList.ts index b1169c37..f716b102 100644 --- a/shared/js/ui/modal/ModalBanList.ts +++ b/shared/js/ui/modal/ModalBanList.ts @@ -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; } diff --git a/shared/js/ui/modal/ModalPermissionEdit.ts b/shared/js/ui/modal/ModalPermissionEdit.ts index 90753546..a40880fc 100644 --- a/shared/js/ui/modal/ModalPermissionEdit.ts +++ b/shared/js/ui/modal/ModalPermissionEdit.ts @@ -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'); diff --git a/shared/js/ui/modal/ModalPlaylistEdit.ts b/shared/js/ui/modal/ModalPlaylistEdit.ts index 35699795..2d38192e 100644 --- a/shared/js/ui/modal/ModalPlaylistEdit.ts +++ b/shared/js/ui/modal/ModalPlaylistEdit.ts @@ -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 + ")"); diff --git a/shared/js/ui/modal/ModalPlaylistList.ts b/shared/js/ui/modal/ModalPlaylistList.ts index 9b92a837..d30a25ab 100644 --- a/shared/js/ui/modal/ModalPlaylistList.ts +++ b/shared/js/ui/modal/ModalPlaylistList.ts @@ -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.
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.
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
Message: ") + error).open(); diff --git a/shared/js/ui/modal/ModalQuery.ts b/shared/js/ui/modal/ModalQuery.ts index 8308d5ab..ff68bd1e 100644 --- a/shared/js/ui/modal/ModalQuery.ts +++ b/shared/js/ui/modal/ModalQuery.ts @@ -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
Message: ") + error).open();