diff --git a/code/DMSDocument.php b/code/DMSDocument.php index 7823003..078a0b0 100644 --- a/code/DMSDocument.php +++ b/code/DMSDocument.php @@ -408,26 +408,54 @@ class DMSDocument extends DataObject implements DMSDocumentInterface { function filenameWithoutID() { $filenameParts = explode('~',$this->Filename); - //Debug::Show($filenameParts); $filename = array_pop($filenameParts); - //Debug::Show($filename);die; return $filename; } function getCMSFields() { - $fields = parent::getCMSFields(); + //include JS to handling showing and hiding of bottom "action" tabs + Requirements::javascript('dms/javascript/DMSDocumentCMSFields.js'); - $fields->removeFieldsFromTab('Root.Main',array('Created','LastEdited','LastChanged','Filename','Folder')); + $fields = new FieldList(); //don't use the automatic scaffolding, it is slow and unnecessary here $fieldsTop = $this->getFieldsForFile(); - $fields->addFieldToTab('Root.Main',$fieldsTop,'Title'); + $fields->add($fieldsTop); + + $fields->add(new TextField('Title','Title')); + $fields->add(new TextareaField('Description','Description')); //create upload field to replace document - $UploadField = new DMSUploadField('file', 'Replace file'); + $UploadField = new DMSUploadField('ReplaceFile', 'Replace file'); $UploadField->setConfig('allowedMaxFileNumber', 1); - $fields->addFieldToTab('Root.Main',$UploadField); + $gridFieldConfig = GridFieldConfig::create()->addComponents( + new GridFieldSortableHeader(), + new GridFieldDataColumns(), + new GridFieldPaginator(30), + new GridFieldEditButton(), + new GridFieldDetailForm() + ); + $gridFieldConfig->getComponentByType('GridFieldDataColumns')->setDisplayFields(array('Title'=>'Title','ClassName'=>'Page Type','ID'=>'Page ID')); + $pagesGrid = GridField::create( + 'Pages', + false, + $this->Pages(), + $gridFieldConfig + ); + + //create actions FieldGroup (bottom actions tabs) + /*$actions = new FieldGroup( + CompositeField::create( + $pagesGrid + )->setName("Usage")->addExtraClass('dms-usage-grid') + ); + $actions->setName('DMSActions'); + $fields->add($actions);*/ + + $fields->add($UploadField); + $fields->add($pagesGrid); + return $fields; } @@ -489,7 +517,7 @@ class DMSDocument extends DataObject implements DMSDocumentInterface { )->setName("FilePreviewData")->addExtraClass('cms-file-info-data') )->setName("FilePreview")->addExtraClass('cms-file-info') ); - $fields->Name = 'FileP'; + $fields->setName('FileP'); $urlField->dontEscape = true; return $fields; diff --git a/code/cms/DMSUploadField.php b/code/cms/DMSUploadField.php index 83f3da3..0067efb 100644 --- a/code/cms/DMSUploadField.php +++ b/code/cms/DMSUploadField.php @@ -13,6 +13,8 @@ */ class DMSUploadField extends UploadField { + protected $folderName = 'DMSTemporaryUploads'; + /** * Override the default behaviour of the UploadField and take the uploaded file (uploaded to assets) and * add it into the DMS storage, deleting the old/uploaded file. @@ -23,4 +25,22 @@ class DMSUploadField extends UploadField { $dmsDocument->ingestFile($file); } + + /** + * Never directly display items uploaded + * @return SS_List + */ + public function getItems() { + return new ArrayList(); + } + + public function Field($properties = array()) { + $fields = parent::Field($properties); + + //replace the download template with a new one + Requirements::block(FRAMEWORK_DIR . '/javascript/UploadField_downloadtemplate.js'); + Requirements::javascript('dms/javascript/DMSUploadField_downloadtemplate.js'); + + return $fields; + } } diff --git a/javascript/DMSDocumentCMSFields.js b/javascript/DMSDocumentCMSFields.js new file mode 100644 index 0000000..659cae5 --- /dev/null +++ b/javascript/DMSDocumentCMSFields.js @@ -0,0 +1,18 @@ +(function($) { + + $.entwine('ss', function($) { + $('.ui-state-success-text').entwine({ + + onmatch: function() { + var form = this.closest('.cms-edit-form'); + console.log(form); + }, + + onunmatch: function() { + var form = this.closest('.cms-edit-form'); + console.log(form); + } + + }); + }); +}); \ No newline at end of file diff --git a/javascript/DMSUploadField_downloadtemplate.js b/javascript/DMSUploadField_downloadtemplate.js new file mode 100644 index 0000000..c1bbbcd --- /dev/null +++ b/javascript/DMSUploadField_downloadtemplate.js @@ -0,0 +1,27 @@ +window.tmpl.cache['ss-uploadfield-downloadtemplate'] = tmpl( + '{% for (var i=0, files=o.files, l=files.length, file=files[0]; i' + + '
' + + '' + + '
' + + '
' + + '' + + '{% if (file.error) { %}' + + '
' + + '
' + + '
' + + '{% } else { %}' + + '
(refresh the page to display new file information)
' + + '{% } %}' + + '
' + + '' + + '{% } %}' +); \ No newline at end of file