mirror of
https://github.com/silverstripe/silverstripe-dms
synced 2024-10-22 14:05:56 +02:00
ENHANCEMENT: warning when deleting a document that is referenced on other pages
This commit is contained in:
parent
ea9a0639e4
commit
bd75a41f9b
@ -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
|
//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');
|
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
|
//set a class to show if the document is hidden
|
||||||
if ($record->isHidden()) {
|
if ($record->isHidden()) {
|
||||||
|
@ -11,10 +11,13 @@ class DMSGridFieldDetailForm_ItemRequest extends GridFieldDetailForm_ItemRequest
|
|||||||
|
|
||||||
//add a data attribute specifying how many pages this document is referenced on
|
//add a data attribute specifying how many pages this document is referenced on
|
||||||
if ($record = $this->record) {
|
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
|
//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;
|
return $form;
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,11 @@ class ShortCodeRelationFinder {
|
|||||||
return $found;
|
return $found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function findPageCount($number) {
|
||||||
|
$list = $this->getList($number);
|
||||||
|
return $list->count();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return DataList
|
* @return DataList
|
||||||
*/
|
*/
|
||||||
|
@ -114,11 +114,27 @@
|
|||||||
//work out how many pages are left attached to this document
|
//work out how many pages are left attached to this document
|
||||||
var form = this.closest('form');
|
var form = this.closest('form');
|
||||||
var pagesCount = form.data('pages-count');
|
var pagesCount = form.data('pages-count');
|
||||||
|
var relationCount = form.data('relation-count');
|
||||||
|
|
||||||
//display an appropriate message
|
//display an appropriate message
|
||||||
var message = '';
|
var message = '';
|
||||||
if (pagesCount > 1) {
|
if (pagesCount > 1 || relationCount > 0) {
|
||||||
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.";
|
var pages = '';
|
||||||
|
if (pagesCount > 1) {
|
||||||
|
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 {
|
} 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.";
|
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.";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user