da15cbe16404f797695df790ef305fe32e825054
[xynt.git] / xynt-link.js
1 function tasks_link(o, anc, a, b, type) {
2     var cur;
3     this.o = o;
4     this.anc = anc;
5     this.beg = document.createElement("div");
6     this.end = document.createElement("div");
7     this.arr = document.createElement("img");
8     this.arr.style.position = "absolute";
9     o.appendChild(this.arr);
10     for (var i = 0 ; i < 2 ; i++) {
11         cur = i == 0 ? this.beg : this.end;
12         cur.style.width = '5px';
13         cur.style.height = '5px';
14         cur.style.backgroundColor = 'gray';
15         cur.style.visibility = 'inherit';
16         cur.style.zIndex = 20;
17         cur.style.position = 'absolute';
18         o.appendChild(cur);
19         // alert("gugu");
20     }
21     
22     this.a = a;
23     this.b = b;
24     this.type = type;
25
26     if (typeof(a.connected) != 'object')
27         return null;
28
29     if (typeof(b.connected) != 'object')
30         return null;
31
32     for (var i = 0 ; i < 2 ; i++) {
33         cur = (i == 0 ? a : b);
34         cur.connected[cur.connected.length++] = this;
35         for( ; cur.parentNode != null && cur.parentNode != anc ; cur = cur.parentNode) {
36             cur.parentNode.connected[cur.parentNode.connected.length++] = this;
37         }
38     }
39     this.update()
40 }
41
42 tasks_link.prototype = {
43     a: null,
44     b: null,
45     type: null,
46
47     update: function(method, obj)
48     {
49         /*
50         if (method == 'end') {
51             if (this.o.style.visibility == 'visible')
52                 this.o.style.visibility = 'hidden';
53             else
54                 this.o.style.visibility = 'visible';
55         }
56         */
57         
58         // FIXME you need to user the width of the border instead of +2
59         this.beg.style.left = (parseInt(this.a.style.left) + parseInt(this.a.style.width) + 2 + parseInt(this.a.parentNode.style.left))+"px";
60         this.beg.style.top  = (parseInt(this.a.style.top)  + parseInt(((parseInt(this.a.style.height) + 2) / 2)) + parseInt(this.a.parentNode.style.top))+"px";
61         this.beg.style.width = (parseInt(this.b.style.left) - (parseInt(this.a.style.left) + 2 + parseInt(this.b.style.width) + 2)+ parseInt(this.b.parentNode.style.left) + 5)+"px";
62         this.beg.style.height = "1px";
63
64         this.end.style.left = (parseInt(this.beg.style.left) + parseInt(this.beg.style.width))+"px";
65         this.arr.style.left = (parseInt(this.end.style.left) - 3)+"px";
66         /* this.end.style.left = (parseInt(this.b.style.left) + parseInt(this.b.parentNode.style.left))+"px";
67            this.end.style.top  = (parseInt(this.b.style.top)  + parseInt(this.b.parentNode.style.top))+"px"; */
68         endpty = parseInt(this.b.style.top)  + parseInt(this.b.parentNode.style.top)+10;
69         this.end.style.width  = "1px";
70         
71         if (parseInt(this.beg.style.top) < endpty) {
72             this.end.style.top  = this.beg.style.top;
73             this.end.style.height = (parseInt(this.b.style.top)  + parseInt(this.b.parentNode.style.top) - ((parseInt(this.a.style.top)  + parseInt(this.a.parentNode.style.top))) ) - 11 +"px";
74             this.arr.style.top = (parseInt(this.end.style.top) + parseInt(this.end.style.height) - 5)+"px";
75             this.arr.src = "img/arrow_do.png";
76         }
77         else {
78             this.end.style.top  = (parseInt(this.b.style.top)  + parseInt(this.b.parentNode.style.top) + 23)+"px";
79             this.end.style.height = (parseInt(this.a.style.top)  + parseInt(this.a.parentNode.style.top) - ((parseInt(this.b.style.top)  + parseInt(this.b.parentNode.style.top))) ) - 11 +"px";
80
81             this.arr.style.top = this.end.style.top;
82             this.arr.src = "img/arrow_up.png";
83         }
84
85
86         this.o.style.visibility = "visible";
87         
88         console.log("met: " + method + " obj: " + (obj == this.a ? "Obj A" : (obj == this.b ? "Obj B" : "Other")) );
89     }
90 }