Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • snitram 27 posts 48 karma points
    Mar 21, 2011 @ 12:56
    snitram
    0

    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:

    eventDocument.Move(monthFolder.Id);
    umbraco.library.UpdateDocumentCache(eventDocument.Id);


    I've been unsuccessful in experimenting with different approaches found on the forum - so far, I've tried:

    eventDocument.Move(monthFolder.Id);
    umbraco.library.UpdateDocumentCache(eventDocument.Id);

    umbraco.BasePages.BasePage.Current.ClientTools.RefreshTree();
    umbraco.BasePages.BasePage.Current.ClientTools.ChangeContentFrameUrl(String.Concat("editContent.aspx?id=" + eventDocument.Id));


    Or

    eventDocument.Move(monthFolder.Id);
    umbraco.library.UpdateDocumentCache(eventDocument.Id);

    umbraco.BasePages.BasePage.Current.ClientTools.ReloadActionNode(true, true);
    umbraco.BasePages.BasePage.Current.ClientTools.RefreshTree();
    umbraco.BasePages.BasePage.Current.ClientTools.ChangeContentFrameUrl(String.Concat("editContent.aspx?id=" + eventDocument.Id));


    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) :

    eventDocument.Move(monthFolder.Id);
    umbraco.library.UpdateDocumentCache(eventDocument.Id);


    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.

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 21, 2011 @ 13:14
    Tom Fulton
    0

    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:

    umbraco.BasePages.BasePage.Current.ClientTools.SyncTree(eventDocument.Path, true);

    or

    umbraco.BasePages.BasePage.Current.ClientTools.SyncTree(eventDocument.Parent.Path, true);

    Hope this helps,
    Tom

  • snitram 27 posts 48 karma points
    Mar 21, 2011 @ 13:43
    snitram
    0

    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 :(

  • Stephen 767 posts 2273 karma points c-trib
    Mar 21, 2011 @ 13:54
    Stephen
    0

    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

  • snitram 27 posts 48 karma points
    Mar 22, 2011 @ 12:14
    snitram
    0

    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

  • jonok 297 posts 658 karma points
    Jul 21, 2011 @ 05:21
    jonok
    0

    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()?

  • jonok 297 posts 658 karma points
    Jul 23, 2011 @ 02:10
    jonok
    0

    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.

Please Sign in or register to post replies

Write your reply to:

Draft