diff --git a/code/DMSDocument.php b/code/DMSDocument.php index cc0bfe0..8056009 100644 --- a/code/DMSDocument.php +++ b/code/DMSDocument.php @@ -459,21 +459,9 @@ class DMSDocument extends DataObject implements DMSDocumentInterface { $gridFieldConfig ); - //create actions FieldGroup (bottom actions tabs) - /*$actions = new FieldGroup( - CompositeField::create( - $pagesGrid - )->setName("Usage")->addExtraClass('dms-usage-grid') - ); - $actions->setName('DMSActions'); - $fields->add($actions);*/ - $fields->add(new LiteralField('BottomTaskSelection',"
")); $fields->add($UploadField); $fields->add($pagesGrid); - $fields->add(FormAction::create('dod', _t('GridFieldDetailForm.Delete', 'Delete')) - ->addExtraClass('ss-ui-action-destructive')); //delete button - move this to actions area above - return $fields; } diff --git a/code/cms/DMSGridFieldDetailForm.php b/code/cms/DMSGridFieldDetailForm.php index c59cac0..d98d6c8 100644 --- a/code/cms/DMSGridFieldDetailForm.php +++ b/code/cms/DMSGridFieldDetailForm.php @@ -8,46 +8,15 @@ class DMSGridFieldDetailForm_ItemRequest extends GridFieldDetailForm_ItemRequest function ItemEditForm() { $form = parent::ItemEditForm(); - //could try and remove the delete button here (or just hide it in css) + //add a data attribute specifying how many pages this document is referenced on + if ($record = $this->record) { + $numberOfRelations = $record->Pages()->Count(); + + //add the number of pages attached to this field as a data-attribute + $form->setAttribute('data-pages-count', $numberOfRelations); + } return $form; } - - /** - * Overriding delete functionality with our own - * @param $data - * @param $form - * @return mixed - * @throws ValidationException - */ - function doDelete($data, $form) { - try { - $toDelete = $this->record; - if (!$toDelete->canDelete()) { - throw new ValidationException(_t('GridFieldDetailForm.DeletePermissionsFailure',"No delete permissions"),0); - } - - $toDelete->delete(); - } catch(ValidationException $e) { - $form->sessionMessage($e->getResult()->message(), 'bad'); - return Controller::curr()->redirectBack(); - } - - $message = sprintf( - _t('GridFieldDetailForm.Deleted', 'Deleted %s %s'), - $this->record->singular_name(), - '"' . htmlspecialchars($this->record->Title, ENT_QUOTES) . '"' - ); - - $form->sessionMessage($message, 'good'); - - //when an item is deleted, redirect to the revelant admin section without the action parameter - $controller = Controller::curr(); - $noActionURL = $controller->removeAction($data['url']); - $controller->getRequest()->addHeader('X-Pjax', 'Content'); // Force a content refresh - - return $controller->redirect($noActionURL, 302); //redirect back to admin section - } - } \ No newline at end of file diff --git a/javascript/DMSDocumentCMSFields.js b/javascript/DMSDocumentCMSFields.js index 1eb4aba..b681354 100644 --- a/javascript/DMSDocumentCMSFields.js +++ b/javascript/DMSDocumentCMSFields.js @@ -1,4 +1,5 @@ (function($) { + "use strict"; $.entwine('ss', function($) { @@ -6,7 +7,7 @@ onadd: function() { this.addClass('ui-button ss-ui-button ui-corner-all ui-state-default ui-widget ui-button-text-only'); this.parents('ul').removeClass('ui-tabs-nav'); - }, + } }); $('#DocumentTypeID input[type=radio]').entwine({ @@ -31,6 +32,30 @@ } }); + $('#Form_ItemEditForm_action_doDelete').entwine({ + onclick: function(e){ + //work out how many pages are left attached to this document + var form = this.closest('form'); + var pagesCount = form.data('pages-count'); + + //display an appropriate message + var message = ''; + 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."; + } 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(); + return false; + } else { + //user says "okay", so go ahead and do the action + this._super(e); + } + } + }); + });