From 66422c0a31ae85e9e4eabaa6727a6acf3018584a Mon Sep 17 00:00:00 2001 From: Julian Seidenberg Date: Tue, 7 Aug 2012 17:11:46 +1200 Subject: [PATCH] ENHANCEMENT: re-adding modified downloadtemplate, but only in specific case when access it through a grid field --- code/cms/DMSUploadField.php | 13 +++++++++++-- javascript/DMSUploadField_downloadtemplate.js | 5 +---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/code/cms/DMSUploadField.php b/code/cms/DMSUploadField.php index 5fab3e2..929b540 100644 --- a/code/cms/DMSUploadField.php +++ b/code/cms/DMSUploadField.php @@ -16,6 +16,14 @@ class DMSUploadField extends UploadField { protected $folderName = 'DMSTemporaryUploads'; + public function __construct($name, $title = null, SS_List $items = null) { + parent::__construct($name, $title, $items); + + //set default DMS replace template to false + $this->setConfig('useDMSReplaceTemplate', 0); + } + + /** * 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. @@ -163,8 +171,9 @@ class DMSUploadField extends UploadField { public function Field($properties = array()) { $fields = parent::Field($properties); - //replace the download template with a new one - if (!empty($this->getConfig('useDMSReplaceTemplate'))) { + //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/javascript/DMSUploadField_downloadtemplate.js'); } diff --git a/javascript/DMSUploadField_downloadtemplate.js b/javascript/DMSUploadField_downloadtemplate.js index a2e29e9..3010ab8 100644 --- a/javascript/DMSUploadField_downloadtemplate.js +++ b/javascript/DMSUploadField_downloadtemplate.js @@ -19,12 +19,9 @@ window.tmpl.cache['ss-uploadfield-downloadtemplate'] = tmpl( '
' + '' + '{% } else { %}' + - '
{% print(file.buttons, true); %}
' + + '
(please refresh the page to display new file information)
' + '{% } %}' + '' + - '{% if (!file.error) { %}' + - '
' + - '{% } %}' + '' + '{% } %}' ); \ No newline at end of file