Cofem/templates/adminActions.html

121 lines
4.0 KiB
HTML
Raw Normal View History

2024-02-03 16:08:26 +01:00
<script>
function addActivationCodes() {
const count = document.getElementById("activationCodeCount").value;
const data = new URLSearchParams();
data.append("action", "add_activation_codes");
data.append("count", count);
2024-02-03 17:01:52 +01:00
doAccountAction(data, "Activation codes added Successfully!", "Activation codes addition failed.");
2024-02-03 16:08:26 +01:00
}
async function listUsers() {
const data = new URLSearchParams();
data.append("action", "list_users");
2024-02-03 17:01:52 +01:00
const result = await doAccountAction(data, "User list retrieved Successfully!", "User list retrieval failed.");
2024-02-03 16:08:26 +01:00
if (result && result.Status === "Success") {
displayUserList(result.Users);
}
}
function displayUserList(users) {
const tableContainer = document.getElementById("userListTable");
tableContainer.innerHTML = ""; // Clear previous content
const table = document.createElement("table");
table.border = "1";
// Create header row
const headerRow = table.insertRow(0);
for (const key in users[0]) {
const th = document.createElement("th");
th.appendChild(document.createTextNode(key));
headerRow.appendChild(th);
}
// Create data rows
for (const user of users) {
const dataRow = table.insertRow();
for (const key in user) {
const td = document.createElement("td");
td.appendChild(document.createTextNode(user[key]));
dataRow.appendChild(td);
}
}
tableContainer.appendChild(table);
}
function listActivationCodes() {
const data = new URLSearchParams();
data.append("action", "list_activation_codes");
2024-02-03 17:01:52 +01:00
doAccountAction(data, "Activation code list retrieved Successfully!", "Activation code list retrieval failed.");
2024-02-03 16:08:26 +01:00
}
function deleteUser() {
const userId = document.getElementById("userId").value;
const data = new URLSearchParams();
data.append("action", "delete_user");
data.append("user_id", userId);
2024-02-03 17:01:52 +01:00
doAccountAction(data, "User deleted Successfully!", "User deletion failed.");
2024-02-03 16:08:26 +01:00
}
function deleteActivationCode() {
const activationCode = document.getElementById("activationCode").value;
const data = new URLSearchParams();
data.append("action", "delete_activation_code");
data.append("activation_code", activationCode);
2024-02-03 17:01:52 +01:00
doAccountAction(data, "Activation code deleted Successfully!", "Activation code deletion failed.");
2024-02-03 16:08:26 +01:00
}
</script>
<div class="form-container" id="addActivationCodesForm">
<h1>Add Activation Codes</h1>
<form>
<label for="activationCodeCount">Activation Code Count:</label>
<input type="text" id="activationCodeCount" name="activationCodeCount" required>
<button type="button" onclick="addActivationCodes()">Add Activation Codes</button>
</form>
</div>
<div class="form-container" id="listUsersForm">
<h1>List Users</h1>
<form>
<button type="button" onclick="listUsers()">List Users</button>
</form>
</div>
<div class="form-container" id="listActivationCodesForm">
<h1>List Activation Codes</h1>
<form>
<button type="button" onclick="listActivationCodes()">List Activation Codes</button>
</form>
</div>
<div class="form-container" id="deleteUserForm">
<h1>Delete User</h1>
<form>
<label for="userId">User ID:</label>
<input type="text" id="userId" name="userId" required>
<button type="button" onclick="deleteUser()">Delete User</button>
</form>
</div>
<div class="form-container" id="deleteActivationCodeForm">
<h1>Delete Activation Code</h1>
<form>
<label for="activationCode">Activation Code:</label>
<input type="text" id="activationCode" name="activationCode" required>
<button type="button" onclick="deleteActivationCode()">Delete Activation Code</button>
</form>
2024-02-03 17:35:45 +01:00
</div>