Merge pull request #146 from silverstripe/ux-fixes/issue7

NEW pages link to document sets
This commit is contained in:
sachajudd 2017-06-07 16:17:33 +12:00 committed by GitHub
commit 55ee260cba
3 changed files with 46 additions and 3 deletions

View File

@ -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(
"<a class='dms-doc-sets-link' href='%s/#Root_DocumentSets%s'>$value</a>",
$page->CMSEditLink(),
$page->DocumentSets()->count()
);
}
}
)
);
}
return $form;

View File

@ -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));

View File

@ -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(
"<a class='dms-doc-sets-link'",
$result
);
}
}