Hareeshchandera / jsplumb

Automatically exported from code.google.com/p/jsplumb
0 stars 0 forks source link

add beforeDrop callback option to target Endpoints #128

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
in the same way that tab components allow you to define a callback that is 
fired before a tab change, which can prevent the tab change by returning false, 
jsPlumb should have a 'beforeDrop' option on target Endpoints that does the 
same thing.

the parameters passed to this callback should be sufficient for the user to be 
able to decide whether the connection is allowed: the source element, source 
Endpoint and target element should do it.

Original issue reported on code.google.com by simon.po...@gmail.com on 10 Sep 2011 at 1:11

GoogleCodeExporter commented 8 years ago
May be a good idea to have the Endpoint option 'preventDuplicate', which can be 
'true' or 'false'. Using such option user can permit or deny creating 
connections between two _already connected_ Endpoints (option 'maxConnections' 
allows to control how many _total_ connections are done using that Endpoint and 
not fit this conditions).

Original comment by shs...@gmail.com on 2 Nov 2011 at 11:20

GoogleCodeExporter commented 8 years ago
May be while working on beforeDrop callback it is good to make beforeDisconnect 
callback, which will be called before connection between two Endpoints is 
destroyed, should return true/false to permit/deny destroying of connection.

Original comment by shs...@gmail.com on 5 Nov 2011 at 4:37

GoogleCodeExporter commented 8 years ago
where would you most like to register these callbacks?  i mean, do you want to 
supply them to a connect call:

jsPlumb.connect({ source:s, target:t, beforeDetach:function(connection) {...} 
});

?

how about when creating an Endpoint, so it applies to all connections to/from 
that Endpoint:

jsPlumb.addEndpoint(aDiv, { isSource:true, beforeDetach:function(connection) { 
... } } );

?

and how about directly on jsPlumb itself, binding to an event, as a catch-all:

jsPlumb.bind("beforeDetach", function(connection) { ... });

?

all of those cases seem useful to me!

oh and what about the method signature - you'd only need the connection to be 
passed to your callback, right?

Original comment by simon.po...@gmail.com on 5 Nov 2011 at 5:49

GoogleCodeExporter commented 8 years ago
beforeDrop and beforeDetach have been added to the dev version now.  i've 
decided not to do "preventDuplicate" for the time being; using beforeDrop you 
can mimic that yourself, and it would just bloat out jsPlumb.

beforeDrop can be added as a parameter on an Endpoint that has isTarget:true 
set, like this:

jsPlumb.addEndpoint(someDiv, { 
  isTarget:true, 
  beforeDrop:function(connection) { ... do something, return a boolean }
});

and it can also be bound to jsPlumb itself:

jsPlumb.bind("beforeDrop", function(connection) { ... do something, return a 
boolean });

beforeDetach can be used in each of the ways i described in my last comment.

this will be released in version 1.3.4.

Original comment by simon.po...@gmail.com on 5 Nov 2011 at 7:34

GoogleCodeExporter commented 8 years ago
Great!
> where would you most like to register these callbacks?
In my case most usefull will be jsPlumb.bind(…)

> you'd only need the connection to be passed to your callback, right?
Yes, because connection have information about enpoint too.

Original comment by shs...@gmail.com on 7 Nov 2011 at 4:51

GoogleCodeExporter commented 8 years ago

Original comment by simon.po...@gmail.com on 8 Dec 2011 at 9:15

GoogleCodeExporter commented 8 years ago
1.3.4 was released today.

Original comment by simon.po...@gmail.com on 9 Jan 2012 at 7:00