diff --git a/admin/javascript/LeftAndMain.EditForm.js b/admin/javascript/LeftAndMain.EditForm.js index 27803198e..87944606b 100644 --- a/admin/javascript/LeftAndMain.EditForm.js +++ b/admin/javascript/LeftAndMain.EditForm.js @@ -262,6 +262,13 @@ this._super(); } }); + + $('.cms-edit-form .ss-gridfield .action-edit').entwine({ + onclick: function(e) { + $('.cms-container').loadPanel(this.attr('href'), '', {selector: '.cms-edit-form'}); + e.preventDefault(); + } + }); }); diff --git a/admin/templates/CMSGridFieldPopupForms.ss b/admin/templates/CMSGridFieldPopupForms.ss new file mode 100644 index 000000000..1981a9b4b --- /dev/null +++ b/admin/templates/CMSGridFieldPopupForms.ss @@ -0,0 +1,4 @@ +
+ Back + $ItemEditForm +
\ No newline at end of file diff --git a/filesystem/Folder.php b/filesystem/Folder.php index fecb3fe8e..6334dfb5c 100644 --- a/filesystem/Folder.php +++ b/filesystem/Folder.php @@ -405,8 +405,8 @@ class Folder extends File { $config->addComponent(new GridFieldPaginator(2)); $config->addComponent(new GridFieldAction_Delete()); $config->addComponent(new GridFieldAction_Edit()); - $config->addComponent($gridFieldForm = new GridFieldItemEditView()); - $gridFieldForm->setTemplate('CMSGridFieldItemEditView'); + $config->addComponent($gridFieldForm = new GridFieldPopupForms()); + $gridFieldForm->setTemplate('CMSGridFieldPopupForms'); $files = DataList::create('File')->filter('ParentID', $this->ID)->exclude('ClassName', 'Folder'); $gridField = new GridField('File','Files', $files, $config); $gridField->setDisplayFields(array( diff --git a/forms/gridfield/GridFieldAction.php b/forms/gridfield/GridFieldAction.php index e35d95bdf..3ae3f040f 100644 --- a/forms/gridfield/GridFieldAction.php +++ b/forms/gridfield/GridFieldAction.php @@ -1,4 +1,90 @@ ''); + } + } + + /** + * Which columns are handled by this component + * + * @param type $gridField + * @return type + */ + public function getColumnsHandled($gridField) { + return array('EditAction'); + } + + /** + * Which GridField actions are this component handling + * + * @param GridField $gridField + * @return array + */ + public function getActions($gridField) { + return array('deleterecord'); + } + + /** + * + * @param GridField $gridField + * @param DataObject $record + * @param string $columnName + * @return string - the HTML for the column + */ + public function getColumnContent($gridField, $record, $columnName) { + return sprintf('%s', Controller::join_links($gridField->Link('item'), $record->ID, 'edit'), _t('GridAction.Edit', 'edit')); + } + + /** + * Handle the actions and apply any changes to the GridField + * + * @param GridField $gridField + * @param string $actionName + * @param mixed $arguments + * @param array $data - form data + * @return void + */ + public function handleAction(GridField $gridField, $actionName, $arguments, $data) { + + } +} + /** * This class is an GridField Component that add Delete action for Objects in the GridField * diff --git a/forms/gridfield/GridFieldPopupForms.php b/forms/gridfield/GridFieldPopupForms.php new file mode 100644 index 000000000..621865312 --- /dev/null +++ b/forms/gridfield/GridFieldPopupForms.php @@ -0,0 +1,143 @@ +/field//item/ + * - /field//item//edit + */ +class GridFieldPopupForms implements GridField_URLHandler { + + /** + * @var String + */ + protected $template = 'GridFieldItemEditView'; + + function getURLHandlers($gridField) { + return array( + 'item/$ID' => 'handleItem', + ); + } + + function handleItem($gridField, $request) { + $record = $gridField->getList()->byId($request->param("ID")); + $handler = new GridFieldPopupForm_ItemRequest($gridField, $this, $record); + $handler->setTemplate($this->template); + return $handler; + } + + /** + * @param String + */ + function setTemplate($template) { + $this->template = $template; + } + + /** + * @return String + */ + function getTemplate() { + return $this->template; + } +} + +class GridFieldPopupForm_ItemRequest extends RequestHandler { + + protected $gridField; + + protected $component; + + protected $record; + + /** + * @var String + */ + protected $template = 'GridFieldItemEditView'; + + static $url_handlers = array( + '$Action!' => '$Action', + '' => 'index', + ); + + function __construct($gridField, $component, $record) { + $this->gridField = $gridField; + $this->component = $gridField; + $this->record = $record; + + parent::__construct(); + } + + function Link($action = null) { + return Controller::join_links($this->gridField->Link('item'), $this->record->ID, $action); + } + + function edit($request) { + $controller = $this->gridField->getForm()->Controller(); + + $return = $this->customise(array( + 'Backlink' => $controller->Link(), + 'ItemEditForm' => $this->ItemEditForm($this->gridField, $request), + ))->renderWith($this->template); + + if($controller->isAjax()) { + return $return; + } else { + // If not requested by ajax, we need to render it within the controller context+template + return $controller->customise(array( + $this->gridField->getForm()->Name() => $return, + )); + } + } + + function ItemEditForm() { + $request = $this->gridField->getForm()->Controller()->getRequest(); + $form = new Form( + $this, + 'ItemEditForm', + $this->record->getCMSFields(), + new FieldList( + $saveAction = new FormAction('doSave', _t('GridFieldDetailsForm.Save', 'Save')) + ) + ); + $saveAction->addExtraClass('ss-ui-action-constructive'); + $form->loadDataFrom($this->record); + return $form; + } + + function doSave($data, $form) { + try { + $form->saveInto($this->record); + $this->record->write(); + } catch(ValidationException $e) { + $form->sessionMessage($e->getResult()->message(), 'bad'); + return Director::redirectBack(); + } + + // TODO Save this item into the given relationship + + $message = sprintf( + _t('ComplexTableField.SUCCESSEDIT2', 'Saved %s %s'), + $this->record->singular_name(), + '"' . htmlspecialchars($this->record->Title, ENT_QUOTES) . '"' + ); + + $form->sessionMessage($message, 'good'); + + return $this->gridField->getForm()->Controller()->redirectBack(); + } + + /** + * @param String + */ + function setTemplate($template) { + $this->template = $template; + } + + /** + * @return String + */ + function getTemplate() { + return $this->template; + } +} \ No newline at end of file diff --git a/templates/GridFieldPopupForms.ss b/templates/GridFieldPopupForms.ss new file mode 100644 index 000000000..b5545b428 --- /dev/null +++ b/templates/GridFieldPopupForms.ss @@ -0,0 +1 @@ +$ItemEditForm \ No newline at end of file