update active status and archive - api calls
This commit is contained in:
parent
460a9a06cd
commit
b225349931
3 changed files with 98 additions and 21 deletions
|
|
@ -1,14 +1,65 @@
|
|||
const archiveButtons = document.getElementsByClassName('archive-button');
|
||||
const activityButtons = document.getElementsByClassName('change-activity-btn');
|
||||
|
||||
for(let i = 0; i < activityButtons.length; i++){
|
||||
activityButtons[i].addEventListener('change', e => {
|
||||
console.log(e.target.checked, e.target.id)
|
||||
})
|
||||
|
||||
|
||||
|
||||
function deactivateArchiveButtons(){
|
||||
for (let i = 0; i < archiveButtons.length; i++){
|
||||
archiveButtons[i].disabled=true;
|
||||
}
|
||||
}
|
||||
function activateArchiveButtons(){
|
||||
for (let i = 0; i < archiveButtons.length; i++){
|
||||
archiveButtons[i].disabled=false;
|
||||
}
|
||||
}
|
||||
function deactivateActiveStatusCheckboxes(){
|
||||
for (let i = 0; i < activityButtons.length; i++){
|
||||
activityButtons[i].disabled=true;
|
||||
}
|
||||
}
|
||||
function activateActiveStatusCheckboxes(){
|
||||
for (let i = 0; i < activityButtons.length; i++){
|
||||
activityButtons[i].disabled=false;
|
||||
}
|
||||
}
|
||||
|
||||
for(let i = 0; i < archiveButtons.length; i++){
|
||||
archiveButtons[i].addEventListener('click', e => {
|
||||
console.log(e.target.id)
|
||||
})
|
||||
async function updateActiveStatus(id, status) {
|
||||
deactivateActiveStatusCheckboxes()
|
||||
deactivateArchiveButtons()
|
||||
var result = await fetch(`/campaigns/update_active_status/${id}/${status}`, {method:'PUT'});
|
||||
var data = await result.json();
|
||||
if (status === true){
|
||||
status = 'True'
|
||||
} else {
|
||||
status = 'False'
|
||||
}
|
||||
document.getElementById(`${id}-active-status`).innerText = status;
|
||||
activateActiveStatusCheckboxes()
|
||||
activateArchiveButtons()
|
||||
|
||||
}
|
||||
|
||||
async function archiveCampaign(id){
|
||||
deactivateActiveStatusCheckboxes()
|
||||
deactivateArchiveButtons()
|
||||
var result = await fetch(`/campaigns/archive_campaign/${id}`, {method:'PUT'});
|
||||
var data = await result.json();
|
||||
document.getElementById(`${id}-row`).remove();
|
||||
activateActiveStatusCheckboxes()
|
||||
activateArchiveButtons()
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", (event) => {
|
||||
for(let i = 0; i < activityButtons.length; i++){
|
||||
activityButtons[i].addEventListener('change', e => {
|
||||
updateActiveStatus(parseInt(e.target.value), e.target.checked)
|
||||
})
|
||||
}
|
||||
for(let i = 0; i < archiveButtons.length; i++){
|
||||
archiveButtons[i].addEventListener('click', e => {
|
||||
archiveCampaign(parseInt(e.target.value))
|
||||
})
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue