Merge branch 'master' of ssh://phpmyadmin.git.sourceforge.net/gitroot/phpmyadmin...
[phpmyadmin/dkf.git] / pmd / scripts / move.js
blobf07d806398ebf11a14bdb93c5ed18f68e677b9a7
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3 * @package phpMyAdmin-Designer
4 */
6 /**
7 * init
8 */
9 var dx, dy, dy2;
10 var cur_click;
11 // update in Main()
12 var sm_x = 2, sm_y = 2;
13 var sm_s = 0;
14 var sm_add = 10;
15 var s_left = 0;
16 var s_right = 0;
17 var ON_relation = 0;
18 var ON_grid = 0;
19 var ON_display_field = 0;
20 // relation_style: 0 - angular 1 - direct
21 var ON_angular_direct = 1;
22 var click_field = 0;
23 var link_relation = "";
24 var id_hint;
25 var canvas_width = 0;
26 var canvas_height = 0;
27 var osn_tab_width = 0;
28 var osn_tab_height = 0;
29 var height_field = 7;
30 var Glob_X, Glob_Y;
31 var timeoutID;
32 var layer_menu_cur_click = 0;
33 var step = 10;
34 var old_class;
36 //------------------------------------------------------------------------------
37 //------------------------------------------------------------------------------
38 //------------------------------------------------------------------------------
41 //window.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP);
42 //---CROSS
43 document.onmousedown = MouseDown;
44 document.onmouseup = MouseUp;
45 document.onmousemove = MouseMove;
47 var isIE = document.all && !window.opera;
48 var isNN = !document.all && document.getElementById;
49 var isN4 = document.layers;
51 if (isIE) {
52 window.onscroll = General_scroll;
53 document.onselectstart = function () {return false;};
56 //document.onmouseup = function(){General_scroll_end();}
57 function MouseDown(e)
59 var offsetx, offsety;
60 if (cur_click != null) {
61 offsetx = isIE ? event.clientX + document.body.scrollLeft : e.pageX;
62 offsety = isIE ? event.clientY + document.body.scrollTop : e.pageY;
63 dx = offsetx - parseInt(cur_click.style.left);
64 dy = offsety - parseInt(cur_click.style.top);
65 //alert(" dx = " + dx + " dy = " +dy);
66 document.getElementById("canvas").style.visibility = 'hidden';
68 var left = parseInt(cur_click.style.left);
69 var top = parseInt(cur_click.style.top);
70 dx = e.pageX - left;
71 dy = e.pageY - top;
73 alert(" dx = " + dx + " dy = " +dy);
75 cur_click.style.zIndex = 2;
77 if (layer_menu_cur_click) {
78 offsetx = isIE ? event.clientX + document.body.scrollLeft : e.pageX;
79 dx = offsetx - parseInt(document.getElementById("layer_menu").style.width);
83 function MouseMove(e)
85 //Glob_X = e.pageX;
86 //Glob_Y = e.pageY;
87 Glob_X = isIE ? event.clientX + document.body.scrollLeft : e.pageX;
88 Glob_Y = isIE ? event.clientY + document.body.scrollTop : e.pageY;
90 //mouseX = (bw.ns4||bw.ns6)? e.pageX: bw.ie&&bw.win&&!bw.ie4? (event.clientX-2)+document.body.scrollLeft : event.clientX+document.body.scrollLeft;
91 //mouseY = (bw.ns4||bw.ns6)? e.pageY: bw.ie&&bw.win&&!bw.ie4? (event.clientY-2)+document.body.scrollTop : event.clientY+document.body.scrollTop;
93 //window.status = "X = "+ Glob_X + " Y = "+ Glob_Y;
95 if (cur_click != null) {
96 var mGx = Glob_X - dx;
97 var mGy = Glob_Y - dy;
98 mGx = mGx > 0 ? mGx : 0;
99 mGy = mGy > 0 ? mGy : 0;
101 if (ON_grid) {
102 mGx = mGx % step < step / 2 ? mGx - mGx % step : mGx - mGx % step + step;
103 mGy = mGy % step < step / 2 ? mGy - mGy % step : mGy - mGy % step + step;
106 cur_click.style.left = mGx + 'px';
107 cur_click.style.top = mGy + 'px';
110 if (ON_relation || ON_display_field) {
111 document.getElementById('hint').style.left = (Glob_X + 20) + 'px';
112 document.getElementById('hint').style.top = (Glob_Y + 20) + 'px';
115 if (layer_menu_cur_click) {
116 document.getElementById("layer_menu").style.width = ((Glob_X - dx) >= 150 ? Glob_X - dx : 150) + 'px';
117 //document.getElementById("layer_menu").style.height = Glob_Y - dy>=200?Glob_Y - dy:200;
118 //document.getElementById("id_scroll_tab").style.height = Glob_Y - dy2;
122 function MouseUp(e)
124 if (cur_click != null) {
125 document.getElementById("canvas").style.visibility = 'visible';
126 Re_load();
127 cur_click.style.zIndex = 1;
128 cur_click = null;
130 layer_menu_cur_click = 0;
131 //window.releaseEvents(Event.MOUSEMOVE);
133 //------------------------------------------------------------------------------
134 //------------------------------------------------------------------------------
135 //------------------------------------------------------------------------------
138 //function ToInt(s)
140 // return s.substring(0,s.length-2)*1; //re = /(\d+)\w*/; newstr = str.replace(re, "$1");
143 function Canvas_pos()
145 canvas_width = document.getElementById('canvas').width = osn_tab_width - 3;
146 canvas_height = document.getElementById('canvas').height = osn_tab_height - 3;
148 if (isIE) {
149 document.getElementById('canvas').style.width = ((osn_tab_width - 3)?(osn_tab_width - 3):0) + 'px';
150 document.getElementById('canvas').style.height = ((osn_tab_height - 3)?(osn_tab_height - 3):0) + 'px';
154 function Osn_tab_pos()
156 osn_tab_width = parseInt(document.getElementById('osn_tab').style.width);
157 osn_tab_height = parseInt(document.getElementById('osn_tab').style.height);
161 function Main()
163 //alert( document.getElementById('osn_tab').offsetTop);
164 //---CROSS
165 if (isIE) {
166 document.getElementById('top_menu').style.position = 'absolute';
167 document.getElementById('layer_menu').style.position = 'absolute';
170 document.getElementById("layer_menu").style.top = -1000 + 'px'; //fast scroll
171 sm_x += document.getElementById('osn_tab').offsetLeft;
172 sm_y += document.getElementById('osn_tab').offsetTop;
173 Osn_tab_pos();
174 Canvas_pos();
175 Small_tab_refresh();
176 Re_load();
177 id_hint = document.getElementById('hint');
178 if (isIE) {
179 General_scroll();
184 //-------------------------------- new -----------------------------------------
185 function Rezize_osn_tab()
187 var max_X = 0;
188 var max_Y = 0;
189 for (key in j_tabs) {
190 var k_x = parseInt(document.getElementById(key).style.left) + document.getElementById(key).offsetWidth;
191 var k_y = parseInt(document.getElementById(key).style.top) + document.getElementById(key).offsetHeight;
192 max_X = max_X < k_x ? k_x : max_X;
193 max_Y = max_Y < k_y ? k_y : max_Y;
196 osn_tab_width = max_X + 50;
197 osn_tab_height = max_Y + 50;
198 Canvas_pos();
199 document.getElementById('osn_tab').style.width = osn_tab_width + 'px';
200 document.getElementById('osn_tab').style.height = osn_tab_height + 'px';
202 //------------------------------------------------------------------------------
205 * refreshes display, must be called after state changes
207 function Re_load()
209 Rezize_osn_tab();
210 var n;
211 var x1;
212 var x2;
213 var a = new Array();
214 Clear();
215 for (K in contr)
216 for (key in contr[K]) // contr name
217 for (key2 in contr[K][key]) // table name
218 for (key3 in contr[K][key][key2]) // field name
220 if (!document.getElementById("check_vis_" + key2).checked ||
221 !document.getElementById("check_vis_" + contr[K][key][key2][key3][0]).checked) {
222 // if hide
223 continue;
225 var x1_left = document.getElementById(key2).offsetLeft+1;
226 var x1_right = x1_left + document.getElementById(key2).offsetWidth;
227 var x2_left = document.getElementById(contr[K][key][key2][key3][0]).offsetLeft;
228 var x2_right = x2_left + document.getElementById(contr[K][key][key2][key3][0]).offsetWidth;
229 a[0] = Math.abs(x1_left - x2_left);
230 a[1] = Math.abs(x1_left - x2_right);
231 a[2] = Math.abs(x1_right - x2_left);
232 a[3] = Math.abs(x1_right - x2_right);
233 n = s_left = s_right = 0;
234 for (var i = 1; i < 4; i++) {
235 if (a[n] > a[i]) {
236 n = i;
239 if (n == 1) {
240 x1 = x1_left - sm_s;
241 x2 = x2_right + sm_s;
242 if (x1 < x2) {
243 n = 0;
246 if (n == 2) {
247 x1 = x1_right + sm_s;
248 x2 = x2_left - sm_s;
249 if (x1 > x2) {
250 n = 0;
253 if (n == 3) {
254 x1 = x1_right + sm_s;
255 x2 = x2_right + sm_s;
256 s_right = 1;
258 if (n == 0) {
259 x1 = x1_left - sm_s;
260 x2 = x2_left - sm_s;
261 s_left = 1;
263 //alert(key2 + "." + key3);
265 var row_offset_top = 0;
266 //alert('id_tbody_' + key2);
267 //alert(document.getElementById('id_hide_tbody_' + key2));
268 var tab_hide_button = document.getElementById('id_hide_tbody_' + key2);
270 //alert(tab_hide_button.innerHTML);
271 if (tab_hide_button.innerHTML == 'v') {
272 row_offset_top = document.getElementById(key2 + "." + key3).offsetTop;
275 var y1 = document.getElementById(key2).offsetTop
276 + row_offset_top
277 + height_field;
278 //alert(1);
280 row_offset_top = 0;
281 var tab_hide_button = document.getElementById('id_hide_tbody_' + contr[K][key][key2][key3][0]);
282 if (tab_hide_button.innerHTML == 'v') {
283 row_offset_top = document.getElementById(contr[K][key][key2][key3][0]
284 + '.' + contr[K][key][key2][key3][1]).offsetTop;
287 var y2 =
288 document.getElementById(contr[K][key][key2][key3][0]).offsetTop
289 + row_offset_top
290 + height_field;
292 //alert(y1 + ' - ' + key2 + "." + key3);
293 Line0(x1 - sm_x, y1 - sm_y, x2 - sm_x, y2 - sm_y, getColorByTarget( contr[K][key][key2][key3][0]+'.'+contr[K][key][key2][key3][1] ) );
298 * draws a line from x1:y1 to x2:y2 with color
300 function Line(x1, y1, x2, y2, color_line)
302 var canvas = document.getElementById("canvas");
303 var ctx = canvas.getContext("2d");
304 ctx.strokeStyle = color_line;
305 ctx.lineWidth = 1;
306 ctx.beginPath();
307 ctx.moveTo(x1, y1);
308 ctx.lineTo(x2, y2);
309 ctx.stroke();
313 * draws a relation/constraint line, whether angular or not
315 function Line0(x1, y1, x2, y2, color_line)
317 Circle(x1, y1, 3, 3, color_line);
318 Rect(x2 - 1, y2 - 2, 4, 4, color_line);
320 if (ON_angular_direct) {
321 Line2(x1, y1, x2, y2, color_line);
322 } else {
323 Line3(x1, y1, x2, y2, color_line);
328 * draws a angualr relation/constraint line
330 function Line2(x1, y1, x2, y2, color_line)
332 var x1_ = x1;
333 var x2_ = x2;
335 if (s_right) {
336 x1_ += sm_add;
337 x2_ += sm_add;
338 } else if (s_left) {
339 x1_ -= sm_add;
340 x2_ -= sm_add;
341 } else if (x1 < x2) {
342 x1_ += sm_add;
343 x2_ -= sm_add;
344 } else {
345 x1_ -= sm_add;
346 x2_ += sm_add;
349 Line(x1, y1, x1_, y1, color_line);
350 Line(x2, y2, x2_, y2, color_line);
351 Line(x1_, y1, x2_, y2, color_line);
355 * draws a relation/constraint line
357 function Line3(x1, y1, x2, y2, color_line)
359 var x1_ = x1;
360 var x2_ = x2;
362 if (s_right) {
363 if (x1 < x2) {
364 x1_ += x2 - x1 + sm_add;
365 x2_ += sm_add;
366 } else {
367 x2_ += x1 - x2 + sm_add;
368 x1_ += sm_add;
371 Line(x1, y1, x1_, y1, color_line);
372 Line(x2, y2, x2_, y2, color_line);
373 Line(x1_, y1, x2_, y2, color_line);
374 return;
376 if (s_left) {
377 if (x1 < x2) {
378 x2_ -= x2 - x1 + sm_add;
379 x1_ -= sm_add;
380 } else {
381 x1_ -= x1 - x2 + sm_add;
382 x2_ -= sm_add;
385 Line(x1, y1, x1_, y1, color_line);
386 Line(x2, y2, x2_, y2, color_line);
387 Line(x1_, y1, x2_, y2, color_line);
388 return;
391 var x_s = (x1 + x2) / 2;
392 Line(x1, y1, x_s, y1, color_line);
393 Line(x_s, y2, x2, y2, color_line);
394 Line(x_s, y1, x_s, y2, color_line);
397 function Circle(x, y, r, w, color)
399 var ctx = document.getElementById('canvas').getContext('2d');
400 ctx.beginPath();
401 ctx.moveTo(x, y);
402 ctx.lineWidth = w;
403 ctx.strokeStyle = color;
404 ctx.arc(x, y, r, 0, 2 * Math.PI, true);
405 ctx.stroke();
408 function Clear()
410 var canvas = document.getElementById("canvas");
411 var ctx = canvas.getContext("2d");
412 ctx.clearRect(0, 0, canvas_width, canvas_height);
415 function Rect(x1, y1, w, h, color)
417 var ctx = document.getElementById('canvas').getContext('2d');
418 ctx.fillStyle = color;
419 ctx.fillRect(x1, y1, w, h);
422 //------------------------------ SAVE ------------------------------------------
423 function Save(url) // (del?) no for pdf
425 for (key in j_tabs) {
426 document.getElementById('t_x_' + key + '_').value = parseInt(document.getElementById(key).style.left);
427 document.getElementById('t_y_' + key + '_').value = parseInt(document.getElementById(key).style.top);
428 document.getElementById('t_v_' + key + '_').value = document.getElementById('id_tbody_' + key).style.display == 'none' ? 0 : 1;
429 document.getElementById('t_h_' + key + '_').value = document.getElementById('check_vis_' + key).checked ? 1 : 0;
431 document.form1.action = url;
432 document.form1.submit();
435 function Get_url_pos()
437 var poststr = '';
438 for (key in j_tabs) {
439 poststr += '&t_x[' + key + ']=' + parseInt(document.getElementById(key).style.left);
440 poststr += '&t_y[' + key + ']=' + parseInt(document.getElementById(key).style.top);
441 poststr += '&t_v[' + key + ']=' + (document.getElementById('id_tbody_' + key).style.display == 'none' ? 0 : 1);
442 poststr += '&t_h[' + key + ']=' + (document.getElementById('check_vis_' + key).checked ? 1 : 0);
444 return poststr;
447 function Save2()
449 var poststr = 'IS_AJAX=1&server='+server+'&db=' + db + '&token=' + token + '&die_save_pos=1';
450 poststr += Get_url_pos();
451 makeRequest('pmd_save_pos.php', poststr);
454 function Grid()
456 if (!ON_grid) {
457 ON_grid = 1;
458 document.getElementById('grid_button').className = 'M_butt_Selected_down';
459 } else {
460 document.getElementById('grid_button').className = 'M_butt';
461 ON_grid = 0;
465 function Angular_direct()
467 if (ON_angular_direct) {
468 ON_angular_direct = 0;
469 document.getElementById('angular_direct_button').className = 'M_butt_Selected_down';
470 } else {
471 ON_angular_direct = 1;
472 document.getElementById('angular_direct_button').className = 'M_butt';
474 Re_load();
476 //++++++++++++++++++++++++++++++ RELATION ++++++++++++++++++++++++++++++++++++++
477 function Start_relation()
479 if (ON_display_field) {
480 return;
483 if (!ON_relation) {
484 document.getElementById('foreign_relation').style.display = '';
485 ON_relation = 1;
486 document.getElementById('hint').innerHTML = PMA_messages['strSelectReferencedKey'];
487 document.getElementById('hint').style.visibility = "visible";
488 document.getElementById('rel_button').className = 'M_butt_Selected_down';
489 } else {
490 document.getElementById('hint').innerHTML = "";
491 document.getElementById('hint').style.visibility = "hidden";
492 document.getElementById('rel_button').className = 'M_butt';
493 click_field = 0;
494 ON_relation = 0;
498 function Click_field(T, f, PK) // table field
500 if (ON_relation) {
501 if (!click_field) {
502 //.style.display=='none' .style.visibility = "hidden"
503 if (!PK) {
504 alert(PMA_messages['strPleaseSelectPrimaryOrUniqueKey']);
505 return;// 0;
506 }//PK
507 if (j_tabs[db + '.' + T] != '1') {
508 document.getElementById('foreign_relation').style.display = 'none';
510 click_field = 1;
511 link_relation = "T1=" + T + "&F1=" + f;
512 document.getElementById('hint').innerHTML = PMA_messages['strSelectForeignKey'];
513 } else {
514 Start_relation(); // hidden hint...
515 if (j_tabs[db + '.' + T] != '1' || !PK) {
516 document.getElementById('foreign_relation').style.display = 'none';
518 var left = Glob_X - (document.getElementById('layer_new_relation').offsetWidth>>1);
519 document.getElementById('layer_new_relation').style.left = left + 'px';
520 var top = Glob_Y - document.getElementById('layer_new_relation').offsetHeight - 10;
521 document.getElementById('layer_new_relation').style.top = top + 'px';
522 document.getElementById('layer_new_relation').style.visibility = "visible";
523 link_relation += '&T2=' + T + '&F2=' + f;
527 if (ON_display_field) {
528 // if is display field
529 if (display_field[T] == f) {
530 //alert(T);
531 //s = '';for(k in display_field)s += k + ' = ' + display_field[k] + ',';alert(s);
532 old_class = 'tab_field';
533 //display_field.splice(T, 1);
534 delete display_field[T];
535 //s = '';for(k in display_field)s += k + ' = ' + display_field[k] + ', ';alert(s);
536 //n = 0;for(k in display_field)n++;alert(n);
537 } else {
538 old_class = 'tab_field_3';
539 if (display_field[T]) {
540 document.getElementById('id_tr_' + T + '.' + display_field[T]).className = 'tab_field';
541 //display_field.splice(T, 1);
542 delete display_field[T];
544 display_field[T] = f;
546 ON_display_field = 0;
547 document.getElementById('hint').innerHTML = "";
548 document.getElementById('hint').style.visibility = "hidden";
549 document.getElementById('display_field_button').className = 'M_butt';
550 makeRequest('pmd_display_field.php', 'T=' + T + '&F=' + f + '&server=' + server + '&db=' + db + '&token=' + token);
554 function New_relation()
556 document.getElementById('layer_new_relation').style.visibility = 'hidden';
557 link_relation += '&server=' + server + '&db=' + db + '&token=' + token + '&die_save_pos=0';
558 link_relation += '&on_delete=' + document.getElementById('on_delete').value + '&on_update=' + document.getElementById('on_update').value;
559 link_relation += Get_url_pos();
561 //alert(link_relation);
562 makeRequest('pmd_relation_new.php', link_relation);
565 //-------------------------- create tables -------------------------------------
567 function Start_table_new()
569 window.location.href = 'db_operations.php?server=' + server + '&db=' + db + '&token=' + token;
572 function Start_tab_upd(table)
574 window.location.href = 'tbl_structure.php?server=' + server + '&db=' + db + '&token=' + token + '&table=' + table;
576 //--------------------------- hide tables --------------------------------------
578 function Small_tab_all(id_this) // max/min all tables
580 if (id_this.alt == "v") {
581 for (key in j_tabs) {
582 if (document.getElementById('id_hide_tbody_'+key).innerHTML == "v") {
583 Small_tab(key, 0);
586 id_this.alt = ">";
587 id_this.src = "pmd/images/rightarrow1.png";
588 } else {
589 for (key in j_tabs) {
590 if (document.getElementById('id_hide_tbody_'+key).innerHTML != "v") {
591 Small_tab(key, 0);
594 id_this.alt = "v";
595 id_this.src = "pmd/images/downarrow1.png";
597 Re_load();
600 function Small_tab_invert() // invert max/min all tables
602 for (key in j_tabs) {
603 Small_tab(key, 0);
605 Re_load();
608 function Small_tab_refresh()
610 for (key in j_tabs) {
611 if(document.getElementById('id_hide_tbody_'+key).innerHTML != "v") {
612 Small_tab(key, 0);
613 Small_tab(key, 0);
618 function Small_tab(t, re_load)
620 var id = document.getElementById('id_tbody_' + t);
621 var id_this = document.getElementById('id_hide_tbody_' + t);
622 var id_t = document.getElementById(t);
624 id_t.style.width = id_t.offsetWidth + 'px';
625 if (id_this.innerHTML == "v") {
626 //---CROSS
627 id.style.display = 'none';
628 id_this.innerHTML = '>';
629 } else {
630 id.style.display = '';
631 id_this.innerHTML = 'v';
633 if (re_load) {
634 Re_load();
637 //------------------------------------------------------------------------------
638 function Select_tab(t)
640 var id_zag = document.getElementById('id_zag_' + t);
641 if (id_zag.className != 'tab_zag_3') {
642 document.getElementById('id_zag_' + t).className = 'tab_zag_2';
643 } else {
644 document.getElementById('id_zag_' + t).className = 'tab_zag';
646 //----------
647 var id_t = document.getElementById(t);
648 window.scrollTo(parseInt(id_t.style.left) - 300, parseInt(id_t.style.top) - 300);
650 setTimeout(function(){document.getElementById('id_zag_' + t).className = 'tab_zag';}, 800);
652 //------------------------------------------------------------------------------
654 function Canvas_click(id)
656 var n = 0;
657 var relation_name = 0;
658 var selected = 0;
659 var a = new Array();
660 var Key0, Key1, Key2, Key3, Key, x1, x2;
661 Clear();
662 for (K in contr)
663 for (key in contr[K])
664 for (key2 in contr[K][key])
665 for (key3 in contr[K][key][key2]) {
666 if (!document.getElementById("check_vis_"+key2).checked ||
667 !document.getElementById("check_vis_"+contr[K][key][key2][key3][0]).checked) continue; // if hide
668 var x1_left = document.getElementById(key2).offsetLeft + 1;//document.getElementById(key2+"."+key3).offsetLeft;
669 var x1_right = x1_left + document.getElementById(key2).offsetWidth;
670 var x2_left = document.getElementById(contr[K][key][key2][key3][0]).offsetLeft;//+document.getElementById(contr[K][key2][key3][0]+"."+contr[K][key2][key3][1]).offsetLeft
671 var x2_right = x2_left + document.getElementById(contr[K][key][key2][key3][0]).offsetWidth;
672 a[0] = Math.abs(x1_left - x2_left);
673 a[1] = Math.abs(x1_left - x2_right);
674 a[2] = Math.abs(x1_right - x2_left);
675 a[3] = Math.abs(x1_right - x2_right);
676 n = s_left = s_right = 0;
677 for (var i = 1; i < 4; i++) {
678 if (a[n] > a[i]) {
679 n = i;
682 if (n == 1) {
683 x1 = x1_left - sm_s;
684 x2 = x2_right + sm_s;
685 if (x1 < x2) {
686 n = 0;
689 if (n == 2) {
690 x1 = x1_right + sm_s;
691 x2 = x2_left - sm_s;
692 if (x1 > x2) {
693 n = 0;
696 if (n == 3) {
697 x1 = x1_right + sm_s;
698 x2 = x2_right + sm_s;
699 s_right = 1;
701 if (n == 0) {
702 x1 = x1_left - sm_s;
703 x2 = x2_left - sm_s;
704 s_left = 1;
707 var y1 = document.getElementById(key2).offsetTop + document.getElementById(key2+"."+key3).offsetTop + height_field;
708 var y2 = document.getElementById(contr[K][key][key2][key3][0]).offsetTop +
709 document.getElementById(contr[K][key][key2][key3][0]+"."+contr[K][key][key2][key3][1]).offsetTop + height_field;
710 if (!selected && Glob_X > x1 - 10 && Glob_X < x1 + 10 && Glob_Y > y1 - 7 && Glob_Y < y1 + 7) {
711 Line0(x1 - sm_x, y1 - sm_y, x2 - sm_x, y2 - sm_y, "rgba(255,0,0,1)");
712 selected = 1; // Rect(x1-sm_x,y1-sm_y,10,10,"rgba(0,255,0,1)");
713 relation_name = key; //
714 Key0 = contr[K][key][key2][key3][0];
715 Key1 = contr[K][key][key2][key3][1];
716 Key2 = key2; Key3 = key3;
717 Key = K;
718 } else {
719 Line0(x1 - sm_x, y1 - sm_y, x2 - sm_x, y2 - sm_y, getColorByTarget( contr[K][key][key2][key3][0]+'.'+contr[K][key][key2][key3][1] ));
722 if (selected) {
723 // select relations
724 //alert(Key0+' - '+Key1+' - '+Key2+' - '+Key3);
725 var left = Glob_X - (document.getElementById('layer_upd_relation').offsetWidth>>1);
726 document.getElementById('layer_upd_relation').style.left = left + 'px';
727 var top = Glob_Y - document.getElementById('layer_upd_relation').offsetHeight - 10;
728 document.getElementById('layer_upd_relation').style.top = top + 'px';
729 document.getElementById('layer_upd_relation').style.visibility = 'visible';
730 link_relation = 'T1=' + Key0 + '&F1=' + Key1 + '&T2=' + Key2 + '&F2=' + Key3 + '&K=' + Key;
734 function Upd_relation()
736 document.getElementById('layer_upd_relation').style.visibility = 'hidden';
737 link_relation += '&server=' + server + '&db=' + db + '&token=' + token + '&die_save_pos=0';
738 link_relation += Get_url_pos();
739 makeRequest('pmd_relation_upd.php', link_relation);
742 function VisibleTab(id, t_n)
744 if (id.checked) {
745 document.getElementById(t_n).style.visibility = 'visible';
746 } else {
747 document.getElementById(t_n).style.visibility = 'hidden';
749 Re_load();
752 function Hide_tab_all(id_this) // max/min all tables
754 if (id_this.alt == 'v') {
755 id_this.alt = '>';
756 id_this.src = "pmd/images/rightarrow1.png";
757 } else {
758 id_this.alt = 'v';
759 id_this.src = "pmd/images/downarrow1.png";
761 var E = document.form1;
762 for (i = 0; i < E.elements.length; i++) {
763 if (E.elements[i].type == "checkbox" && E.elements[i].id.substring(0, 10) == 'check_vis_') {
764 if (id_this.alt == 'v') {
765 E.elements[i].checked = true;
766 document.getElementById(E.elements[i].value).style.visibility = 'visible';
767 } else {
768 E.elements[i].checked = false;
769 document.getElementById(E.elements[i].value).style.visibility = 'hidden';
773 Re_load();
776 function in_array_k(x, m)
778 var b = 0;
779 for (u in m) {
780 if (x == u) {
781 b=1;
782 break;
785 return b;
788 function No_have_constr(id_this)
790 var a = new Array();
791 for (K in contr)
792 for (key in contr[K]) // contr name
793 for (key2 in contr[K][key]) // table name
794 for (key3 in contr[K][key][key2]) // field name
795 a[key2] = a[contr[K][key][key2][key3][0]] = 1; // exist constr
798 if (id_this.alt == 'v') {
799 id_this.alt = '>';
800 id_this.src = "pmd/images/rightarrow2.png";
801 } else {
802 id_this.alt = 'v';
803 id_this.src = "pmd/images/downarrow2.png";
805 var E = document.form1;
806 for (i = 0; i < E.elements.length; i++) {
807 if (E.elements[i].type == "checkbox" && E.elements[i].id.substring(0, 10) == 'check_vis_')
809 if (!in_array_k(E.elements[i].value, a))
810 if (id_this.alt == 'v') {
811 E.elements[i].checked = true;
812 document.getElementById(E.elements[i].value).style.visibility = 'visible';
813 } else {
814 E.elements[i].checked = false;
815 document.getElementById(E.elements[i].value).style.visibility = 'hidden';
821 function Help()
823 var WinHelp = window.open("pmd_help.php", "wind1", "top=200,left=400,width=300,height=200,resizable=yes,scrollbars=yes,menubar=no");
826 function PDF_save()
828 // var WinPDF =
829 // window.open("pmd_pdf.php?token="+token+"&db="+db,"wind1", "top=200,left=200,width=200,height=100,resizable=yes,scrollbars=yes,menubar=no");
830 Save('pmd_pdf.php?server=' + server + '&token=' + token + '&db=' + db);
833 function General_scroll()
836 if (!document.getElementById('show_relation_olways').checked) {
837 document.getElementById("canvas").style.visibility = 'hidden';
838 clearTimeout(timeoutID);
839 timeoutID = setTimeout(General_scroll_end, 500);
842 //if (timeoutID)
843 clearTimeout(timeoutID);
844 timeoutID = setTimeout
846 function()
848 document.getElementById('top_menu').style.left = document.body.scrollLeft + 'px';
849 document.getElementById('top_menu').style.top = document.body.scrollTop + 'px';
850 document.getElementById('layer_menu').style.left = document.body.scrollLeft + 'px';
851 document.getElementById('layer_menu').style.top = (document.body.scrollTop + document.getElementById('top_menu').offsetHeight) + 'px';
853 ,200
858 function General_scroll_end()
860 document.getElementById('layer_menu').style.left = document.body.scrollLeft;
861 document.getElementById('layer_menu').style.top = document.body.scrollTop + document.getElementById('top_menu').offsetHeight;
862 if (isIE) {
863 document.getElementById('layer_menu').style.left = document.body.scrollLeft;
864 document.getElementById('layer_menu').style.top = document.body.scrollTop + document.getElementById('top_menu').offsetHeight;
866 document.getElementById("canvas").style.visibility = 'visible';
870 function Show_left_menu(id_this) // max/min all tables
872 if (id_this.alt == "v") {
873 document.getElementById("layer_menu").style.top = document.getElementById('top_menu').offsetHeight + 'px';
874 document.getElementById("layer_menu").style.visibility = 'visible';
875 id_this.alt = ">";
876 id_this.src = "pmd/images/uparrow2_m.png";
877 if (isIE) {
878 General_scroll();
880 } else {
881 document.getElementById("layer_menu").style.top = -1000 + 'px'; //fast scroll
882 document.getElementById("layer_menu").style.visibility = 'hidden';
883 id_this.alt = "v";
884 id_this.src = "pmd/images/downarrow2_m.png";
887 //------------------------------------------------------------------------------
888 function Top_menu_right(id_this)
890 if (id_this.alt == ">") {
891 document.getElementById('top_menu').style.marginLeft = document.getElementById('top_menu').offsetWidth + 'px'; // = 350
892 id_this.alt = "<";
893 id_this.src = "pmd/images/2leftarrow_m.png";
894 } else {
895 document.getElementById('top_menu').style.marginLeft = 0;
896 id_this.alt = ">";
897 id_this.src = "pmd/images/2rightarrow_m.png";
900 //------------------------------------------------------------------------------
901 function Start_display_field()
903 if (ON_relation) {
904 return;
906 if (!ON_display_field) {
907 ON_display_field = 1;
908 document.getElementById('hint').innerHTML = PMA_messages['strChangeDisplay'];
909 document.getElementById('hint').style.visibility = "visible";
910 document.getElementById('display_field_button').className = 'M_butt_Selected_down';//'#FFEE99';gray #AAAAAA
912 if (isIE) { // correct for IE
913 document.getElementById('display_field_button').className = 'M_butt_Selected_down_IE';
915 } else {
916 document.getElementById('hint').innerHTML = "";
917 document.getElementById('hint').style.visibility = "hidden";
918 document.getElementById('display_field_button').className = 'M_butt';
919 ON_display_field = 0;
922 //------------------------------------------------------------------------------
923 var TargetColors = new Array();
924 function getColorByTarget( target )
926 var color = ''; //"rgba(0,100,150,1)";
928 for (i in TargetColors)
929 if (TargetColors[i][0]==target) {
930 color = TargetColors[i][1];
931 break;
935 if (color.length==0)
937 var i = TargetColors.length+1;
938 var d = i % 6;
939 var j = (i - d) / 6;
940 j = j % 4;
941 j++;
942 var color_case = new Array(
943 new Array(1, 0, 0),
944 new Array(0, 1, 0),
945 new Array(0, 0, 1),
946 new Array(1, 1, 0),
947 new Array(1, 0, 1),
948 new Array(0, 1, 1)
950 var a = color_case[d][0];
951 var b = color_case[d][1];
952 var c = color_case[d][2];
953 e = (1 - (j - 1) / 6);
955 var r = Math.round(a * 200 * e);
956 var g = Math.round(b * 200 * e);
957 var b = Math.round(c * 200 * e);
958 var color = "rgba("+r+","+g+","+b+",1)";
960 TargetColors.push( new Array(target, color) );
965 return color;