Skip to content

Instantly share code, notes, and snippets.

@iaindooley
Created April 12, 2019 08:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save iaindooley/b83a779982ece1f58a4768a9cce3862e to your computer and use it in GitHub Desktop.
Save iaindooley/b83a779982ece1f58a4768a9cce3862e to your computer and use it in GitHub Desktop.
Update existing checklists
function updateExistingChecklists(notification)
{
//WAS A NEW ITEM ADDED?
var new_item = new Notification(notification).addedChecklistItem();
//IF IT WAS ADDED TO A CARD NAMED "Checklist Templates"
if(new_item.checklist().card().name() == "Checklist Templates")
{
//LOOP THROUGH ALL CARDS ON THE BOARD
new_item.checklist().card().board().cards().each(function(card)
{
//COPY THE NEW CHECKLIST TO THE CARD BUT WITH THE WORD " NEW" ON THE END
new_item.checklist().card().copyChecklist(new_item.checklist().name()+" NEW",card);
//GET A LIST OF OLD ITEMS FROM THE PREVIOUS CHECKLIST
var old_items = card.checklist(new_item.checklist().name());
//GRAB THE NEWLY ADDED CHECKLIST
var new_checklist = card.checklist(new_item.checklist().name()+" NEW");
//FOR EACH ITEM THAT WAS PREVIOUSLY PART OF THIS CHECKLIST ...
old_items.each(function(item)
{
//IF IT HAD ALREADY BEEN COMPLETED ...
if(item.isComplete())
//MARK THE CORRESPONDING ITEM ON THE NEWLY ADDED CHECKLIST COMPLETE
new_checklist.item(item.name()).markComplete())
});
//REMOVE THE OLD CHECKLIST
card.removeChecklist(new_item.checklist().name());
//RENAME THE NEW CHECKLIST TO THE ORIGINAL CHECKLIST NAME
card.checklist(new_item.checklist().name()+" NEW").setName(new_item.checklist().name());
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment