-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See #22
- Loading branch information
Showing
10 changed files
with
420 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const ajax = require('axios') | ||
|
||
async function del(e) { | ||
let btn = e.target | ||
let res = btn.parentNode | ||
let to = btn.attributes['data-to'].value | ||
|
||
if(!window.confirm('Are you sure you\'d like to delete this?')) { | ||
btn.innerHTML = 'delete' | ||
return | ||
} | ||
|
||
await ajax({ | ||
url: to, | ||
method: 'delete', | ||
headers: { | ||
'X-CSRF-Token': window.csrf | ||
} | ||
}) | ||
|
||
if(btn.attributes['data-sure']) { | ||
window.location.href = '/you' | ||
} else { | ||
btn.innerHTML = 'undelete' | ||
} | ||
} | ||
|
||
async function undelete(e) { | ||
let btn = e.target | ||
let res = btn.parentNode | ||
let to = btn.attributes['data-to'].value | ||
|
||
await ajax({ | ||
url: to, | ||
method: 'post', | ||
headers: { | ||
'X-CSRF-Token': window.csrf | ||
} | ||
}) | ||
|
||
btn.innerHTML = 'delete' | ||
} | ||
|
||
module.exports = function() { | ||
let btns = document.querySelectorAll('.btn.admin-do') | ||
|
||
for(let i = 0; i < btns.length; i++) { | ||
let btn = btns[i] | ||
|
||
btn.addEventListener('click', function(e) { | ||
if(btn.innerText == 'delete') { | ||
btn.innerHTML = 'deleting...' | ||
del(e) | ||
} else { | ||
btn.innerHTML = 'undeleting...' | ||
undelete(e) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.