Skip to content

Commit

Permalink
子要素の移動
Browse files Browse the repository at this point in the history
  • Loading branch information
motsat committed Jul 7, 2011
1 parent fd47611 commit 78d9fd7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
29 changes: 27 additions & 2 deletions public/js/objectMediator.js
Expand Up @@ -59,6 +59,7 @@ TaskRenderer.prototype.renderTaskChild = function(x, y, task, mediator){
.attr($.extend(this.v.pathL.attr,{'scale':0.1}))
.animate( {'scale':1}, 100)
.toBack();
s.push(p);
s.click(function(){mediator.showEditBox(task, s)});
return s;
}
Expand Down Expand Up @@ -97,7 +98,7 @@ ObjectMediator.prototype.setUp = function(config, objects) {
var sets = [];
for (var i=0; i < objects.tasks.length; i++) {
sets[i] = this.taskRenderer.renderTaskParent(nextX, v.paper.margin.h, objects.tasks[i], this, false) ;
pushArrayAt(this.shapes.tasks, i, {parent:sets[i]});
pushArrayAt(this.shapes.tasks, i, {parent:sets[i], childs:[]});
nextX += (v.rectP.w + v.taskMargin.w);
}

Expand Down Expand Up @@ -134,6 +135,8 @@ ObjectMediator.prototype.addChildTask = function(task, shapes)
taskShape = this.taskRenderer.renderTaskChild(x,y, newTask, this);

task.tasks.push(newTask);
var order = this.orderOfParentTask(task);
this.shapes.tasks[order].childs.push(taskShape);
}
ObjectMediator.prototype.addParentTask = function(x)
{
Expand All @@ -144,7 +147,7 @@ ObjectMediator.prototype.addParentTask = function(x)
//this.objects.tasks = pushArrayAt(this.objects.tasks, num, newTask);
//this.shapes.tasks = pushArrayAt(this.shapes.tasks, num, taskShape);
pushArrayAt(this.objects.tasks, num, newTask);
pushArrayAt(this.shapes.tasks, num, {parent:taskShape});
pushArrayAt(this.shapes.tasks, num, {parent:taskShape, childs:[]});
this.moveTaskShapesAt(num + 1); // 追加分以降のものを移動
}
ObjectMediator.prototype.calculateTaskX = function(num)
Expand All @@ -158,6 +161,13 @@ ObjectMediator.prototype.moveRaphaelSets = function(sets, x) {

for (var n = 0; n < sets.items.length; n++){
var item = sets.items[n];
if (item.type == 'path') {
path = $.extend(true, [], item.attr('path')); // deep copy
path[0][1] += v.rectP.w + v.taskMargin.w;
path[1][1] += v.rectP.w + v.taskMargin.w;

item.animate({'path':pathToString(path)}, 500);
}
var x = item.getBBox().x;
item.animate( {'x': x + v.rectP.w + v.taskMargin.w}, 500);
}
Expand All @@ -176,6 +186,14 @@ ObjectMediator.prototype.moveTaskShapesAt = function(num)

for (var i = num; i < tasks.length; i++) {
this.moveRaphaelSets(tasks[i].parent, v.rectP.w + v.taskMargin.w );
if (0 < tasks[i].childs.length){
var childs = tasks[i].childs;
log(1);
for (var z = 0; z < childs.length; z++) {
log(2);
this.moveRaphaelSets(childs[z], v.rectP.w + v.taskMargin.w );
}
}
}
}

Expand All @@ -196,3 +214,10 @@ ObjectMediator.prototype.showEditBox = function(task, shapes) {
$('#editbox').dialog( { draggable: true });

}
ObjectMediator.prototype.orderOfParentTask = function(task) {
for (var i=0;i < this.objects.tasks.length; i++) {
if (this.objects.tasks[i] === task){
return i;
}
}
}
2 changes: 1 addition & 1 deletion views/index.ejs
Expand Up @@ -33,7 +33,7 @@ var v = {'paper' :{'w':1000, 'h':250,'margin':{'w':30,'h':10}},
'attr':{"stroke":"orange", "stroke-width":1, "gradient":'100-#FFCD35-#FFD659'}},
'rectMOn' :{'attr':{"stroke":"crimson" , "scale":1.5}},
'font_m' :{'padding_rect':{x:10,y:20},
'attr':{'text-anchor': 'start',"fill":"#333333",'font-size':17, 'font-family':''}},
'attr':{'text-anchor': 'start',"fill":"#333333",'font-size':14, 'font-family':''}},
'icon' :{"w":20,"h":20, "margin":20},
'taskMargin':{w:30,child:{w:10,h:10}},
'taskR' :10};
Expand Down

0 comments on commit 78d9fd7

Please sign in to comment.