mirror of
https://github.com/silverstripe/silverstripe-dms
synced 2024-10-22 12:05:56 +00:00
API-CHANGE: overriding upload field for DMS
This commit is contained in:
parent
c0b52b939d
commit
f7e0bb918a
@ -423,6 +423,12 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
$fieldsTop = $this->getFieldsForFile();
|
||||
$fields->addFieldToTab('Root.Main',$fieldsTop,'Title');
|
||||
|
||||
//create upload field to replace document
|
||||
$UploadField = new UploadField('file', 'Replace file');
|
||||
$UploadField->setConfig('allowedMaxFileNumber', 1);
|
||||
|
||||
$fields->addFieldToTab('Root.Main',$UploadField);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
26
code/DMSUploadField.php
Normal file
26
code/DMSUploadField.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Field for uploading files into a DMSDocument. Replacing the existing file.
|
||||
*
|
||||
* <b>NOTE: this Field will call write() on the supplied record</b>
|
||||
*
|
||||
* <b>Features (some might not be available to old browsers):</b>
|
||||
*
|
||||
*
|
||||
* @author Julian Seidenberg
|
||||
* @package dms
|
||||
*/
|
||||
class DMSUploadField extends UploadField {
|
||||
|
||||
/**
|
||||
* Override the default behaviour of the UploadField and take the uploaded file (uploaded to assets) and
|
||||
* add it into the DMS storage, deleting the old/uploaded file.
|
||||
* @param File
|
||||
*/
|
||||
protected function attachFile($file) {
|
||||
$dmsDocument = $this->getRecord();
|
||||
$dmsDocument->ingestFile($file);
|
||||
}
|
||||
|
||||
}
|
64
templates/DMSUploadField.ss
Normal file
64
templates/DMSUploadField.ss
Normal file
@ -0,0 +1,64 @@
|
||||
<ul class="ss-uploadfield-files files">
|
||||
<% if $Items %>
|
||||
<% loop $Items %>
|
||||
<li class="ss-uploadfield-item template-download" data-fileid="$ID">
|
||||
<div class="ss-uploadfield-item-preview preview"><span>
|
||||
<img alt="$hasRelation" src="$UploadFieldThumbnailURL" />
|
||||
</span></div>
|
||||
<div class="ss-uploadfield-item-info">
|
||||
<label class="ss-uploadfield-item-name">
|
||||
<b>{$Title}.{$Extension}</b>
|
||||
<span>$Size</span>
|
||||
<div class="clear"><!-- --></div>
|
||||
</label>
|
||||
<div class="ss-uploadfield-item-actions">
|
||||
<% if Top.isDisabled || Top.isReadonly %>
|
||||
<% else %>
|
||||
$UploadFieldFileButtons
|
||||
<% end_if %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ss-uploadfield-item-editform loading includeParent">
|
||||
<iframe frameborder="0" src="$UploadFieldEditLink"></iframe>
|
||||
</div>
|
||||
</li>
|
||||
<% end_loop %>
|
||||
<% end_if %>
|
||||
</ul>
|
||||
<% if isDisabled || isReadonly %>
|
||||
<% if isSaveable %>
|
||||
<% else %>
|
||||
<div class="ss-uploadfield-item">
|
||||
<em><% _t('FileIFrameField.ATTACHONCESAVED2', 'Files can be attached once you have saved the record for the first time.') %></em>
|
||||
</div>
|
||||
<% end_if %>
|
||||
<% else %>
|
||||
<div class="ss-uploadfield-item ss-uploadfield-addfile<% if $Items && $displayInput %> borderTop<% end_if %>" <% if not $displayInput %>style="display: none;"<% end_if %>>
|
||||
<div class="ss-uploadfield-item-preview ss-uploadfield-dropzone ui-corner-all">
|
||||
<% if $multiple %>
|
||||
<% _t('UploadField.DROPFILES', 'drop files') %>
|
||||
<% else %>
|
||||
<% _t('UploadField.DROPFILE', 'drop a file') %>
|
||||
<% end_if %>
|
||||
</div>
|
||||
<div class="ss-uploadfield-item-info">
|
||||
<label class="ss-uploadfield-item-name"><b>
|
||||
<% if $multiple %>
|
||||
<% _t('UploadField.ATTACHFILES', 'Attach files') %>
|
||||
<% else %>
|
||||
<% _t('UploadField.ATTACHFILE', 'Attach a file') %>
|
||||
<% end_if %>
|
||||
</b></label>
|
||||
<label class="ss-uploadfield-fromcomputer ss-ui-button ui-corner-all" title="<% _t('UploadField.FROMCOMPUTERINFO', 'Upload from your computer') %>" data-icon="drive-upload">
|
||||
<% _t('UploadField.FROMCOMPUTER', 'From your computer') %>
|
||||
<input id="$id" name="$getName" class="$extraClass ss-uploadfield-fromcomputer-fileinput" data-config="$configString" type="file"<% if $multiple %> multiple="multiple"<% end_if %> />
|
||||
</label>
|
||||
<button class="ss-uploadfield-fromfiles ss-ui-button ui-corner-all" title="<% _t('UploadField.FROMCOMPUTERINFO', 'Select from files') %>" data-icon="network-cloud"><% _t('UploadField.FROMFILES', 'From files') %></button>
|
||||
<% if not $autoUpload %>
|
||||
<button class="ss-uploadfield-startall ss-ui-button ui-corner-all" title="<% _t('UploadField.STARTALLINFO', 'Start all uploads') %>" data-icon="navigation"><% _t('UploadField.STARTALL', 'Start all') %></button>
|
||||
<% end_if %>
|
||||
<div class="clear"><!-- --></div>
|
||||
</div>
|
||||
<div class="clear"><!-- --></div>
|
||||
</div>
|
||||
<% end_if %>
|
Loading…
x
Reference in New Issue
Block a user