NEW Document sorting (and optional drag'n'drop)

This commit is contained in:
Ingo Schommer 2012-08-21 22:57:40 +02:00
parent bd75a41f9b
commit f7f268a859
3 changed files with 22 additions and 3 deletions

View File

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

View File

@ -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',

View File

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