icecaster/silverstripe-versioned-gridfield

doRollback problem

Opened this issue · 6 comments

Hi Icecaster,

Firstly thanks for producing this module. I was wondering if you are able to help with this issue I am experiencing though. I don't know if this is an isolated problem on my installation but for some reason the redirect is not taking place when pressing the 'cancel draft changes'. It sometimes works the first time but after that if I press it a second time after saving a draft it doesn't work.

If I refresh the browser manually then I am returned to the edit form and the draft has been reverted to the published version as it should be.

So for some reason line 210 = return Controller::curr()->redirect($this->Link('edit')); is not being fired in VersionedGridFieldDetailForm.php.

Have you experienced this issue? or do you have any ideas on how I can resolve this issue? I hope that makes sense.

Cheers,

Jim

Hi Jim,

Which version of SS are you using?

Cheers

Hi Icecaster,

I am currently using SS 3.0.5.

Many thanks, Jim

Hey Jim,

so far I'm unable to reproduce the problem.
Can you check your js console for any errors?

cheers

Hi again Icecaster,

Weird thing about this is that Firebug isn't reporting any js errors at all. Not very helpful really. I tested the 'cancel draft changes' on the Pages tab in the CMS and there are no issues there but had a little trouble getting the code that powers that to work in Model Admin. I am a little stumped on this one. I can send you log in details if you want to have a look and see if anything jumps out at you.

Cheers

Just noticed something that might help solve this maybe. On the edit form if I remove 'edit' from the url and then reload the page without the 'edit' on the end of the url and then press the 'cancel draft changes' button it works as it should. By doing this it then reverts the url back to the full url with 'edit' on the end.

Process I took to produce this effect:

  1. change text and click on 'save draft'.
  2. once daft has been saved manually change '../admin/blog_admin/BlogEntryExtended/EditForm/field/BlogEntryExtended/item/40/edit' url to
    '../admin/blog_admin/BlogEntryExtended/EditForm/field/BlogEntryExtended/item/40/'
  3. refresh the page and then click on 'cancel draft changes' then this redirects the page back to the first url listed.

I hope that makes sense. I suspect it is a js problem that is causing this. I will keep looking into this but any further suggestions would be appreciated.

Cheers

Hi again,

I have ended up just using the below to return the user back to the list view. Not the best solution I know but it will have to do for now. I am still not sure why this isn't working the way it should. Here is my code though if anyone else experiences the problem I am:

function doRollback($data, $form) {
        $record = $this->record;
        $controller = Controller::curr();
        try {
            if($record){
                $record->publish("Live", "Stage", false);
            }
        } catch(ValidationException $e) {
            $form->sessionMessage($e->getResult()->message(), 'bad');
            return $controller->redirectBack();
        }

        $message = sprintf(
          _t('GridFieldDetailForm.doRollBack', 'Cancelled Draft changes for %s %s'),
          $record->singular_name(),
          '<a href="' . $this->Link('edit') . '">"' . htmlspecialchars($record->Title, ENT_QUOTES) . '"</a>'
        );

        $toplevelController = $this->getToplevelController();
        if($toplevelController && $toplevelController instanceof LeftAndMain) {
            $backForm = $toplevelController->getEditForm();
            $backForm->sessionMessage($message, 'good');
        } else {
            $form->sessionMessage($message, 'good');
        }

        $noActionURL = $controller->removeAction($data['url']);
        $controller->getRequest()->addHeader('X-Pjax', 'Content'); // Force a content refresh
        return $controller->redirect($noActionURL, 302);
}

On the other hand I have managed to get the preview working correctly as it does on the pages tab so I can give you the code I am using for you to check out. It does require a modification to the page type you are managing through Model admin. Let me know if would like to take a look.

Cheers,

Jim