mirror of
https://github.com/silverstripe/silverstripe-dms
synced 2024-10-22 14:05:56 +02:00
FEATURE: Upload button for documents (WIP)
This commit is contained in:
parent
5a13ff221e
commit
c0b52b939d
@ -1,2 +1,3 @@
|
|||||||
<?php
|
<?php
|
||||||
Object::add_extension('SiteTree','DMSSiteTreeExtension');
|
Object::add_extension('SiteTree','DMSSiteTreeExtension');
|
||||||
|
CMSMenu::remove_menu_item('DMSDocumentAddController');
|
142
code/DMSDocumentAddController.php
Normal file
142
code/DMSDocumentAddController.php
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class DMSDocumentAddController extends LeftAndMain {
|
||||||
|
|
||||||
|
static $url_segment = 'pages/adddocument';
|
||||||
|
static $url_priority = 60;
|
||||||
|
static $required_permission_codes = 'CMS_ACCESS_AssetAdmin';
|
||||||
|
static $menu_title = 'Edit Page';
|
||||||
|
public static $tree_class = 'SiteTree';
|
||||||
|
|
||||||
|
// public function upload($request) {
|
||||||
|
// $formHtml = $this->renderWith(array('AssetAdmin_UploadContent'));
|
||||||
|
// if($request->isAjax()) {
|
||||||
|
// return $formHtml;
|
||||||
|
// } else {
|
||||||
|
// return $this->customise(array(
|
||||||
|
// 'Content' => $formHtml
|
||||||
|
// ))->renderWith(array('AssetAdmin', 'LeftAndMain'));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom currentPage() method to handle opening the 'root' folder
|
||||||
|
*/
|
||||||
|
public function currentPage() {
|
||||||
|
$id = $this->currentPageID();
|
||||||
|
|
||||||
|
if($id && is_numeric($id) && $id > 0) {
|
||||||
|
return DataObject::get_by_id('SiteTree', $id);
|
||||||
|
} else {
|
||||||
|
// ID is either '0' or 'root'
|
||||||
|
return singleton('SiteTree');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return fake-ID "root" if no ID is found (needed to upload files into the root-folder)
|
||||||
|
*/
|
||||||
|
public function currentPageID() {
|
||||||
|
if(is_numeric($this->request->requestVar('ID'))) {
|
||||||
|
return $this->request->requestVar('ID');
|
||||||
|
} elseif (is_numeric($this->urlParams['ID'])) {
|
||||||
|
return $this->urlParams['ID'];
|
||||||
|
} elseif(Session::get("{$this->class}.currentPage")) {
|
||||||
|
return Session::get("{$this->class}.currentPage");
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Form
|
||||||
|
* @todo what template is used here? AssetAdmin_UploadContent.ss doesn't seem to be used anymore
|
||||||
|
*/
|
||||||
|
public function getEditForm($id = null, $fields = null) {
|
||||||
|
Requirements::javascript(FRAMEWORK_DIR . '/javascript/AssetUploadField.js');
|
||||||
|
Requirements::css(FRAMEWORK_DIR . '/css/AssetUploadField.css');
|
||||||
|
|
||||||
|
$page = $this->currentPage();
|
||||||
|
|
||||||
|
$uploadField = UploadField::create('AssetUploadField', '');
|
||||||
|
$uploadField->setConfig('previewMaxWidth', 40);
|
||||||
|
$uploadField->setConfig('previewMaxHeight', 30);
|
||||||
|
$uploadField->addExtraClass('ss-assetuploadfield');
|
||||||
|
$uploadField->removeExtraClass('ss-uploadfield');
|
||||||
|
$uploadField->setTemplate('AssetUploadField');
|
||||||
|
|
||||||
|
/*if ($folder->exists() && $folder->getFilename()) {
|
||||||
|
// The Upload class expects a folder relative *within* assets/
|
||||||
|
$path = preg_replace('/^' . ASSETS_DIR . '\//', '', $folder->getFilename());
|
||||||
|
$uploadField->setFolderName($path);
|
||||||
|
} else {
|
||||||
|
$uploadField->setFolderName(ASSETS_DIR);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
$exts = $uploadField->getValidator()->getAllowedExtensions();
|
||||||
|
asort($exts);
|
||||||
|
|
||||||
|
$form = new Form(
|
||||||
|
$this,
|
||||||
|
'getEditForm',
|
||||||
|
new FieldList(
|
||||||
|
$uploadField,
|
||||||
|
new LiteralField(
|
||||||
|
'AllowedExtensions',
|
||||||
|
sprintf(
|
||||||
|
'<p>%s: %s</p>',
|
||||||
|
_t('AssetAdmin.ALLOWEDEXTS', 'Allowed extensions'),
|
||||||
|
implode('<em>, </em>', $exts)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
new HiddenField('ID')
|
||||||
|
),
|
||||||
|
new FieldList()
|
||||||
|
);
|
||||||
|
$form->addExtraClass('center cms-edit-form ' . $this->BaseCSSClasses());
|
||||||
|
// Don't use AssetAdmin_EditForm, as it assumes a different panel structure
|
||||||
|
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
|
||||||
|
/*$form->Fields()->push(
|
||||||
|
new LiteralField(
|
||||||
|
'BackLink',
|
||||||
|
sprintf(
|
||||||
|
'<a href="%s" class="backlink ss-ui-button cms-panel-link" data-icon="back">%s</a>',
|
||||||
|
Controller::join_links(singleton('AssetAdmin')->Link('show'), $folder ? $folder->ID : 0),
|
||||||
|
_t('AssetAdmin.BackToFolder', 'Back to folder')
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);*/
|
||||||
|
//$form->loadDataFrom($folder);
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return ArrayList
|
||||||
|
*/
|
||||||
|
/*public function Breadcrumbs($unlinked = false) {
|
||||||
|
$items = parent::Breadcrumbs($unlinked);
|
||||||
|
|
||||||
|
// The root element should explicitly point to the root node.
|
||||||
|
$items[0]->Link = Controller::join_links(singleton('AssetAdmin')->Link('show'), 0);
|
||||||
|
|
||||||
|
// Enforce linkage of hierarchy to AssetAdmin
|
||||||
|
foreach($items as $item) {
|
||||||
|
$baselink = $this->Link('show');
|
||||||
|
if(strpos($item->Link, $baselink) !== false) {
|
||||||
|
$item->Link = str_replace($baselink, singleton('AssetAdmin')->Link('show'), $item->Link);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$items->push(new ArrayData(array(
|
||||||
|
'Title' => _t('AssetAdmin.Upload', 'Upload'),
|
||||||
|
'Link' => $this->Link()
|
||||||
|
)));
|
||||||
|
|
||||||
|
return $items;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
@ -6,17 +6,41 @@ class DMSSiteTreeExtension extends DataExtension {
|
|||||||
);
|
);
|
||||||
|
|
||||||
function updateCMSFields(FieldList $fields){
|
function updateCMSFields(FieldList $fields){
|
||||||
$documentsListConfig = GridFieldConfig_RecordEditor::create();
|
// Document listing
|
||||||
|
$gridFieldConfig = GridFieldConfig::create()->addComponents(
|
||||||
|
new GridFieldToolbarHeader(),
|
||||||
|
new GridFieldFilterHeader(),
|
||||||
|
new GridFieldSortableHeader(),
|
||||||
|
new GridFieldDataColumns(),
|
||||||
|
new GridFieldPaginator(15),
|
||||||
|
new GridFieldEditButton(),
|
||||||
|
new GridFieldDeleteAction(),
|
||||||
|
new GridFieldDetailForm()
|
||||||
|
//GridFieldLevelup::create($folder->ID)->setLinkSpec('admin/assets/show/%d')
|
||||||
|
);
|
||||||
$modelClass = DMS::$modelClass;
|
$modelClass = DMS::$modelClass;
|
||||||
$documentsListConfig->getComponentByType('GridFieldDataColumns')->setDisplayFields($modelClass::$display_fields);
|
$gridFieldConfig->getComponentByType('GridFieldDataColumns')->setDisplayFields($modelClass::$display_fields);
|
||||||
|
$gridField = GridField::create(
|
||||||
$fields->addFieldToTab(
|
'Documents',
|
||||||
'Root.Documents',
|
false,
|
||||||
GridField::create(
|
$this->owner->Documents(),
|
||||||
'Documents',
|
$gridFieldConfig
|
||||||
false,
|
);
|
||||||
$this->owner->Documents(),
|
|
||||||
$documentsListConfig
|
$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
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user