From 607d3e8266711d818b8712accb1ae434f2c2c00f Mon Sep 17 00:00:00 2001 From: Julian Seidenberg Date: Thu, 9 Aug 2012 18:10:50 +1200 Subject: [PATCH] ENHANCEMENT: Editing document defaults after adding --- code/cms/DMSDocumentAddController.php | 29 +++++++++++++---- javascript/DMSDocumentAddExistingField.js | 23 ++++++++++++-- templates/DMSDocumentAddExistingField.ss | 38 ++++++++++++----------- 3 files changed, 64 insertions(+), 26 deletions(-) diff --git a/code/cms/DMSDocumentAddController.php b/code/cms/DMSDocumentAddController.php index 13a9f43..330c1e8 100644 --- a/code/cms/DMSDocumentAddController.php +++ b/code/cms/DMSDocumentAddController.php @@ -172,13 +172,30 @@ class DMSDocumentAddController extends LeftAndMain { } public function linkdocument() { - $page = $this->currentPage(); - $document = DataObject::get_by_id('DMSDocument', (int) $_GET['documentID']); - $document->addPage($page); + $return = array('error' => _t('UploadField.FIELDNOTSET', 'Could not add document to page')); - return json_encode(array( - 'iframe_url' => $this->getEditForm()->Fields()->fieldByName('Main.From your computer.AssetUploadField')->getItemHandler($document->ID)->EditLink() - )); + $page = $this->currentPage(); + if (!empty($page)) { + $document = DataObject::get_by_id('DMSDocument', (int) $_GET['documentID']); + $document->addPage($page); + + // Collect all output data. + $return = array( + 'id' => $document->ID, + 'name' => $document->getTitle(), + 'thumbnail_url' => $document->UploadFieldThumbnailURL, + 'edit_url' => $this->getEditForm()->Fields()->fieldByName('Main.From your computer.AssetUploadField')->getItemHandler($document->ID)->EditLink(), + 'size' => $document->getFileSizeFormatted(), + 'buttons' => $document->renderWith('UploadField_FileButtons'), + '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/javascript/DMSDocumentAddExistingField.js b/javascript/DMSDocumentAddExistingField.js index af440fe..b322c9e 100644 --- a/javascript/DMSDocumentAddExistingField.js +++ b/javascript/DMSDocumentAddExistingField.js @@ -1,7 +1,12 @@ (function($) { + "use strict"; + + $.entwine('ss', function($) { + $('.document-add-existing .document-autocomplete').entwine({ onmatch: function() { - $(this).autocomplete({ + var self = this; + this.autocomplete({ source: 'admin/pages/adddocument/documentautocomplete', select: function(event, ui) { if(ui.item) { @@ -13,7 +18,19 @@ { dataType: 'json', success: function(data, textstatus) { - alert(data.iframe_url); + var fn = window.tmpl.cache['ss-uploadfield-downloadtemplate']; + var fnout = fn({ + files: [data], + formatFileSize: function (bytes) { + if (typeof bytes !== 'number') return ''; + if (bytes >= 1000000000) return (bytes / 1000000000).toFixed(2) + ' GB'; + if (bytes >= 1000000) return (bytes / 1000000).toFixed(2) + ' MB'; + return (bytes / 1000).toFixed(2) + ' KB'; + }, + options: self.fileupload('option') + }); + + $('.ss-add-files').append(fnout); } } ); @@ -22,4 +39,6 @@ }); } }); + + }); }(jQuery)); \ No newline at end of file diff --git a/templates/DMSDocumentAddExistingField.ss b/templates/DMSDocumentAddExistingField.ss index 4a3213b..e2a9f7e 100644 --- a/templates/DMSDocumentAddExistingField.ss +++ b/templates/DMSDocumentAddExistingField.ss @@ -1,22 +1,24 @@ -
+
+
-

- - 1 - Link a Document - -

+

+ + 1 + Link a Document + +

- -
+ +
-
-

- - 2 - Edit details - -

-
-
    +
    +

    + + 2 + Edit details + +

    +
    +
      +
      \ No newline at end of file