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',
|
'getfile',
|
||||||
'getsubtree',
|
'getsubtree',
|
||||||
'movemarked',
|
'movemarked',
|
||||||
'removefile',
|
|
||||||
'save',
|
'save',
|
||||||
'savefile',
|
'savefile',
|
||||||
'uploadiframe',
|
'uploadiframe',
|
||||||
@ -110,7 +109,7 @@ JS
|
|||||||
|
|
||||||
CMSBatchActionHandler::register('delete', 'AssetAdmin_DeleteBatchAction', 'Folder');
|
CMSBatchActionHandler::register('delete', 'AssetAdmin_DeleteBatchAction', 'Folder');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the content of the upload iframe. The form is specified by a template.
|
* Show the content of the upload iframe. The form is specified by a template.
|
||||||
*/
|
*/
|
||||||
@ -609,29 +608,6 @@ JS;
|
|||||||
return $form;
|
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
|
* @return Form
|
||||||
*/
|
*/
|
||||||
|
@ -323,7 +323,7 @@ JS;
|
|||||||
public function getEditForm($id = null) {
|
public function getEditForm($id = null) {
|
||||||
// Include JavaScript to ensure HtmlEditorField works.
|
// Include JavaScript to ensure HtmlEditorField works.
|
||||||
HtmlEditorField::include_js();
|
HtmlEditorField::include_js();
|
||||||
|
|
||||||
if(!$id) $id = $this->currentPageID();
|
if(!$id) $id = $this->currentPageID();
|
||||||
|
|
||||||
$record = ($id) ? $this->getRecord($id) : null;
|
$record = ($id) ? $this->getRecord($id) : null;
|
||||||
|
@ -14,7 +14,8 @@ AssetTableField.prototype = {
|
|||||||
'ctf[ID]' : true,
|
'ctf[ID]' : true,
|
||||||
'FileFilterButton' : true,
|
'FileFilterButton' : true,
|
||||||
'FileFieldName' : true,
|
'FileFieldName' : true,
|
||||||
'FileSearch' : true
|
'FileSearch' : true,
|
||||||
|
'Files[]' : true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -135,35 +136,4 @@ MarkingPropertiesButton.prototype = {
|
|||||||
}
|
}
|
||||||
return false;
|
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,40 +18,15 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
<% if Items %>
|
<% if Items %>
|
||||||
<% control Items %>
|
<% control Items %>
|
||||||
<tr id="record-$Parent.Name-$ID">
|
<% include AssetTableField_Item %>
|
||||||
<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>
|
|
||||||
<% end_control %>
|
<% end_control %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<tr class="notfound">
|
<tr class="notfound">
|
||||||
<td> </td>
|
<td></td>
|
||||||
<% if Markable %><td width="18"> </td><% end_if %>
|
<% if Markable %><th width="18"> </th><% end_if %>
|
||||||
<td colspan="$Headings.Count"><i>No $NamePlural found</i></td>
|
<td colspan="$Headings.Count"><i><% _t('NOITEMSFOUND','No items found') %></i></td>
|
||||||
<% if Can(show) %><td width="18"> </td><% end_if %>
|
<% if Can(delete) %><td width="18"> </td><% end_if %>
|
||||||
<% if Can(edit) %><td width="18"> </td><% end_if %>
|
</tr>
|
||||||
<% if Can(delete) %><td width="18"> </td><% end_if %>
|
|
||||||
</tr>
|
|
||||||
<% end_if %>
|
<% end_if %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
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