I'm trying to automate the organization of events for an event calendar into sub folders. So far all is working fine except for the focus of the moved document in the content tree. My approach is as follows:
On Document.AfterPublish I check the date field of the event, to find out if the event is placed beneath the correct sub folder - if not, I create the sub folder if it doesn't exist, and then finally move the document to the correct sub folder. The folder structure is like this:
The eventDocument is moved correctly, the document cache is updated (i.e. the url of the event updates correctly), but the content tree collapses, and you manually have to locate the eventDocument once again.
The last two lines of code in my event handlers are:
I found, that if I change the attachment of my event handler to Document.AfterSave, and use the createDate field, then the following works like a charm (reason why I just don't use this, is that my date field isn't available on the creating of an event) :
Is this related to issue #29448? If so, we do have a patch that applies against 4.7 and adds a MoveNode method to ClientTools. That method registers that a node has moved, refreshes the tree accordingly, and sets focus onto that node. We're using it with a custom AutoFolder package of ours.
Haven't had time enough to publish the patch, though, but if you can build from source, let me know and I create a fork with that patch.
I can't seem to get ClientTools.MoveNode() to even move the node - it just stays under the original parent node. Does anything need to be called before or after MoveNode()?
Just thought I'd post how I got the ClientTools.SyncTree() to work for me (this is being called in the AfterSave handler...
When calling SyncTree I pass in the path of the parent of the parent, eg. umbraco.BasePages.BasePage.Current.ClientTools.SyncTree(documentObject.Parent.Parent.Path, true);
Previously I was just calling it with the parent path and it was causing the tree to collapse completely, eg. umbraco.BasePages.BasePage.Current.ClientTools.SyncTree(documentObject.Parent.Path, true);
Don't know why it works one way and not the other.
How to focus a moved Document from event handler
Hi fellow Umbracoates,
I'm trying to automate the organization of events for an event calendar into sub folders. So far all is working fine except for the focus of the moved document in the content tree. My approach is as follows:
On Document.AfterPublish I check the date field of the event, to find out if the event is placed beneath the correct sub folder - if not, I create the sub folder if it doesn't exist, and then finally move the document to the correct sub folder. The folder structure is like this:
Event calendar
- 2011
-- March
--- Event 1
--- Event 2
The eventDocument is moved correctly, the document cache is updated (i.e. the url of the event updates correctly), but the content tree collapses, and you manually have to locate the eventDocument once again.
The last two lines of code in my event handlers are:
I've been unsuccessful in experimenting with different approaches found on the forum - so far, I've tried:
Or
I found, that if I change the attachment of my event handler to Document.AfterSave, and use the createDate field, then the following works like a charm (reason why I just don't use this, is that my date field isn't available on the creating of an event) :
I should mention that I'm working on Umbraco 4.7.0 running on Windows Server 2008 and MSSQL Express.
Any help would be greatly appreciated.
Hi,
If I understand correctly you are wanting to refresh the tree and select the newly moved node? You should be able to use SyncTree for this:
or
Hope this helps,
Tom
Hi Tom
You are correct - I need to select the newly moved node in the content tree.
Thanks for your suggestions - I tried both of them without any luck :(
Is this related to issue #29448? If so, we do have a patch that applies against 4.7 and adds a MoveNode method to ClientTools. That method registers that a node has moved, refreshes the tree accordingly, and sets focus onto that node. We're using it with a custom AutoFolder package of ours.
Haven't had time enough to publish the patch, though, but if you can build from source, let me know and I create a fork with that patch.
Stephen
Hi Stephen
It sounds like that could be my problem. I can indeed build from source, so if you could create the fork, that would be grand
I can't seem to get ClientTools.MoveNode() to even move the node - it just stays under the original parent node. Does anything need to be called before or after MoveNode()?
Just thought I'd post how I got the ClientTools.SyncTree() to work for me (this is being called in the AfterSave handler...
When calling SyncTree I pass in the path of the parent of the parent, eg.
umbraco.BasePages.BasePage.Current.ClientTools.SyncTree(documentObject.Parent.Parent.Path, true);
Previously I was just calling it with the parent path and it was causing the tree to collapse completely, eg.
umbraco.BasePages.BasePage.Current.ClientTools.SyncTree(documentObject.Parent.Path, true);
Don't know why it works one way and not the other.
is working on a reply...