BALKANGraph / FamilyTreeJS

Build family tree app with BALKAN FamilyTreeJS library. Family Tree also called a genealogy or a pedigree chart, is a chart representing family relationships in a conventional tree structure.
50 stars 16 forks source link

nodeTreeMenu event w/ info on the added node(s)? #37

Closed blavv closed 6 months ago

blavv commented 1 year ago

I want to make use of nodeTreeMenu to add node(s) to my tree programmatically.

Is there any event triggered when those placeholder nodes (e.g. "Add husband") are clicked? I've observed "update" and "updated" events are triggered after the nodes are added, but those events only pass FamilyTree object and no specific info on the node(s) that are just added.

Ideally, I want to issue my own node ID(s) for the node(s) that are to be added by clicking on the nodeTreeMenu placeholder node (i.e. send an AJAX request to create one on the server BEFORE the nodes are added to the tree).

ZornitsaPesheva commented 1 year ago

Did you try the "add" event?

blavv commented 1 year ago

Yes, I tried the following events:

add adding added update updating

but only update and updated fired off the events with args being the family tree instance.

ZornitsaPesheva commented 1 year ago

You can use this example to change the id: https://code.balkan.app/family-tree-js/change-id-on-update#JS

blavv commented 1 year ago

Thanks for the codes. What I am trying to do here is to first generate the node record on the server and use the ID assigned by the server to add a new node to the tree, so simply overriding the generateId() won't work - I need more info on the user's intension, such as which node to add the new node to and its relationship.

I guess I'll have to emulate nodeTreeMenu on my own by placing "dummy" nodes with "Add xxx" template with onClick event passing the info I need, and then remove all the dummy nodes once the user clicks on any of the dummies, request to the server for the node & relationship creation, and finally add a new node based on the server response.

The nodeTreeMenu=true seemed so easy, though. I wonder what other people are doing to store the newly created tree nodes on the backend server...

blavv commented 1 year ago

Oh and by the way the code you gave me above doesn't work with adding more than one nodes at a time (e.g. "Add son" with a new husband). I am getting "Uncaught RangeError: Maximum call stack size exceeded".

ZornitsaPesheva commented 1 year ago

We have fixed the code.