From be809ac2c94fca286052942a9afc9c03bb42e91b Mon Sep 17 00:00:00 2001 From: Andrew O'Neil Date: Tue, 14 Aug 2012 13:59:08 +1200 Subject: [PATCH] ENHANCEMENT: Show list of documents when page is selected in dropdown --- code/cms/DMSDocumentAddController.php | 17 +++++++++++++++++ javascript/DMSDocumentAddExistingField.js | 6 ++++++ templates/DMSDocumentAddExistingField.ss | 4 ++++ 3 files changed, 27 insertions(+) diff --git a/code/cms/DMSDocumentAddController.php b/code/cms/DMSDocumentAddController.php index 346f530..d8531e0 100644 --- a/code/cms/DMSDocumentAddController.php +++ b/code/cms/DMSDocumentAddController.php @@ -196,6 +196,23 @@ class DMSDocumentAddController extends LeftAndMain { return json_encode($return); } + + public function documentlist() { + $page = DataObject::get_by_id('SiteTree', (int) $_GET['pageID']); + if($page && $page->Documents()) { + $list = ''; + + return $list; + } else { + return '

There are no documents attached to the selected page.

'; + } + } } diff --git a/javascript/DMSDocumentAddExistingField.js b/javascript/DMSDocumentAddExistingField.js index 475bb9d..7c5f302 100644 --- a/javascript/DMSDocumentAddExistingField.js +++ b/javascript/DMSDocumentAddExistingField.js @@ -40,5 +40,11 @@ } }); + $('.document-add-existing input[name=PageSelector]').entwine({ + onchange: function(event) { + $(this).closest('.document-add-existing').find('.document-list').load('admin/pages/adddocument/documentlist?pageID=' + $(this).val()); + } + }); + }); }(jQuery)); \ No newline at end of file diff --git a/templates/DMSDocumentAddExistingField.ss b/templates/DMSDocumentAddExistingField.ss index 04f65dc..2b50262 100644 --- a/templates/DMSDocumentAddExistingField.ss +++ b/templates/DMSDocumentAddExistingField.ss @@ -12,6 +12,10 @@ or Add from page $fieldByName(PageSelector) +
+ +
+