From 8e63324d9e723be4229079525f4f214486d82fd0 Mon Sep 17 00:00:00 2001 From: kinde Date: Thu, 21 Nov 2024 23:08:46 +0500 Subject: [PATCH 1/6] add players fetch and players table --- src/main/webapp/html/my.html | 58 ++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/main/webapp/html/my.html b/src/main/webapp/html/my.html index eb66ac55..f4eaadcb 100644 --- a/src/main/webapp/html/my.html +++ b/src/main/webapp/html/my.html @@ -6,6 +6,64 @@

RPG admin panel

+ + + + + + + + + + + + + +
#NameTitleRaceProfessionLevelBirthdayBanned
+ \ No newline at end of file From 254117d40fb36bdb892bbbc7197996b9de90d73f Mon Sep 17 00:00:00 2001 From: kinde Date: Mon, 25 Nov 2024 23:19:10 +0500 Subject: [PATCH 2/6] pagination and edit\delete buttons without functions --- src/main/webapp/html/my.html | 212 ++++++++++++++++++++++++----------- 1 file changed, 148 insertions(+), 64 deletions(-) diff --git a/src/main/webapp/html/my.html b/src/main/webapp/html/my.html index f4eaadcb..0c7d664c 100644 --- a/src/main/webapp/html/my.html +++ b/src/main/webapp/html/my.html @@ -1,69 +1,153 @@ - - - RPG - - - - -

RPG admin panel

- - - - - - - - - - - - - -
#NameTitleRaceProfessionLevelBirthdayBanned
- + + + + +

RPG admin panel

+
+ + +
+ + + + + + + + + + + + + + + + + +
#NameTitleRaceProfessionLevelBirthdayBannedEditDelete
+ + - - \ No newline at end of file + + + \ No newline at end of file From 83be2e46b18c4b4421ba03e763ad0ea2ee9ce64a Mon Sep 17 00:00:00 2001 From: kinde Date: Wed, 27 Nov 2024 22:17:02 +0500 Subject: [PATCH 3/6] delete player on button press --- src/main/webapp/html/my.html | 267 ++++++++++++++++++++--------------- 1 file changed, 153 insertions(+), 114 deletions(-) diff --git a/src/main/webapp/html/my.html b/src/main/webapp/html/my.html index 0c7d664c..61b0b0f1 100644 --- a/src/main/webapp/html/my.html +++ b/src/main/webapp/html/my.html @@ -1,95 +1,133 @@ - - - RPG - - - - - -

RPG admin panel

-
- - -
- - - - - - - - - - - - - - - - - -
#NameTitleRaceProfessionLevelBirthdayBannedEditDelete
- - - - \ No newline at end of file + } + + $(document).ready(function () { + loadPlayers(currentPage); + setCurrentPage(); + deletePlayer(); + }); + + + \ No newline at end of file From a5e7db0f059687361bc70b58aa752601f6fafd3d Mon Sep 17 00:00:00 2001 From: kinde Date: Fri, 29 Nov 2024 00:40:13 +0500 Subject: [PATCH 4/6] working edit and save button --- src/main/webapp/html/my.html | 136 +++++++++++++++++++++++++++-------- 1 file changed, 108 insertions(+), 28 deletions(-) diff --git a/src/main/webapp/html/my.html b/src/main/webapp/html/my.html index 61b0b0f1..3ad843d3 100644 --- a/src/main/webapp/html/my.html +++ b/src/main/webapp/html/my.html @@ -30,7 +30,6 @@ display: block; margin: 0 auto; padding: 0; - border: none; background: none; } @@ -38,9 +37,20 @@ display: block; margin: 0 auto; padding: 0; - border: none; background: none; } + + .save-button { + display: block; + margin: 0 auto; + padding: 0; + background: none; + } + .read-cell { + border: none; + background-color: transparent; + color: black; + } @@ -81,21 +91,55 @@

RPG admin panel

let playersPerPage = 10; let currentPage = 0; - function updatePlayer() { - $.post('https://example.com/api', { - key1: 'value1', - key2: 'value2' - }) - .done(function(response) { - console.log('Успех:', response); // Обработка успешного ответа - }) - .fail(function(xhr, status, error) { - console.log('Ошибка:', error); // Обработка ошибки - }); + function editPlayer() { + $('#players-table').on('click', '.edit-button', function (event) { + event.preventDefault(); + var row = $(this).closest('tr'); + + const inputs = row.find('input, select'); + inputs.prop('disabled', false); + inputs.addClass('editable-cell'); + + var currentCell = $(this).parent(); + var saveButton = $(this).siblings('.save-button'); + + $(this).hide(); + saveButton.show(); + }); } + function sendPlayerUpdate() { + $('#players-table').on('click', '.save-button', function (event) { + event.preventDefault(); + var row = $(this).closest('tr'); + const inputs = row.find('input, select'); + + const data = {}; + Array.from(inputs).forEach(input => { + data[input.name] = input.value; + }); + + var playerId = row.find('td:first').text(); + + $.ajax({ + url: `/rest/players/${playerId}`, + type: 'POST', + data: JSON.stringify(data), + contentType: 'application/json', + success: function(result) { + alert('Success!'); + loadPlayers(currentPage); + }, + error: function(xhr, statusText) { + console.log('Error:', xhr.responseJSON.message); + } + }); + }); +} + + function deletePlayer() { - $('#players-table').on('click', '.delete-button', function(event) { + $('#players-table').on('click', '.delete-button', function (event) { event.preventDefault(); var $row = $(this).closest('tr'); var playerId = $row.find('td:first').text(); // Получение содержимого первой ячейки строки @@ -103,11 +147,11 @@

RPG admin panel

$.ajax({ url: '/rest/players/' + playerId, // Замените на ваш URL type: 'DELETE', - success: function(response) { + success: function (response) { console.log('Player deleted successfully', response); loadPlayers(currentPage); }, - error: function(xhr, status, error) { + error: function (xhr, status, error) { console.error('Error:', error); } }); @@ -129,18 +173,44 @@

RPG admin panel

data.forEach(player => { playersTableBody.append(` - ${player.id} - ${player.name} - ${player.title} - ${player.race} - ${player.profession} - ${player.level} - ${formatTimestamp(player.birthday)} - ${player.banned} + ${player.id} + + + + + + + + + ${player.level} + ${formatTimestamp(player.birthday)} + - + +