mirror of
https://github.com/silverstripe/silverstripe-dms
synced 2024-10-22 14:05:56 +02:00
ENHANCEMENT: working replace file and usage listing
This commit is contained in:
parent
449b1d3ba4
commit
fcd29dbf31
@ -408,26 +408,54 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
|
||||
function filenameWithoutID() {
|
||||
$filenameParts = explode('~',$this->Filename);
|
||||
//Debug::Show($filenameParts);
|
||||
$filename = array_pop($filenameParts);
|
||||
//Debug::Show($filename);die;
|
||||
return $filename;
|
||||
}
|
||||
|
||||
|
||||
function getCMSFields() {
|
||||
$fields = parent::getCMSFields();
|
||||
//include JS to handling showing and hiding of bottom "action" tabs
|
||||
Requirements::javascript('dms/javascript/DMSDocumentCMSFields.js');
|
||||
|
||||
$fields->removeFieldsFromTab('Root.Main',array('Created','LastEdited','LastChanged','Filename','Folder'));
|
||||
$fields = new FieldList(); //don't use the automatic scaffolding, it is slow and unnecessary here
|
||||
|
||||
$fieldsTop = $this->getFieldsForFile();
|
||||
$fields->addFieldToTab('Root.Main',$fieldsTop,'Title');
|
||||
$fields->add($fieldsTop);
|
||||
|
||||
$fields->add(new TextField('Title','Title'));
|
||||
$fields->add(new TextareaField('Description','Description'));
|
||||
|
||||
//create upload field to replace document
|
||||
$UploadField = new DMSUploadField('file', 'Replace file');
|
||||
$UploadField = new DMSUploadField('ReplaceFile', 'Replace file');
|
||||
$UploadField->setConfig('allowedMaxFileNumber', 1);
|
||||
|
||||
$fields->addFieldToTab('Root.Main',$UploadField);
|
||||
$gridFieldConfig = GridFieldConfig::create()->addComponents(
|
||||
new GridFieldSortableHeader(),
|
||||
new GridFieldDataColumns(),
|
||||
new GridFieldPaginator(30),
|
||||
new GridFieldEditButton(),
|
||||
new GridFieldDetailForm()
|
||||
);
|
||||
$gridFieldConfig->getComponentByType('GridFieldDataColumns')->setDisplayFields(array('Title'=>'Title','ClassName'=>'Page Type','ID'=>'Page ID'));
|
||||
$pagesGrid = GridField::create(
|
||||
'Pages',
|
||||
false,
|
||||
$this->Pages(),
|
||||
$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($UploadField);
|
||||
$fields->add($pagesGrid);
|
||||
|
||||
|
||||
return $fields;
|
||||
}
|
||||
@ -489,7 +517,7 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
||||
)->setName("FilePreviewData")->addExtraClass('cms-file-info-data')
|
||||
)->setName("FilePreview")->addExtraClass('cms-file-info')
|
||||
);
|
||||
$fields->Name = 'FileP';
|
||||
$fields->setName('FileP');
|
||||
$urlField->dontEscape = true;
|
||||
|
||||
return $fields;
|
||||
|
@ -13,6 +13,8 @@
|
||||
*/
|
||||
class DMSUploadField extends UploadField {
|
||||
|
||||
protected $folderName = 'DMSTemporaryUploads';
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@ -23,4 +25,22 @@ class DMSUploadField extends UploadField {
|
||||
$dmsDocument->ingestFile($file);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Never directly display items uploaded
|
||||
* @return SS_List
|
||||
*/
|
||||
public function getItems() {
|
||||
return new ArrayList();
|
||||
}
|
||||
|
||||
public function Field($properties = array()) {
|
||||
$fields = parent::Field($properties);
|
||||
|
||||
//replace the download template with a new one
|
||||
Requirements::block(FRAMEWORK_DIR . '/javascript/UploadField_downloadtemplate.js');
|
||||
Requirements::javascript('dms/javascript/DMSUploadField_downloadtemplate.js');
|
||||
|
||||
return $fields;
|
||||
}
|
||||
}
|
||||
|
18
javascript/DMSDocumentCMSFields.js
Normal file
18
javascript/DMSDocumentCMSFields.js
Normal file
@ -0,0 +1,18 @@
|
||||
(function($) {
|
||||
|
||||
$.entwine('ss', function($) {
|
||||
$('.ui-state-success-text').entwine({
|
||||
|
||||
onmatch: function() {
|
||||
var form = this.closest('.cms-edit-form');
|
||||
console.log(form);
|
||||
},
|
||||
|
||||
onunmatch: function() {
|
||||
var form = this.closest('.cms-edit-form');
|
||||
console.log(form);
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
});
|
27
javascript/DMSUploadField_downloadtemplate.js
Normal file
27
javascript/DMSUploadField_downloadtemplate.js
Normal file
@ -0,0 +1,27 @@
|
||||
window.tmpl.cache['ss-uploadfield-downloadtemplate'] = tmpl(
|
||||
'{% for (var i=0, files=o.files, l=files.length, file=files[0]; i<l; file=files[++i]) { %}' +
|
||||
'<li class="ss-uploadfield-item template-download{% if (file.error) { %} ui-state-error{% } %}" data-fileid="{%=file.id%}">' +
|
||||
'<div class="ss-uploadfield-item-preview preview"><span>' +
|
||||
'<img src="{%=file.thumbnail_url%}" alt="" />' +
|
||||
'</span></div>' +
|
||||
'<div class="ss-uploadfield-item-info">' +
|
||||
'<label class="ss-uploadfield-item-name">' +
|
||||
'<span class="name" title="{%=file.name%}">{%=file.name%}</span> ' +
|
||||
'{% if (!file.error) { %}' +
|
||||
'<div class="ss-uploadfield-item-status ui-state-success-text" title="'+ss.i18n._t('UploadField.Uploaded', 'Uploaded')+'">'+ss.i18n._t('UploadField.Uploaded', 'Uploaded')+'</div>' +
|
||||
'{% } else { %}' +
|
||||
'<div class="ss-uploadfield-item-status ui-state-error-text" title="{%=o.options.errorMessages[file.error] || file.error%}">{%=o.options.errorMessages[file.error] || file.error%}</div>' +
|
||||
'{% } %}' +
|
||||
'<div class="clear"><!-- --></div>' +
|
||||
'</label>' +
|
||||
'{% if (file.error) { %}' +
|
||||
'<div class="ss-uploadfield-item-actions">' +
|
||||
'<div class="ss-uploadfield-item-cancel ss-uploadfield-item-cancelfailed"><button class="icon icon-16">' + ss.i18n._t('UploadField.CANCEL', 'Cancel') + '</button></div>' +
|
||||
'</div>' +
|
||||
'{% } else { %}' +
|
||||
'<div class="ss-uploadfield-item-actions">(refresh the page to display new file information)</div>' +
|
||||
'{% } %}' +
|
||||
'</div>' +
|
||||
'</li>' +
|
||||
'{% } %}'
|
||||
);
|
Loading…
Reference in New Issue
Block a user