mirror of
https://github.com/silverstripe/silverstripe-dms
synced 2024-10-22 14:05:56 +02:00
ENHANCEMENT: delete button warning
This commit is contained in:
parent
fd94ad19f4
commit
02fad50ab3
@ -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',"<div id=\"Actions\" class=\"field actions\"><label class=\"left\">Actions</label><ul><li class=\"ss-ui-button\">Replace</li><li class=\"ss-ui-button\">Embargo</li></ul></div>"));
|
||||
$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;
|
||||
}
|
||||
|
@ -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(),
|
||||
'<a href="' . $this->Link('edit') . '">"' . htmlspecialchars($this->record->Title, ENT_QUOTES) . '"</a>'
|
||||
);
|
||||
|
||||
$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
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user