ENHANCEMENT: warning when deleting a document that is referenced on other pages

This commit is contained in:
Julian Seidenberg 2012-08-21 17:57:06 +12:00
parent ea9a0639e4
commit bd75a41f9b
4 changed files with 29 additions and 5 deletions

View File

@ -47,7 +47,7 @@ class DMSGridFieldDeleteAction extends GridFieldDeleteAction implements GridFiel
//set a class telling JS what kind of warning to display when clicking the delete button
if ($numberOfRelations > 1) $field->addExtraClass('dms-delete-link-only');
else $field->addExtraClasS('dms-delete-last-warning');
else $field->addExtraClass('dms-delete-last-warning');
//set a class to show if the document is hidden
if ($record->isHidden()) {

View File

@ -11,10 +11,13 @@ class DMSGridFieldDetailForm_ItemRequest extends GridFieldDetailForm_ItemRequest
//add a data attribute specifying how many pages this document is referenced on
if ($record = $this->record) {
$numberOfRelations = $record->Pages()->Count();
$numberOfPageRelations = $record->Pages()->Count();
$relations = new ShortCodeRelationFinder();
$numberOfInlineRelations = $relations->findPageCount($record->ID);
//add the number of pages attached to this field as a data-attribute
$form->setAttribute('data-pages-count', $numberOfRelations);
$form->setAttribute('data-pages-count', $numberOfPageRelations);
$form->setAttribute('data-relation-count', $numberOfInlineRelations);
}
return $form;
}

View File

@ -30,6 +30,11 @@ class ShortCodeRelationFinder {
return $found;
}
function findPageCount($number) {
$list = $this->getList($number);
return $list->count();
}
/**
* @return DataList
*/

View File

@ -114,11 +114,27 @@
//work out how many pages are left attached to this document
var form = this.closest('form');
var pagesCount = form.data('pages-count');
var relationCount = form.data('relation-count');
//display an appropriate message
var message = '';
if (pagesCount > 1 || relationCount > 0) {
var pages = '';
if (pagesCount > 1) {
message = "Permanently delete this document and remove it from all pages where it is referenced?\n\nWarning: this document is attached to a total of "+pagesCount+" pages. Deleting it here will permanently delete it from this page and all other pages where it is referenced.";
pages = "\nWarning: doc is attached to a total of "+pagesCount+" pages. ";
}
var references = '';
var referencesWarning = '';
if (relationCount > 0) {
var pname = '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.";
}