Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExtPersist beforeRestore event #520

Merged
merged 3 commits into from
Dec 19, 2015
Merged

Conversation

HobieCat
Copy link
Contributor

Hello there,
I've added a beforeRestore event being fired before the tree status is restored by ExtPersist.
The callback function is passed just like with the restore event, and it may return false to prevent tree state restoration.
If you find this useful, please accept the pull request and merge the code at your convenience.

This should not break any demos, you decide if a new demo is needed.
I suggest to update the wiki and the documentation, feel free to ask if I could be of any help.

Cheers!

HobieCat and others added 3 commits November 18, 2015 15:20
…callback may return false to prevent tree status restoration
Removed trailing whitespaces after Travis CI build failed. My bad, should be OK now.
@mar10
Copy link
Owner

mar10 commented Nov 20, 2015

Thanks, that may be useful. Is there a concrete use-case? Should we add a way to control what kind of status (select, expand, active) is / is not restored?

@HobieCat
Copy link
Contributor Author

Let me try to explain the use-case that made me add this event.
Let's pretend I have a fancytree.php outputting the javascript that loads and displays the fancytree.
If I pass it a get parameter (fancytree.php?forceKey=123) where the value it's a node.key that node must be selected, expanded and activated.
The fancytree.php injects the get parameter in a javascript variable, let's call it forceKey and let its value be 0 if no $_GET['forceKey'] has been passed. Under this assumptions, I initialize the fancytree like:

var forceKey = <?php echo isset($_GET['forceKey']) ? intval($_GET['forceKey']) : 0 ; ?>
$('#tree').fancytree({
    ...
    init: function() {
        if ( forceKey>0 ) {
            // do a getNodeByKey and select, expand and activate the found node
        }
    },
    beforeRestore: function() {
        return forceKey==0; // ExtPersist will not restore, init will take care of selecting, expanding and activating
    }
    ...
});

This use case I very simple and does not take care of node status, it can be quite easily extended to have beforeRestore return an object/array with select, expand and active booleans as a rough idea.
Please let me know if i can be of any help on writing this piece of code and excuse me for my bad english and if I didn't make myself clear: it's almost 01:30 of a quite hot Friday night here in Rome...

Cheers!

@mar10
Copy link
Owner

mar10 commented Nov 22, 2015

Probably the same time zone (I am located near Hamburg) but definitely not the same climate zone (had some snow today...)
I think I am going to merge your PR, after I finished the current refactorings.
Thanks for contributing.

@HobieCat
Copy link
Contributor Author

Excellent, thanks to you for your great job!

mar10 added a commit that referenced this pull request Dec 19, 2015
@mar10 mar10 merged commit af6a07a into mar10:master Dec 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants