Skip to content

Commit

Permalink
Drag and Drop : replace graphics switch with graphic move
Browse files Browse the repository at this point in the history
  • Loading branch information
jcornet committed Aug 28, 2015
1 parent 5fb5e8b commit d2fbf9a
Showing 1 changed file with 43 additions and 8 deletions.
51 changes: 43 additions & 8 deletions Widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,11 @@ define([
var from_i = tr_id.split("--")[tr_id.split("--").length - 1];
var to_i = target_tr.id.split("--")[target_tr.id.split("--").length - 1];

// @TODO Know if drop in top (down target) or bottom (under target) of row

//Switch the 2 rows
this.switch2DrawingGraphics(from_i, to_i);
this.moveDrawingGraphic(from_i, to_i);
this.listGenerateDrawTable();

// console.log("Drop", tr_id, target_tr.id);
},

_listOnDragOver:function(evt){
Expand All @@ -405,19 +405,54 @@ define([
this.drawBox.drawLayer.graphics[i2] = g1;

//Redraw in good order
var start_i = (i1 < i2) ? i1 : i2;
this._redrawGraphics(start_i);
return true;
},

moveDrawingGraphic:function(from_i, to_i){
from_i = parseInt(from_i);
to_i = parseInt(to_i);

if(from_i == to_i)
return;

//get from graphic
var from_graphic = this.drawBox.drawLayer.graphics[from_i];

//Move graphics up or down
if(from_i < to_i){
for(var i=from_i, nb=this.drawBox.drawLayer.graphics.length; i < to_i && i < nb; i++)
this.drawBox.drawLayer.graphics[i] = this.drawBox.drawLayer.graphics[i+1];
}
else{
for(var i=from_i, nb=this.drawBox.drawLayer.graphics.length; i > to_i && i > 0; i--)
this.drawBox.drawLayer.graphics[i] = this.drawBox.drawLayer.graphics[i-1];
}

//Copy from graphic in destination
this.drawBox.drawLayer.graphics[to_i] = from_graphic;

//Redraw in good order
var start_i = (from_i < to_i) ? from_i : to_i;
this._redrawGraphics(start_i);
return true;
},

_redrawGraphics:function(start_i){
if(!start_i)
start_i = 0;
var nb = this.drawBox.drawLayer.graphics.length;
for (var i = 0; i < nb; i++) {
var g = this.drawBox.drawLayer.graphics[i];

if (i >= i1 || i >= i2) {
if (i >= start_i) {
var g = this.drawBox.drawLayer.graphics[i];
var shape = g.getShape();
if (shape)
shape.moveToFront();
}
}
return true;

},

listOnActionClick : function (evt) {
if (!evt.target || !evt.target.id)
return;
Expand Down

0 comments on commit d2fbf9a

Please sign in to comment.