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:
Ingo Schommer 2013-01-02 17:28:25 +01:00 committed by Julian Seidenberg
parent 8f5c65d539
commit 597e393630
3 changed files with 8 additions and 12 deletions

View File

@ -548,10 +548,9 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
//create upload field to replace document
$uploadField = new DMSUploadField('ReplaceFile', 'Replace file');
$uploadField->setConfig('allowedMaxFileNumber', 1);
$uploadField->setConfig('useDMSReplaceTemplate', 1);
$uploadField->setConfig('downloadTemplateName', 'ss-dmsuploadfield-downloadtemplate');
$uploadField->setRecord($this);
$gridFieldConfig = GridFieldConfig::create()->addComponents(
new GridFieldToolbarHeader(),
new GridFieldSortableHeader(),

View File

@ -167,15 +167,12 @@ class DMSUploadField extends UploadField {
public function Field($properties = array()) {
$fields = parent::Field($properties);
//replace the download template with a new one only when access the upload field through a GridField
$useCustomTemplate = $this->getConfig('useDMSReplaceTemplate');
if (!empty($useCustomTemplate)) {
Requirements::block(FRAMEWORK_DIR . '/javascript/UploadField_downloadtemplate.js');
Requirements::javascript(DMS_DIR.'/javascript/DMSUploadField_downloadtemplate.js');
} else {
//in the add dialog, add the addtemplate into the set of file that load
Requirements::javascript(DMS_DIR.'/javascript/DMSUploadField_addtemplate.js');
}
// Replace the download template with a new one only when access the upload field through a GridField.
// Needs to be enabled through setConfig('downloadTemplateName', 'ss-dmsuploadfield-downloadtemplate');
Requirements::javascript('dms/javascript/DMSUploadField_downloadtemplate.js');
// In the add dialog, add the addtemplate into the set of file that load.
Requirements::javascript('dms/javascript/DMSUploadField_addtemplate.js');
return $fields;
}

View File

@ -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]) { %}' +
'<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>' +