Skip to content

Commit

Permalink
Merge pull request silverstripe#464 from mateusz/os7299
Browse files Browse the repository at this point in the history
BUGFIX: add capability of redirecting form actions.
  • Loading branch information
Sean Harvey committed May 18, 2012
2 parents 1e47b0f + 8b4b896 commit 3f932d6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
6 changes: 3 additions & 3 deletions admin/code/LeftAndMain.php
Expand Up @@ -106,7 +106,7 @@ class LeftAndMain extends Controller implements PermissionProvider {
); );


/** /**
* @var PJAXResponseNegotiator * @var PjaxResponseNegotiator
*/ */
protected $responseNegotiator; protected $responseNegotiator;


Expand Down Expand Up @@ -416,12 +416,12 @@ public function show($request) {
/** /**
* Caution: Volatile API. * Caution: Volatile API.
* *
* @return PJAXResponseNegotiator * @return PjaxResponseNegotiator
*/ */
public function getResponseNegotiator() { public function getResponseNegotiator() {
if(!$this->responseNegotiator) { if(!$this->responseNegotiator) {
$controller = $this; $controller = $this;
$this->responseNegotiator = new PJAXResponseNegotiator(array( $this->responseNegotiator = new PjaxResponseNegotiator(array(
'CurrentForm' => function() use(&$controller) { 'CurrentForm' => function() use(&$controller) {
return $controller->getEditForm()->forTemplate(); return $controller->getEditForm()->forTemplate();
}, },
Expand Down
12 changes: 10 additions & 2 deletions admin/javascript/LeftAndMain.Content.js
Expand Up @@ -80,10 +80,18 @@
// as automatic browser ajax response redirects seem to discard the hash/fragment. // as automatic browser ajax response redirects seem to discard the hash/fragment.
formData.push({name: 'BackURL', value:History.getPageUrl()}); formData.push({name: 'BackURL', value:History.getPageUrl()});


// Some action buttons are redirecting to content areas as oposed to reloading the form.
// They will have pjax-content class on them.
var pjaxType = 'CurrentForm', pjaxSelector = '.cms-edit-form';
if ($(button).hasClass('pjax-content')) {
pjaxType = 'Content';
pjaxSelector = '.cms-content';
}

jQuery.ajax(jQuery.extend({ jQuery.ajax(jQuery.extend({
headers: { headers: {
"X-Pjax" : "CurrentForm", "X-Pjax" : pjaxType,
'X-Pjax-Selector': '.cms-edit-form' 'X-Pjax-Selector': pjaxSelector
}, },
url: form.attr('action'), url: form.attr('action'),
data: formData, data: formData,
Expand Down
3 changes: 2 additions & 1 deletion forms/gridfield/GridFieldDetailForm.php
Expand Up @@ -291,8 +291,9 @@ function ItemEditForm() {
if($this->record->ID !== 0) { if($this->record->ID !== 0) {
$actions->push(FormAction::create('doSave', _t('GridFieldDetailForm.Save', 'Save')) $actions->push(FormAction::create('doSave', _t('GridFieldDetailForm.Save', 'Save'))
->setUseButtonTag(true)->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept')); ->setUseButtonTag(true)->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept'));
// The delete action will redirect, hence pjax-content class.
$actions->push(FormAction::create('doDelete', _t('GridFieldDetailForm.Delete', 'Delete')) $actions->push(FormAction::create('doDelete', _t('GridFieldDetailForm.Delete', 'Delete'))
->addExtraClass('ss-ui-action-destructive')); ->addExtraClass('ss-ui-action-destructive')->addExtraClass('pjax-content'));
}else{ // adding new record }else{ // adding new record
//Change the Save label to 'Create' //Change the Save label to 'Create'
$actions->push(FormAction::create('doSave', _t('GridFieldDetailForm.Create', 'Create')) $actions->push(FormAction::create('doSave', _t('GridFieldDetailForm.Create', 'Create'))
Expand Down

0 comments on commit 3f932d6

Please sign in to comment.