Adding to this discussion with a related question, does anyone have any experience with manipulating the display of the SiteTree in the left CMS pane after creating a new Page in the manner which has been discussed in this thread?
I have a certain class which performs several actions in the onAfterWrite() function (a DataObject in the DataObjectManager popup), amongst which the creation of a new page in the SiteTree which is linked to the saved DataObject. Everything is going fine (thanks to the posts in this thread!), but I'd like for the SiteTree to "refresh" itself so that the created Page is instantly visible to the user, without having to reload the whole CMS.
This has to be possible somehow, as the same thing happens (indirectly) whenever a page in the SiteTree is (e.g.) duplicated. But I've been searching through classes for about half an hour so far and haven't stumbled upon anything which seems to do the trick.
I've noticed that the duplicate() method in the CMSMain class uses the LeftAndMain class' returnItemToUser() method. That method seems to have a bit of custom JavaScript which manipulates the SiteTree. I've tried passing my newly created Page to the returnItemToUser() method, I've tried copy pasting bits of its JavaScript into my onAfterWrite() method (using Requirements::customScript()). None of this does the trick though.
I've had a look in the tree.js file but can't seem to locate any straight-forward "refresh"-type function in there either (which I find odd). Finally, looking at the API for the LeftAndMain class, the following methods appear useful but I can't get them to work for me either:
- ForceReload()
- addTreeNodeJS()
- ajaxupdateparent()