From f7f268a859db0767bba3492aec9f97e54a86a9db Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 21 Aug 2012 22:57:40 +0200 Subject: [PATCH] NEW Document sorting (and optional drag'n'drop) --- README.md | 1 + code/DMSDocument.php | 8 +++++++- code/DMSSiteTreeExtension.php | 16 ++++++++++++++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e8751b0..6055bac 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ Example: ### Requirements * PHP 5.3 with the "fileinfo" module (or alternatively the "whereis" and "file" Unix commands) + * (optional) [https://github.com/UndefinedOffset/SortableGridField]("SortableGridField" module) ### Configuration diff --git a/code/DMSDocument.php b/code/DMSDocument.php index b278453..923f8a7 100644 --- a/code/DMSDocument.php +++ b/code/DMSDocument.php @@ -17,7 +17,13 @@ class DMSDocument extends DataObject implements DMSDocumentInterface { 'Pages' => 'SiteTree', 'Tags' => 'DMSTag' ); - + + static $many_many_extraFields = array( + 'Pages' => array( + 'DocumentSort' => 'Int' + ), + ); + static $display_fields = array( 'ID'=>'ID', 'Title'=>'Title', diff --git a/code/DMSSiteTreeExtension.php b/code/DMSSiteTreeExtension.php index ceb18cc..a1e4b81 100644 --- a/code/DMSSiteTreeExtension.php +++ b/code/DMSSiteTreeExtension.php @@ -4,7 +4,7 @@ class DMSSiteTreeExtension extends DataExtension { static $belongs_many_many = array( 'Documents' => 'DMSDocument' ); - + function updateCMSFields(FieldList $fields){ //javascript to customize the grid field for the DMS document (overriding entwine in FRAMEWORK_DIR.'/javascript/GridField.js' Requirements::javascript('dms/javascript/DMSGridField.js'); @@ -19,12 +19,17 @@ class DMSSiteTreeExtension extends DataExtension { new GridFieldFilterHeader(), new GridFieldSortableHeader(), new GridFieldDataColumns(), - new GridFieldPaginator(15), + $paginatorComponent = new GridFieldPaginator(15), new GridFieldEditButton(), new DMSGridFieldDeleteAction(), //special delete dialog to handle custom behaviour of unlinking and deleting new GridFieldDetailForm() //GridFieldLevelup::create($folder->ID)->setLinkSpec('admin/assets/show/%d') ); + if(class_exists('GridFieldSortableRows')) { + $sortableComponent = new GridFieldSortableRows('DocumentSort'); + $sortableComponent->setUsePagination(false)->setForceRedraw(true); + $gridFieldConfig->addComponent($sortableComponent); + } // HACK: Create a singleton of DMSDocument to ensure extensions are applied before we try to get display fields. singleton('DMSDocument'); @@ -60,6 +65,13 @@ class DMSSiteTreeExtension extends DataExtension { ); } + /** + * Overloaded to enforce sorting + */ + function Documents() { + return $this->owner->getManyManyComponents('Documents')->sort('DocumentSort'); + } + function onBeforeDelete() { $dmsDocuments = $this->owner->Documents(); foreach($dmsDocuments as $document) {