From 043eb540c19653a833ef6c8182469cbc5a5c0865 Mon Sep 17 00:00:00 2001 From: Julian Seidenberg Date: Fri, 10 Aug 2012 12:05:34 +1200 Subject: [PATCH] ENHANCEMENT: Tidy-up of DMS link existing document feature --- code/cms/DMSDocumentAddController.php | 11 ++++----- code/cms/DMSUploadField.php | 9 +++---- javascript/DMSDocumentAddExistingField.js | 2 +- javascript/DMSUploadField_addtemplate.js | 30 +++++++++++++++++++++++ templates/DMSDocumentAddExistingField.ss | 2 +- 5 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 javascript/DMSUploadField_addtemplate.js diff --git a/code/cms/DMSDocumentAddController.php b/code/cms/DMSDocumentAddController.php index 330c1e8..346f530 100644 --- a/code/cms/DMSDocumentAddController.php +++ b/code/cms/DMSDocumentAddController.php @@ -179,23 +179,22 @@ class DMSDocumentAddController extends LeftAndMain { $document = DataObject::get_by_id('DMSDocument', (int) $_GET['documentID']); $document->addPage($page); + $buttonText = ''; + // Collect all output data. $return = array( 'id' => $document->ID, 'name' => $document->getTitle(), - 'thumbnail_url' => $document->UploadFieldThumbnailURL, + 'thumbnail_url' => $document->Icon($document->getFileExt()), 'edit_url' => $this->getEditForm()->Fields()->fieldByName('Main.From your computer.AssetUploadField')->getItemHandler($document->ID)->EditLink(), 'size' => $document->getFileSizeFormatted(), - 'buttons' => $document->renderWith('UploadField_FileButtons'), + 'buttons' => $buttonText, 'showeditform' => true ); } return json_encode($return); - -// array( -// 'iframe_url' => $this->getEditForm()->Fields()->fieldByName('Main.From your computer.AssetUploadField')->getItemHandler($document->ID)->EditLink() -// )); } } diff --git a/code/cms/DMSUploadField.php b/code/cms/DMSUploadField.php index 929b540..f8dd507 100644 --- a/code/cms/DMSUploadField.php +++ b/code/cms/DMSUploadField.php @@ -135,15 +135,11 @@ class DMSUploadField extends UploadField { // CUSTOM Attach the file to the related record. $document = $this->attachFile($file); - // TODO: both $document->UploadFieldThumbnailURL and $document->UploadFieldFileButtons are null, - // check the code from UploadField.php where they use $file->UploadFieldThumbnailURL and $file->UploadFieldFileButtons - // and $file is_a File but in our case $document is a Document, that is why it doesn't work. - // Collect all output data. $return = array_merge($return, array( 'id' => $document->ID, 'name' => $document->getTitle(), - 'thumbnail_url' => $document->UploadFieldThumbnailURL, + 'thumbnail_url' => $document->Icon($document->getFileExt()), 'edit_url' => $this->getItemHandler($document->ID)->EditLink(), 'size' => $document->getFileSizeFormatted(), 'buttons' => $document->renderWith($this->getTemplateFileButtons()), @@ -176,6 +172,9 @@ class DMSUploadField extends UploadField { if (!empty($useCustomTemplate)) { Requirements::block(FRAMEWORK_DIR . '/javascript/UploadField_downloadtemplate.js'); Requirements::javascript('dms/javascript/DMSUploadField_downloadtemplate.js'); + } else { + //in the add dialog, add the addtemplate into the set of file that load + Requirements::javascript('dms/javascript/DMSUploadField_addtemplate.js'); } return $fields; diff --git a/javascript/DMSDocumentAddExistingField.js b/javascript/DMSDocumentAddExistingField.js index b322c9e..ea15059 100644 --- a/javascript/DMSDocumentAddExistingField.js +++ b/javascript/DMSDocumentAddExistingField.js @@ -18,7 +18,7 @@ { dataType: 'json', success: function(data, textstatus) { - var fn = window.tmpl.cache['ss-uploadfield-downloadtemplate']; + var fn = window.tmpl.cache['ss-uploadfield-addtemplate']; var fnout = fn({ files: [data], formatFileSize: function (bytes) { diff --git a/javascript/DMSUploadField_addtemplate.js b/javascript/DMSUploadField_addtemplate.js new file mode 100644 index 0000000..9ea0663 --- /dev/null +++ b/javascript/DMSUploadField_addtemplate.js @@ -0,0 +1,30 @@ +window.tmpl.cache['ss-uploadfield-addtemplate'] = tmpl( + '{% for (var i=0, files=o.files, l=files.length, file=files[0]; i' + + '
' + + '' + + '
' + + '
' + + '' + + '{% if (file.error) { %}' + + '
' + + '
' + + '
' + + '{% } else { %}' + + '
{% print(file.buttons, true); %}
' + + '{% } %}' + + '
' + + '{% if (!file.error) { %}' + + '
' + + '{% } %}' + + '' + + '{% } %}' +); \ No newline at end of file diff --git a/templates/DMSDocumentAddExistingField.ss b/templates/DMSDocumentAddExistingField.ss index e2a9f7e..59c3498 100644 --- a/templates/DMSDocumentAddExistingField.ss +++ b/templates/DMSDocumentAddExistingField.ss @@ -15,7 +15,7 @@

2 - Edit details + Edit Document Details