Finalize rolerules with delete button

master
Cristiano Pires 2 years ago
parent a449b65c73
commit ac8cff2202

@ -154,6 +154,13 @@ exports.getRules = async (req,res)=>
.catch(()=>{return null})
return res.json(payload);
}
exports.deleteRule = async (req, res)=>
{
var deleted = await roleRulesM.findByIdAndDelete(req.headers.ruleid)
.then(()=>{return {success:'Done'}})
.catch(()=>{return {error:'Failed to delete'}});
res.json(deleted);
}
exports.updateRule = (bot)=>
{
return async (req, res)=>

@ -120,6 +120,11 @@ p
top:1vh;
right:1vh;
}
#Feeds
{
cursor:pointer;
}
#Guilds
{
/* background-color: ivory; */
@ -452,6 +457,17 @@ input
transform:translateX(-50%);
color:ivory;
cursor:pointer;
font-weight: bold;
font-family: 'lato';
}
#change
{
left:70%;
}
#delete
{
left:30%;
color: #410303a9;
}
#emojiImg
{

@ -183,7 +183,32 @@ async function handleToggleRules(element)
`
rulesElement.classList.remove('hidden')
}
function handleToggleFeeds(element)
{
}
function deleteRule(element)
{
var ruleID = document.getElementById('roleRule').classList[1];
fetch(`${window.location.origin}/api/deleteRule`,
{
method: "POST",
mode: "cors",
headers: {ruleID},
})
.then(result => result.json())
.then(res =>
{
console.log(res);
if(res.success)
{
element.parentNode.classList.add('hidden')
document.getElementById('popup').classList.remove('hidden');
}
else alert(res.error);
})
.catch(console.error);
}
function addRule(element)
{

@ -11,6 +11,7 @@ module.exports = (io, bot)=>
router.route('/api/getRules').get(api.getRules);
router.route('/api/getMessage').get(api.getMessage(bot));
router.route('/api/updateRule').post(api.updateRule(bot));
router.route('/api/deleteRule').post(api.deleteRule);
router.route('/dashboard').get(dash.get(io))
.post(dash.post(io));
router.route('/getMessage').get(api.getMessage(bot))

@ -33,6 +33,7 @@
<span class="material-symbols-outlined" id="strikes">check_box_outline_blank </span>
</p>
<p id="RoleRules" onclick="handleToggleRules(this)">Role rules</p>
<p id="Feeds" onclick="handleToggleFeeds(this)">Feeds</p>
<div id="rules" class="rules hidden">
<i onclick="handleClose(this)" class="close material-symbols-outlined" id="close_bt">
cancel
@ -53,6 +54,7 @@
<input id ="roleID" class='role roleID'></input>
<input id = "emojiID" class ="emoji emojiID"></input>
<button id="change" class="bt" onclick='updateRule(this)'>Change</button>
<button id="delete" class="bt" onclick='deleteRule(this)'>Delete</button>
</div>

Loading…
Cancel
Save