mirror of
https://github.com/silverstripe/silverstripe-dms
synced 2024-10-22 14:05:56 +02:00
BUG DMSUploadField JS template usage
Instead of relying on JavaScript requirements blocking, configure a more specific template name to use in certain situations. We can't control JS files loaded by the browser already by previous requests, so Requirements blocking does not override the template in all cases, creating execution-path specific edge cases (like showing "save to refresh" messages in the background of a "add document" upload success)
This commit is contained in:
parent
8f5c65d539
commit
597e393630
@ -548,10 +548,9 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
|
|||||||
//create upload field to replace document
|
//create upload field to replace document
|
||||||
$uploadField = new DMSUploadField('ReplaceFile', 'Replace file');
|
$uploadField = new DMSUploadField('ReplaceFile', 'Replace file');
|
||||||
$uploadField->setConfig('allowedMaxFileNumber', 1);
|
$uploadField->setConfig('allowedMaxFileNumber', 1);
|
||||||
$uploadField->setConfig('useDMSReplaceTemplate', 1);
|
$uploadField->setConfig('downloadTemplateName', 'ss-dmsuploadfield-downloadtemplate');
|
||||||
$uploadField->setRecord($this);
|
$uploadField->setRecord($this);
|
||||||
|
|
||||||
|
|
||||||
$gridFieldConfig = GridFieldConfig::create()->addComponents(
|
$gridFieldConfig = GridFieldConfig::create()->addComponents(
|
||||||
new GridFieldToolbarHeader(),
|
new GridFieldToolbarHeader(),
|
||||||
new GridFieldSortableHeader(),
|
new GridFieldSortableHeader(),
|
||||||
|
@ -167,15 +167,12 @@ class DMSUploadField extends UploadField {
|
|||||||
public function Field($properties = array()) {
|
public function Field($properties = array()) {
|
||||||
$fields = parent::Field($properties);
|
$fields = parent::Field($properties);
|
||||||
|
|
||||||
//replace the download template with a new one only when access the upload field through a GridField
|
// Replace the download template with a new one only when access the upload field through a GridField.
|
||||||
$useCustomTemplate = $this->getConfig('useDMSReplaceTemplate');
|
// Needs to be enabled through setConfig('downloadTemplateName', 'ss-dmsuploadfield-downloadtemplate');
|
||||||
if (!empty($useCustomTemplate)) {
|
Requirements::javascript('dms/javascript/DMSUploadField_downloadtemplate.js');
|
||||||
Requirements::block(FRAMEWORK_DIR . '/javascript/UploadField_downloadtemplate.js');
|
|
||||||
Requirements::javascript(DMS_DIR.'/javascript/DMSUploadField_downloadtemplate.js');
|
// In the add dialog, add the addtemplate into the set of file that load.
|
||||||
} else {
|
Requirements::javascript('dms/javascript/DMSUploadField_addtemplate.js');
|
||||||
//in the add dialog, add the addtemplate into the set of file that load
|
|
||||||
Requirements::javascript(DMS_DIR.'/javascript/DMSUploadField_addtemplate.js');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $fields;
|
return $fields;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
window.tmpl.cache['ss-uploadfield-downloadtemplate'] = tmpl(
|
window.tmpl.cache['ss-dmsuploadfield-downloadtemplate'] = tmpl(
|
||||||
'{% for (var i=0, files=o.files, l=files.length, file=files[0]; i<l; file=files[++i]) { %}' +
|
'{% 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%}">' +
|
'<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>' +
|
'<div class="ss-uploadfield-item-preview preview"><span>' +
|
||||||
|
Loading…
Reference in New Issue
Block a user