From f7e0bb918a7f5ac84b091ff96873f239cb978f80 Mon Sep 17 00:00:00 2001 From: Julian Seidenberg Date: Tue, 31 Jul 2012 14:24:35 +1200 Subject: [PATCH] API-CHANGE: overriding upload field for DMS --- code/DMSDocument.php | 6 ++++ code/DMSUploadField.php | 26 +++++++++++++++ templates/DMSUploadField.ss | 64 +++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 code/DMSUploadField.php create mode 100644 templates/DMSUploadField.ss diff --git a/code/DMSDocument.php b/code/DMSDocument.php index 0bb4749..1abf569 100644 --- a/code/DMSDocument.php +++ b/code/DMSDocument.php @@ -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; } diff --git a/code/DMSUploadField.php b/code/DMSUploadField.php new file mode 100644 index 0000000..83f3da3 --- /dev/null +++ b/code/DMSUploadField.php @@ -0,0 +1,26 @@ +NOTE: this Field will call write() on the supplied record + * + * Features (some might not be available to old browsers): + * + * + * @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); + } + +} diff --git a/templates/DMSUploadField.ss b/templates/DMSUploadField.ss new file mode 100644 index 0000000..6a10370 --- /dev/null +++ b/templates/DMSUploadField.ss @@ -0,0 +1,64 @@ + +<% if isDisabled || isReadonly %> + <% if isSaveable %> + <% else %> +
+ <% _t('FileIFrameField.ATTACHONCESAVED2', 'Files can be attached once you have saved the record for the first time.') %> +
+ <% end_if %> +<% else %> +
style="display: none;"<% end_if %>> +
+ <% if $multiple %> + <% _t('UploadField.DROPFILES', 'drop files') %> + <% else %> + <% _t('UploadField.DROPFILE', 'drop a file') %> + <% end_if %> +
+
+ + + + <% if not $autoUpload %> + + <% end_if %> +
+
+
+
+<% end_if %>