Jadowyne Ulve c18c6cec16 test
2025-01-11 12:51:52 -06:00

131 lines
5.5 KiB
HTML

<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" charset="utf-8" />
<title>Edit Role</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@materializecss/materialize@2.0.3-alpha/dist/css/materialize.min.css" />
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined" />
<script src="https://cdn.jsdelivr.net/npm/@materializecss/materialize@2.0.3-alpha/dist/js/materialize.min.js"></script>
</head>
<style>
.dropdown-disabled {
pointer-events: none;
}
.item :hover{
cursor: pointer;
background-color: whitesmoke;
}
.custom_row:hover{
background-color: rgb(230, 230, 230) !important;
cursor: pointer;
}
</style>
<body>
<div class="container">
<div class="section">
<div class="row" style="gap: 1em;">
<div class="col s12" style="padding-bottom: 10px;">
<a href='{{ proto['referrer'] }}' class="left btn green lighten-4 black-text btn-flat"><i class="material-icons">arrow_back</i></a>
<a href="/items" class="btn btn-flat right">Home</a>
<a href="/profile" class="btn btn-flat right">Profile</a>
</div>
<div class="s12 m6 input-field">
<input id="role_name" type="text" placeholder=" " maxlength="20">
<label for="role_name">Name</label>
</div>
<div class="input-field col s12">
<select id="role_site">
<option value="" disabled selected>Choose your option</option>
</select>
<label for="role_site">Site</label>
</div>
<div class="input-field col s12">
<textarea id="role_description" class="materialize-textarea" placeholder=" "></textarea>
<label for="role_description">Description</label>
</div>
<div class="col s12">
<h4>Permissions</h4>
</div>
<div class="col s12">
<h5>All</h5>
</div>
<div class="col s12 m6">
<p>
<label>
<input type="checkbox" />
<span>Edit</span>
</label>
</p>
<p>
<label>
<input type="checkbox" />
<span>Delete</span>
</label>
</p>
</div>
<div class="col s12 m6">
<p>
<label>
<input type="checkbox" />
<span>Create</span>
</label>
</p>
<p>
<label>
<input type="checkbox" />
<span>View</span>
</label>
</p>
</div>
<div class="col s12">
<button class="btn btn-flat green lighten-4 right" onclick="updateRole()">Update</button>
<button class="btn btn-flat red lighten-4 right" style="margin-right: 10px;" onclick="deleteRole()">Delete</button>
</div>
</div>
</div>
</div>
</body>
<script src="{{ url_for('static', filename='adminHandler.js') }}"></script>
<script>
let role = {{role|tojson}}
console.log(role)
document.addEventListener('DOMContentLoaded', async function() {
var elems = document.querySelectorAll('select');
var instances = M.FormSelect.init(elems, {})
await populateRoleForm()
});
async function populateRoleForm() {
document.getElementById("role_name").value = role[1];
document.getElementById("role_description").value = role[2];
const selectElement = document.getElementById("role_site");
selectElement.innerHTML = "";
var sites = await fetchSites()
for (let i = 0; i < sites.length; i++){
let newOption = document.createElement("option");
newOption.value = sites[i][0];
newOption.text = sites[i][1];
selectElement.appendChild(newOption);
};
selectElement.value = role[3];
M.FormSelect.init(selectElement);
}
async function deleteRole(){
const url = new URL('/deleteRole', window.location.origin);
await fetch(url, {
method: 'POST',
headers: {'Content-Type': 'application/json',},
body: JSON.stringify({role_id: role[0],}),
});
const adminurl = new URL(`/admin`, window.location.origin);
window.location.href = adminurl.toString();
}
</script>
</html>