mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
ENHANCEMENT Moved AssetAdmin->deletemarked() logic into AssetTableField
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92826 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
4d60aa5c83
commit
26df8bd9af
@ -360,61 +360,6 @@ HTML;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the "delete marked" action.
|
||||
* Called and returns in same way as 'save' function
|
||||
*/
|
||||
public function deletemarked($urlParams, $form) {
|
||||
$fileList = "'" . ereg_replace(' *, *',"','",trim(addslashes($_REQUEST['FileIDs']))) . "'";
|
||||
$numFiles = 0;
|
||||
$folderID = 0;
|
||||
$deleteList = '';
|
||||
$brokenPageList = '';
|
||||
|
||||
if($fileList != "''") {
|
||||
$files = DataObject::get("File", "\"File\".\"ID\" IN ($fileList)");
|
||||
if($files) {
|
||||
foreach($files as $file) {
|
||||
if($file instanceof Image) {
|
||||
$file->deleteFormattedImages();
|
||||
}
|
||||
if(!$folderID) {
|
||||
$folderID = $file->ParentID;
|
||||
}
|
||||
$file->delete();
|
||||
$numFiles++;
|
||||
}
|
||||
if($brokenPages = Notifications::getItems('BrokenLink')) {
|
||||
$brokenPageList = " ". _t('AssetAdmin.NOWBROKEN', 'These pages now have broken links:') . '</ul>';
|
||||
foreach($brokenPages as $brokenPage) {
|
||||
$brokenPageList .= "<li style="font-size: 65%">" . $brokenPage->Breadcrumbs(3, true) . '</li>';
|
||||
}
|
||||
$brokenPageList .= '</ul>';
|
||||
Notifications::notifyByEmail("BrokenLink", "Page_BrokenLinkEmail");
|
||||
} else {
|
||||
$brokenPageList = '';
|
||||
}
|
||||
|
||||
$deleteList = '';
|
||||
if($folderID) {
|
||||
$remaining = DB::query("SELECT COUNT(*) FROM \"File\" WHERE \"ParentID\" = $folderID")->value();
|
||||
if(!$remaining) $deleteList .= "Element.removeClassName(\$('sitetree').getTreeNodeByIdx('$folderID').getElementsByTagName('a')[0],'contents');";
|
||||
}
|
||||
} else {
|
||||
user_error("No files in $fileList could be found!", E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
$message = sprintf(_t('AssetAdmin.DELETEDX',"Deleted %s files.%s"),$numFiles,$brokenPageList) ;
|
||||
|
||||
FormResponse::add($deleteList);
|
||||
FormResponse::status_message($message, "good");
|
||||
FormResponse::add("$('Form_EditForm').getPageFromServer($('Form_EditForm_ID').value)");
|
||||
|
||||
return FormResponse::respond();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the content to be placed in Form_SubForm when editing a file.
|
||||
* Called using ajax.
|
||||
|
@ -244,6 +244,65 @@ class AssetTableField extends ComplexTableField {
|
||||
return $fieldContainer->FieldHolder();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FormField|null
|
||||
*/
|
||||
function DeleteMarkedButton() {
|
||||
if(!$this->isReadonly() ) {
|
||||
$deleteButton = new InlineFormAction(
|
||||
'deletemarked',
|
||||
_t('Folder.DELSELECTED','Delete selected files'),
|
||||
'delete'
|
||||
);
|
||||
$deleteButton->includeDefaultJS(false);
|
||||
return $deleteButton;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string HTML
|
||||
*/
|
||||
public function deletemarked($request) {
|
||||
$fileIDs = $request->requestVar($this->Name());
|
||||
$numFiles = 0;
|
||||
$brokenPageList = '';
|
||||
|
||||
if($fileIDs && count($fileIDs)) {
|
||||
$files = DataObject::get(
|
||||
"File",
|
||||
sprintf("\"File\".\"ID\" IN (%s)", Convert::raw2sql(implode(',', $fileIDs)))
|
||||
);
|
||||
if($files) {
|
||||
foreach($files as $file) {
|
||||
$file->delete();
|
||||
$numFiles++;
|
||||
}
|
||||
if($brokenPages = Notifications::getItems('BrokenLink')) {
|
||||
$brokenPageList = " ". _t('AssetAdmin.NOWBROKEN', 'These pages now have broken links:') . '<ul>';
|
||||
foreach($brokenPages as $brokenPage) {
|
||||
$brokenPageList .= "<li style="font-size: 65%">" . $brokenPage->Breadcrumbs(3, true) . '</li>';
|
||||
}
|
||||
$brokenPageList .= '</ul>';
|
||||
Notifications::notifyByEmail("BrokenLink", "Page_BrokenLinkEmail");
|
||||
} else {
|
||||
$brokenPageList = '';
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$response = $this->form->Controller()->getResponse();
|
||||
$response->addHeader(
|
||||
'X-Status',
|
||||
sprintf(
|
||||
_t('AssetAdmin.DELETEDX',"Deleted %s file(s) %s"),
|
||||
$numFiles,
|
||||
$brokenPageList
|
||||
)
|
||||
);
|
||||
|
||||
return $response->output();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -1,3 +1,47 @@
|
||||
(function($) {
|
||||
$.concrete('ss', function($){
|
||||
|
||||
$('.AssetTableField :checkbox').concrete({
|
||||
onchange: function() {
|
||||
var container = this.parents('.AssetTableField');
|
||||
var input = container.find('input#deletemarked');
|
||||
if(container.find(':input[name=Files\[\]]:checked').length) {
|
||||
input.removeAttr('disabled');
|
||||
} else {
|
||||
input.attr('disabled', 'disabled');
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* Batch delete files marked by checkboxes in the table.
|
||||
* Refreshes the form field afterwards via ajax.
|
||||
*/
|
||||
$('.AssetTableField input#deletemarked').concrete({
|
||||
onmatch: function() {
|
||||
this.attr('disabled', 'disabled');
|
||||
this._super();
|
||||
},
|
||||
onclick: function(e) {
|
||||
if(!confirm(ss.i18n._t('AssetTableField.REALLYDELETE'))) return false;
|
||||
|
||||
var container = this.parents('.AssetTableField');
|
||||
var self = this;
|
||||
this.addClass('loading');
|
||||
$.post(
|
||||
container.attr('href') + '/deletemarked',
|
||||
this.parents('form').serialize(),
|
||||
function(data, status) {
|
||||
self.removeClass('loading');
|
||||
container[0].refresh();
|
||||
}
|
||||
);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
});
|
||||
}(jQuery));
|
||||
|
||||
AssetTableField = Class.create();
|
||||
AssetTableField.applyTo('#Form_EditForm_Files');
|
||||
AssetTableField.prototype = {
|
||||
@ -96,44 +140,3 @@ FileFilterButton.prototype = {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
MarkingPropertiesButton = Class.create();
|
||||
MarkingPropertiesButton.applyTo(
|
||||
'#Form_EditForm_deletemarked',
|
||||
"Please select some files to delete!", 'deletemarked', 'Do you really want to delete the marked files?'
|
||||
);
|
||||
|
||||
MarkingPropertiesButton.prototype = {
|
||||
initialize: function(noneCheckedError, action, confirmMessage) {
|
||||
this.noneCheckedError = noneCheckedError;
|
||||
this.action = action;
|
||||
this.confirmMessage = confirmMessage;
|
||||
},
|
||||
|
||||
onclick: function() {
|
||||
var i, list = "", checkboxes = $('Form_EditForm').elements['Files[]'];
|
||||
if(!checkboxes) checkboxes = [];
|
||||
if(!checkboxes.length) checkboxes = [ checkboxes ];
|
||||
for(i=0;i<checkboxes.length;i++) {
|
||||
if(checkboxes[i].checked) list += (list?',':'') + checkboxes[i].value;
|
||||
}
|
||||
|
||||
if(list == "") {
|
||||
alert(this.noneCheckedError);
|
||||
return false;
|
||||
|
||||
} else {
|
||||
$('Form_EditForm_FileIDs').value = list;
|
||||
}
|
||||
// If there is a confirmation message, show it before submitting
|
||||
if('' != this.confirmMessage) {
|
||||
// Only submit if OK button is clicked
|
||||
if (confirm(this.confirmMessage)) {
|
||||
$('Form_EditForm').save(false, null, this.action);
|
||||
}
|
||||
} else {
|
||||
$('Form_EditForm').save(false, null, this.action);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -28,6 +28,7 @@ if(typeof(ss) == 'undefined' || typeof(ss.i18n) == 'undefined') {
|
||||
'LeftAndMain.CONFIRMUNSAVEDSHORT': "WARNING: Your changes have not been saved.",
|
||||
'CMSMAIN.ALERTCLASSNAME': 'The page type will be updated after the page is saved',
|
||||
'CMSMAIN.URLSEGMENTVALIDATION': 'URLs can only be made up of letters, digits and hyphens.',
|
||||
'AssetAdmin.BATCHACTIONSDELETECONFIRM': "Do you really want to delete %s folders?"
|
||||
'AssetAdmin.BATCHACTIONSDELETECONFIRM': "Do you really want to delete %s folders?",
|
||||
'AssetTableField.REALLYDELETE': 'Do you really want to delete the marked files?'
|
||||
});
|
||||
}
|
@ -30,4 +30,10 @@
|
||||
<% end_if %>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="utility">
|
||||
$DeleteMarkedButton
|
||||
<% control Utility %>
|
||||
<span class="item"><a href="$Link">$Title</a></span>
|
||||
<% end_control %>
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user