diff --git a/code/cms/DMSDocumentAdmin.php b/code/cms/DMSDocumentAdmin.php index 08f90fd..32dd51e 100644 --- a/code/cms/DMSDocumentAdmin.php +++ b/code/cms/DMSDocumentAdmin.php @@ -13,6 +13,11 @@ class DMSDocumentAdmin extends ModelAdmin private static $menu_icon = 'dms/images/app_icons/drawer.png'; + public function init() + { + parent::init(); + Requirements::javascript(DMS_DIR . '/javascript/DMSGridField.js'); + } /** * Remove the default "add" button and replace it with a customised version for DMS * @@ -41,13 +46,29 @@ class DMSDocumentAdmin extends ModelAdmin if ($this->modelClass === 'DMSDocument') { $gridFieldConfig->removeComponentsByType('GridFieldAddNewButton'); - $gridFieldConfig->addComponent(new DMSGridFieldAddNewButton('buttons-before-left'), 'GridFieldExportButton'); + $gridFieldConfig->addComponent( + new DMSGridFieldAddNewButton('buttons-before-left'), + 'GridFieldExportButton' + ); } elseif ($this->modelClass === 'DMSDocumentSet') { $dataColumns = $gridFieldConfig->getComponentByType('GridFieldDataColumns'); $fields = $dataColumns->getDisplayFields($gridField); $fields = array('Title' => 'Title', 'Page.Title' => 'Page') + $fields; - $dataColumns->setDisplayFields($fields); - Requirements::add_i18n_javascript(DMS_DIR.'/javascript/lang'); + $dataColumns->setDisplayFields($fields) + ->setFieldFormatting( + array( + 'Page.Title' => function ($value, $item) { + // Link a page click directly to the Document Set on the actual page + if ($page = SiteTree::get()->byID($item->PageID)) { + return sprintf( + "$value", + $page->CMSEditLink(), + $page->DocumentSets()->count() + ); + } + } + ) + ); } return $form; diff --git a/javascript/DMSGridField.js b/javascript/DMSGridField.js index 79d294c..0d8a88d 100644 --- a/javascript/DMSGridField.js +++ b/javascript/DMSGridField.js @@ -11,5 +11,14 @@ return false; } }); + + $('.ss-gridfield-item a.dms-doc-sets-link').entwine({ + onclick: function (e){ + // Prevent the initial flash of the gridfield's edit form + e.preventDefault(); + document.location.href=this.attr('href'); + return false; + } + }); }); }(jQuery)); diff --git a/tests/cms/DMSDocumentAdminTest.php b/tests/cms/DMSDocumentAdminTest.php index 38f5aea..0466542 100644 --- a/tests/cms/DMSDocumentAdminTest.php +++ b/tests/cms/DMSDocumentAdminTest.php @@ -57,4 +57,17 @@ class DMSDocumentAdminTest extends FunctionalTest $this->assertContains('Home Test Page', $result); $this->assertContains('About Us Test Page', $result); } + + /** + * Checks that the document sets GridField has a data column which links to the DocumentSets tab on + * the actual page in the CMS + */ + public function testDocumentSetsGridFieldHasLinkToCMSPageEditor() + { + $result = (string)$this->get('admin/documents/DMSDocumentSet')->getBody(); + $this->assertContains( + "