mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
ENHANCEMENT Using built-in TableListField javascript deletion for AssetTableField
ENHANCEMENT Less template overloading in AssetTableField.ss git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92820 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
f15e2d8da3
commit
343044e89c
@ -45,7 +45,6 @@ class AssetAdmin extends LeftAndMain {
|
||||
'getfile',
|
||||
'getsubtree',
|
||||
'movemarked',
|
||||
'removefile',
|
||||
'save',
|
||||
'savefile',
|
||||
'uploadiframe',
|
||||
@ -609,29 +608,6 @@ JS;
|
||||
return $form;
|
||||
}
|
||||
|
||||
public function removefile(){
|
||||
if($fileID = $this->urlParams['ID']) {
|
||||
$file = DataObject::get_by_id('File', $fileID);
|
||||
// Delete the temp verions of this file in assets/_resampled
|
||||
if($file instanceof Image) {
|
||||
$file->deleteFormattedImages();
|
||||
}
|
||||
$file->delete();
|
||||
$file->destroy();
|
||||
|
||||
if(Director::is_ajax()) {
|
||||
echo <<<JS
|
||||
$('Form_EditForm_Files').removeFile($fileID);
|
||||
statusMessage('removed file', 'good');
|
||||
JS;
|
||||
} else {
|
||||
Director::redirectBack();
|
||||
}
|
||||
} else {
|
||||
user_error("AssetAdmin::removefile: Bad parameters: File=$fileID", E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Form
|
||||
*/
|
||||
|
@ -14,7 +14,8 @@ AssetTableField.prototype = {
|
||||
'ctf[ID]' : true,
|
||||
'FileFilterButton' : true,
|
||||
'FileFieldName' : true,
|
||||
'FileSearch' : true
|
||||
'FileSearch' : true,
|
||||
'Files[]' : true
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -136,34 +137,3 @@ MarkingPropertiesButton.prototype = {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Behaviour.register({
|
||||
'#Form_EditForm_Files': {
|
||||
removeFile : function(fileID) {
|
||||
var record;
|
||||
if(record = $('record-' + fileID)) {
|
||||
record.parentNode.removeChild(record);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
'#Form_EditForm_Files a.deletelink' : {
|
||||
onclick : function(event) {
|
||||
// Send request
|
||||
new Ajax.Request(this.href + (this.href.indexOf("?") == -1 ? "?" : "&") + "ajax=1", {
|
||||
method : 'get',
|
||||
onSuccess : Ajax.Evaluator,
|
||||
onFailure : function(response) {errorMessage('Server Error', response);}
|
||||
});
|
||||
Event.stop(event);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
'#Form_EditForm' : {
|
||||
changeDetection_fieldsToIgnore : {
|
||||
'Files[]' : true
|
||||
}
|
||||
}
|
||||
});
|
@ -18,38 +18,13 @@
|
||||
<tbody>
|
||||
<% if Items %>
|
||||
<% control Items %>
|
||||
<tr id="record-$Parent.Name-$ID">
|
||||
<td class="dragfile" id="drag-$Parent.Name-$ID">
|
||||
<img id="drag-img-$Parent.Name-$ID" alt="Drag" title="<% _t('DRAGTOFOLDER','Drag to folder on left to move file') %>" src="sapphire/images/drag.gif" />
|
||||
</div>
|
||||
<% if Markable %><td class="markingcheckbox">$MarkingCheckbox</td><% end_if %>
|
||||
<% control Fields %>
|
||||
<td>$Value</td>
|
||||
<% end_control %>
|
||||
<% if Can(show) %>
|
||||
<td width="18" class="action">
|
||||
<a class="popuplink showlink" href="$ShowLink" target="_blank" title="<% _t('SHOW', 'Show asset') %>"><img src="cms/images/show.png" alt="<% _t('SHOW', 'Show asset') %>" /></a>
|
||||
</td>
|
||||
<% end_if %>
|
||||
<% if Can(edit) %>
|
||||
<td width="18" class="action">
|
||||
<a class="popuplink editlink" href="$EditLink" target="_blank" title="<% _t('EDIT', 'Edit asset') %>"><img src="cms/images/edit.gif" alt="<% _t('EDIT', 'Edit asset') %>" /></a>
|
||||
</td>
|
||||
<% end_if %>
|
||||
<% if Can(delete) %>
|
||||
<td width="18" class="action">
|
||||
<a class="deletelink" href="admin/assets/removefile/$ID" title="<% _t('DELFILE', 'Delete this file') %>"><img src="cms/images/delete.gif" alt="<% _t('DELFILE', 'Delete this file') %>" title="<% _t('DELFILE','Delete this file') %>" /></a>
|
||||
</td>
|
||||
<% end_if %>
|
||||
</tr>
|
||||
<% include AssetTableField_Item %>
|
||||
<% end_control %>
|
||||
<% else %>
|
||||
<tr class="notfound">
|
||||
<td> </td>
|
||||
<% if Markable %><td width="18"> </td><% end_if %>
|
||||
<td colspan="$Headings.Count"><i>No $NamePlural found</i></td>
|
||||
<% if Can(show) %><td width="18"> </td><% end_if %>
|
||||
<% if Can(edit) %><td width="18"> </td><% end_if %>
|
||||
<td></td>
|
||||
<% if Markable %><th width="18"> </th><% end_if %>
|
||||
<td colspan="$Headings.Count"><i><% _t('NOITEMSFOUND','No items found') %></i></td>
|
||||
<% if Can(delete) %><td width="18"> </td><% end_if %>
|
||||
</tr>
|
||||
<% end_if %>
|
||||
|
22
templates/Includes/AssetTableField_Item.ss
Normal file
22
templates/Includes/AssetTableField_Item.ss
Normal file
@ -0,0 +1,22 @@
|
||||
<tr id="record-$Parent.id-$ID"<% if HighlightClasses %> class="$HighlightClasses"<% end_if %>>
|
||||
<td class="dragfile" id="drag-$Parent.Name-$ID">
|
||||
<img id="drag-img-$Parent.Name-$ID" alt="Drag" title="<% _t('DRAGTOFOLDER','Drag to folder on left to move file') %>" src="sapphire/images/drag.gif" />
|
||||
</div>
|
||||
<% if Markable %><td class="markingcheckbox">$MarkingCheckbox</td><% end_if %>
|
||||
<% control Fields %>
|
||||
<td class="field-$Title.HTMLATT $FirstLast $Name">$Value</td>
|
||||
<% end_control %>
|
||||
<% control Actions %>
|
||||
<td width="16">
|
||||
<% if IsAllowed %>
|
||||
<a class="$Class" href="$Link">
|
||||
<% if Icon %><img src="$Icon" alt="$Label" /><% else %>$Label<% end_if %>
|
||||
</a>
|
||||
<% else %>
|
||||
<span class="disabled">
|
||||
<% if IconDisabled %><img src="$IconDisabled" alt="$Label" /><% else %>$Label<% end_if %>
|
||||
</span>
|
||||
<% end_if %>
|
||||
</td>
|
||||
<% end_control %>
|
||||
</tr>
|
Loading…
Reference in New Issue
Block a user