// Work out how many pages are left attached to this document
varform=this.closest('form');
varpagesCount=form.data('pages-count');
varrelationCount=form.data('relation-count');
// Display an appropriate message
varmessage='';
if(pagesCount>1||relationCount>0){
varpages='';
if(pagesCount>1){
pages="\nWarning: doc is attached to a total of "+pagesCount+" pages. ";
}
varreferences='';
varreferencesWarning='';
if(relationCount>0){
varpname='pages';
referencesWarning="\n\nBefore deleting: please update the content on the pages where this document is referenced, otherwise the links on those pages will break.";
if(relationCount===1){
pname='page';
referencesWarning="\n\nBefore deleting: please update the content on the page where this document is referenced, otherwise the links on that page will break.";
}
references="\nWarning: doc is referenced in the text of "+relationCount+" "+pname+".";
}
message="Permanently delete this document and remove it from all pages where it is referenced?\n"+pages+references+"\n\nDeleting it here will permanently delete it from this page and all other pages where it is referenced."+referencesWarning;
}else{
message="Permanently delete this document and remove it from this page?\n\nNotice: this document is only attached to this page, so deleting it won't affect any other pages.";
}
if(!confirm(message)){
e.preventDefault();
returnfalse;
}else{
// User says "okay", so go ahead and do the action