Communicate JQuery drag back to Wt
Added by Jacob Russell over 11 years ago
I am looking to create a graph using WPaintedDevice with WRectF and addEllipse for 2 different types of nodes that are ellipses and rectangles. I want the nodes to be draggable within the WContainerWidget which I can do with the information found on this thread:
http://redmine.webtoolkit.eu/boards/2/topics/7752?r=8022#message-8022
to make the nodes draggable, but I would like the edges to move when the node is moved. The way that seems easiest to do this is by calling the update method on the node and all of it's edges when the node is moved, but how can I know that it is moved?
Replies (4)
RE: Communicate JQuery drag back to Wt - Added by Jacob Russell over 11 years ago
First of all I should note that I do not consider myself an expert in C (especially initializer lists).
I have found the initial steps to doing this but am having some problems. I am able to create a vector of instances of my node class and move each around using jquery, but now I want to update the positions of my arrows every time that one of my objects is moved.
In my constructor for a node, I have:
doJavascript("$('#"this->id)"').draggable();"); //set each node draggable
doJavascript("$('#"this->id)"').on('dragstop',Wt.emit($('#"this->id()"'),'newCoords',1,1));"); //call newCoords(,1,1) when movement stops
I have tested the first line, and tested the second line replacing "Wt.emit..." with alert and verified that it is calling my function when the object is moved. Now I want to use the new coordinates to update the locations of my arrows but I am having a lot of trouble with the JSignal class.
The first problem is that the Javascript example is a little bit simpler than what I am trying to do, and since I am not a C expert I am having a little bit of trouble generalizing. I have multiple parameters (int x and int y) that I would like to return from each node object and am having difficulty initializing my JSignal<int,int> in the initializer list.
Node::Node(WContainerWidget* parent):WContainerWidget(parent),newCoords_(this,"newCoords"){
...
doJavascript("$('#"this->id)"').draggable();");
doJavascript("$('#"this->id)"').on('dragstop',Wt.emit($('#"this->id()"'),'newCoords',1,1));");
...
}
The constructor for JSignal appears to only take a parent, a name (const char *) and a default false boolean (which I do not pass in) but then expects to initialize all parameters which gives me an error:
invalid reference of non-const reference of type 'Wt::JSignal<int,int>&' from an rvalue of type 'const char*'
Am I even approaching the JSignal correctly? I am just trying to return 2 positions (x and y) to the individual (c) object that was moved in javascript.
RE: Communicate JQuery drag back to Wt - Added by Jacob Russell over 11 years ago
Nevermind, I have fixed the problem, I had an & that I did not need. It still does not return the values to me though.
RE: Communicate JQuery drag back to Wt - Added by Koen Deforche over 11 years ago
Hey,
Your code does look like it should work, at least the logic seems correct. What values do you get in the signal handler server-side?
Regards,
koen
RE: Communicate JQuery drag back to Wt - Added by Jacob Russell over 11 years ago
It does work now, my code to call the Wt.emit was not correct.
doJavascript("$('#"this->id)"').on('dragstop',function(event,ui){Wt.emit($('#"this->id()"'),'newCoords',1,1))};");
I overlooked wrapping my function when I removed my alert.