2012-07-17 07:58:33 +02:00
|
|
|
<?php
|
|
|
|
class DMSSiteTreeExtension extends DataExtension {
|
|
|
|
|
|
|
|
static $belongs_many_many = array(
|
|
|
|
'Documents' => 'DMSDocument'
|
|
|
|
);
|
2012-07-27 05:38:42 +02:00
|
|
|
|
2012-07-30 02:33:01 +02:00
|
|
|
function updateCMSFields(FieldList $fields){
|
2012-08-01 05:00:43 +02:00
|
|
|
//javascript to customize the grid field for the DMS document (overriding entwine in FRAMEWORK_DIR.'/javascript/GridField.js'
|
|
|
|
Requirements::javascript('dms/javascript/DMSGridField.js');
|
2012-08-07 01:55:05 +02:00
|
|
|
Requirements::css('dms/css/DMSMainCMS.css');
|
2012-08-01 05:00:43 +02:00
|
|
|
|
2012-07-31 04:12:20 +02:00
|
|
|
// Document listing
|
|
|
|
$gridFieldConfig = GridFieldConfig::create()->addComponents(
|
|
|
|
new GridFieldToolbarHeader(),
|
|
|
|
new GridFieldFilterHeader(),
|
|
|
|
new GridFieldSortableHeader(),
|
|
|
|
new GridFieldDataColumns(),
|
|
|
|
new GridFieldPaginator(15),
|
|
|
|
new GridFieldEditButton(),
|
2012-08-01 05:00:43 +02:00
|
|
|
new DMSGridFieldDeleteAction(), //special delete dialog to handle custom behaviour of unlinking and deleting
|
2012-07-31 04:12:20 +02:00
|
|
|
new GridFieldDetailForm()
|
|
|
|
//GridFieldLevelup::create($folder->ID)->setLinkSpec('admin/assets/show/%d')
|
|
|
|
);
|
2012-07-27 05:38:42 +02:00
|
|
|
$modelClass = DMS::$modelClass;
|
2012-08-01 02:27:30 +02:00
|
|
|
$gridFieldConfig->getComponentByType('GridFieldDataColumns')->setDisplayFields($modelClass::$display_fields)
|
|
|
|
->setFieldCasting(array('LastChanged'=>"Date->Ago"))
|
|
|
|
->setFieldFormatting(array('FilenameWithoutID'=>'<a target=\'_blank\' class=\'file-url\' href=\'$DownloadLink\'>$FilenameWithoutID</a>'));
|
2012-08-01 08:37:53 +02:00
|
|
|
|
|
|
|
//override delete functionality with this class
|
|
|
|
$gridFieldConfig->getComponentByType('GridFieldDetailForm')->setItemRequestClass('DMSGridFieldDetailForm_ItemRequest');
|
|
|
|
|
2012-07-31 04:12:20 +02:00
|
|
|
$gridField = GridField::create(
|
|
|
|
'Documents',
|
|
|
|
false,
|
|
|
|
$this->owner->Documents(),
|
|
|
|
$gridFieldConfig
|
|
|
|
);
|
|
|
|
|
|
|
|
$uploadBtn = new LiteralField(
|
|
|
|
'UploadButton',
|
|
|
|
sprintf(
|
|
|
|
'<a class="ss-ui-button ss-ui-action-constructive cms-panel-link" data-pjax-target="Content" data-icon="add" href="%s">%s</a>',
|
|
|
|
Controller::join_links(singleton('DMSDocumentAddController')->Link(), '?ID=' . $this->owner->ID),
|
|
|
|
"Add Document"
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$fields->addFieldsToTab(
|
|
|
|
'Root.Documents',
|
|
|
|
array(
|
|
|
|
$uploadBtn,
|
|
|
|
$gridField
|
2012-07-27 05:38:42 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2012-08-07 04:38:40 +02:00
|
|
|
|
|
|
|
function onBeforeDelete() {
|
|
|
|
$dmsDocuments = $this->owner->Documents();
|
|
|
|
foreach($dmsDocuments as $document) {
|
|
|
|
//if the document is only associated with one page, i.e. only associated with this page
|
|
|
|
if ($document->Pages()->Count() <= 1) {
|
|
|
|
//delete the document before deleting this page
|
|
|
|
$document->delete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-13 04:14:31 +02:00
|
|
|
|
|
|
|
function onBeforePublish() {
|
|
|
|
$embargoedDocuments = $this->owner->Documents()->filter('EmbargoedUntilPublished',true);
|
|
|
|
if ($embargoedDocuments->Count() > 0) {
|
|
|
|
foreach($embargoedDocuments as $doc) {
|
|
|
|
$doc->EmbargoedUntilPublished = false;
|
|
|
|
$doc->write();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2012-07-17 07:58:33 +02:00
|
|
|
}
|