FEATURE: WIP add existing document to page

This commit is contained in:
Andrew O'Neil 2012-08-06 17:52:18 +12:00
parent 546546ced1
commit 8be5a754bc
3 changed files with 75 additions and 8 deletions

View File

@ -73,18 +73,28 @@ class DMSDocumentAddController extends LeftAndMain {
<a class=\"ss-ui-button ss-ui-action-constructive cms-panel-link ui-corner-all\" href=\"".$backlink."\">
Done!
</a>";
$addExistingField = new DMSDocumentAddExistingField('AddExisting', 'Add Existing');
$addExistingField->setRecord($page);
$form = new Form(
$this,
'getEditForm',
new FieldList(
new HiddenField('ID', false, $page->ID),
$uploadField,
new LiteralField(
'AllowedExtensions',
sprintf(
'<p>%s: %s</p>',
_t('AssetAdmin.ALLOWEDEXTS', 'Allowed extensions'),
implode('<em>, </em>', $exts)
new TabSet('Main',
new Tab('From your computer',
new HiddenField('ID', false, $page->ID),
$uploadField,
new LiteralField(
'AllowedExtensions',
sprintf(
'<p>%s: %s</p>',
_t('AssetAdmin.ALLOWEDEXTS', 'Allowed extensions'),
implode('<em>, </em>', $exts)
)
)
),
new Tab('From the CMS',
$addExistingField
)
)
),

View File

@ -0,0 +1,37 @@
<?php
class DMSDocumentAddExistingField extends FormField {
/**
* Force a record to be used as "Parent" for uploaded Files (eg a Page with a has_one to File)
* @param DataObject $record
*/
public function setRecord($record) {
$this->record = $record;
return $this;
}
/**
* Get the record to use as "Parent" for uploaded Files (eg a Page with a has_one to File) If none is set, it will use Form->getRecord() or Form->Controller()->data()
* @return DataObject
*/
public function getRecord() {
if (!$this->record && $this->form) {
if ($this->form->getRecord() && is_a($this->form->getRecord(), 'DataObject')) {
$this->record = $this->form->getRecord();
} elseif ($this->form->Controller() && $this->form->Controller()->hasMethod('data')
&& $this->form->Controller()->data() && is_a($this->form->Controller()->data(), 'DataObject')) {
$this->record = $this->form->Controller()->data();
}
}
return $this->record;
}
public function FieldHolder($properties = array()) {
return $this->Field($properties);
}
public function Field($properties = array()) {
return $this->renderWith('DMSDocumentAddExistingField');
}
}
?>

View File

@ -0,0 +1,20 @@
<div class="field">
<h3>
<span class="step-label">
<span class="flyout">1</span><span class="arrow"></span>
<span class="title">Link a Document</span>
</span>
</h3>
</div>
<div>
<h3>
<span class="step-label">
<span class="flyout">2</span><span class="arrow"></span>
<span class="title">Edit details</span>
</span>
</h3>
<div class="fileOverview">
<ul class="files"></ul>
</div>