Skip to content

Instantly share code, notes, and snippets.

@leecannon
Last active June 17, 2023 10:01
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save leecannon/1734e3cb7b4d70c25f6c1c85fbe54665 to your computer and use it in GitHub Desktop.
Save leecannon/1734e3cb7b4d70c25f6c1c85fbe54665 to your computer and use it in GitHub Desktop.
Confluence user macro to un-tick all tasks on the page - No Macro Body
## @noparams
<script type="text/javascript">
function untick() {
var base_url = window.location.protocol + "//" + window.location.host;
var tasklist_id = document.getElementsByClassName("inline-task-list")[0].dataset.inlineTasksContentId;
var boxes = document.getElementsByClassName("checked");
var number_of_boxes = boxes.length;
if (number_of_boxes == 0) return;
var completed_boxes = 0;
document.getElementById("btnUntick").innerHTML = "Please Wait...";
for (i = 0; i < number_of_boxes; i++) {
var task_id = boxes[i].dataset.inlineTaskId;
var targeturl = base_url + "/rest/inlinetasks/1/task/" + tasklist_id + "/" + task_id + "/";
jQuery.ajax({type: "POST",
url: targeturl,
data: JSON.stringify({status: "UNCHECKED", trigger: "VIEW_PAGE"}),
dataType: "json",
contentType: "application/json",
timeout: 30000,
success: function() {
completed_boxes = completed_boxes + 1;
if (completed_boxes == number_of_boxes) {
location.reload();
}
},
error: function() {
completed_boxes = completed_boxes + 1;
if (completed_boxes == number_of_boxes) {
location.reload();
}
}
});
}
}
</script>
<button id="btnUntick" type="button" class="submit aui-button aui-button-primary" onclick="untick()">Un-tick all boxes</button>
@tosts
Copy link

tosts commented Jan 18, 2019

The url encoded version of the requests does no longer seem to work.

For me it works again, if I change the post-ing lines to

        xhttp.open("POST", url, true);
        xhttp.setRequestHeader("Content-type", "application/json");
        xhttp.send('{"trigger": "VIEW_PAGE", "status": "UNCHECKED"}');

@cubistico
Copy link

The script seems to hang after the "Please Wait..." message turns on if no checkbox was ticked and there's nothing to untick. This can be confusing for the user.

To avoid this, I've inserted the following lines before the for loop:

    if (number_of_boxes == 0) {
        location.reload();
    } 

@leecannon
Copy link
Author

I've update the gist with the latest version of the macro that i'm using.

@khallingstad
Copy link

Beautiful script! Thank you very much. Working nicely on On-prem Confluence v. 7.2.1. To bad Confluence could not add this feature as default.

@leecannon
Copy link
Author

Updated script to handle failed AJAX

@leecannon
Copy link
Author

Also made a gist to tick all checkboxes on the page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment