Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implemented a drop to canvas feature, could be used to create new ele…

…ments by dragging a connector and dropping it to the empty canvas
  • Loading branch information...
commit 7e940bd7d524f6de3976b5dde580ac2eb6c6c7a9 1 parent 19c5aaa
@zubairov zubairov authored etgryphon committed
View
5 frameworks/linkit/mixins/terminal.js
@@ -353,7 +353,10 @@ LinkIt.Terminal = {
// First, Check nodes for compatability
var links = this._getLinkObjects(otherTerminal, otherNode, this, myNode);
myNodeAccepted = (myNode && links[0]) ? myNode.canLink( links[0] ) : NO;
- otherNodeAccepted = (otherNode && myNodeAccepted && links[1]) ? otherNode.canLink( links[1] ) : NO;
+ otherNodeAccepted = (otherNode && myNodeAccepted && links[1]) ? otherNode.canLink( links[1] ) : NO;
+ }
+ if (otherTerminal && otherTerminal.get('isCanvas')) {
+ return otherTerminal.get('acceptCanvasDrop');
}
return (myNodeAccepted && otherNodeAccepted);
},
View
43 frameworks/linkit/views/canvas.js
@@ -67,9 +67,50 @@ LinkIt.CanvasView = SC.CollectionView.extend({
/**
*/
displayProperties: ['frame'],
+
+ /**
+ * Easy to use detection of the canvas class
+ */
+ isCanvas : YES,
- // PUBLIC METHODS
+ //*** SC.DropTarget ***
+ /**
+ Must be true when your view is instantiated.
+ Drop targets must be specially registered in order to receive drop
+ events. SproutCore knows to register your view when this property
+ is true on view creation.
+ */
+ isDropTarget: YES,
+
+ // PUBLIC METHODS
+
+ /**
+ * You would need to override this function with your specific handler
+ * to handle Drops to the canvas.
+ */
+ acceptCanvasDrop: YES,
+
+ computeDragOperations: function(drag, evt) {
+ // Make it dependent on acceptCanvasDrop
+ return this.acceptCanvasDrop?SC.DRAG_LINK:SC.DRAG_NONE;
+ },
+
+ /**
+ * Overridden perform drag operation so that CollectionView#performDragOperation will
+ * not get called.
+ * If you would like to implement a Canvas Drop to Create a new element
+ * just override this operation to do what you need to do
+ *
+ * @param drag
+ * @param op
+ * @returns
+ */
+ performDragOperation: function(drag, op) {
+ return SC.DRAG_NONE;
+ },
+
+
/**
Call this to trigger a links refresh
*/
Please sign in to comment.
Something went wrong with that request. Please try again.