history tab changes
[phpmyadmin/ankitg.git] / pmd / scripts / move.js
blobff0acb806f62022c293ebe8e52159284734c9c87
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3 * @version $Id$
4 * @package phpMyAdmin-Designer
5 */
7 /**
8 * init
9 */
10 var dx, dy, dy2;
11 var cur_click;
12 // update in Main()
13 var sm_x = 2, sm_y = 2;
14 var sm_s = 0;
15 var sm_add = 10;
16 var s_left = 0;
17 var s_right = 0;
18 var ON_relation = 0;
19 var ON_grid = 0;
20 var ON_display_field = 0;
21 // relation_style: 0 - angular 1 - direct
22 var ON_angular_direct = 1;
23 var click_field = 0;
24 var link_relation = "";
25 var id_hint;
26 var canvas_width = 0;
27 var canvas_height = 0;
28 var osn_tab_width = 0;
29 var osn_tab_height = 0;
30 var height_field = 7;
31 var Glob_X, Glob_Y;
32 var timeoutID;
33 var layer_menu_cur_click = 0;
34 var step = 10;
35 var old_class;
37 //------------------------------------------------------------------------------
38 //------------------------------------------------------------------------------
39 //------------------------------------------------------------------------------
42 //window.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP);
43 //---CROSS
44 document.onmousedown = MouseDown;
45 document.onmouseup = MouseUp;
46 document.onmousemove = MouseMove;
48 var isIE = document.all && !window.opera;
49 var isNN = !document.all && document.getElementById;
50 var isN4 = document.layers;
52 if (isIE) {
53 window.onscroll = General_scroll;
54 document.onselectstart = function () {return false;};
57 //document.onmouseup = function(){General_scroll_end();}
58 function MouseDown(e)
60 var offsetx, offsety;
61 if (cur_click != null) {
62 offsetx = isIE ? event.clientX + document.body.scrollLeft : e.pageX;
63 offsety = isIE ? event.clientY + document.body.scrollTop : e.pageY;
64 dx = offsetx - parseInt(cur_click.style.left);
65 dy = offsety - parseInt(cur_click.style.top);
66 //alert(" dx = " + dx + " dy = " +dy);
67 document.getElementById("canvas").style.visibility = 'hidden';
69 var left = parseInt(cur_click.style.left);
70 var top = parseInt(cur_click.style.top);
71 dx = e.pageX - left;
72 dy = e.pageY - top;
74 alert(" dx = " + dx + " dy = " +dy);
76 cur_click.style.zIndex = 2;
78 if (layer_menu_cur_click) {
79 offsetx = isIE ? event.clientX + document.body.scrollLeft : e.pageX;
80 dx = offsetx - parseInt(document.getElementById("layer_menu").style.width);
84 function MouseMove(e)
86 //Glob_X = e.pageX;
87 //Glob_Y = e.pageY;
88 Glob_X = isIE ? event.clientX + document.body.scrollLeft : e.pageX;
89 Glob_Y = isIE ? event.clientY + document.body.scrollTop : e.pageY;
91 //mouseX = (bw.ns4||bw.ns6)? e.pageX: bw.ie&&bw.win&&!bw.ie4? (event.clientX-2)+document.body.scrollLeft : event.clientX+document.body.scrollLeft;
92 //mouseY = (bw.ns4||bw.ns6)? e.pageY: bw.ie&&bw.win&&!bw.ie4? (event.clientY-2)+document.body.scrollTop : event.clientY+document.body.scrollTop;
94 //window.status = "X = "+ Glob_X + " Y = "+ Glob_Y;
96 if (cur_click != null) {
97 var mGx = Glob_X - dx;
98 var mGy = Glob_Y - dy;
99 mGx = mGx > 0 ? mGx : 0;
100 mGy = mGy > 0 ? mGy : 0;
102 if (ON_grid) {
103 mGx = mGx % step < step / 2 ? mGx - mGx % step : mGx - mGx % step + step;
104 mGy = mGy % step < step / 2 ? mGy - mGy % step : mGy - mGy % step + step;
107 cur_click.style.left = mGx + 'px';
108 cur_click.style.top = mGy + 'px';
111 if (ON_relation || ON_display_field) {
112 document.getElementById('hint').style.left = (Glob_X + 20) + 'px';
113 document.getElementById('hint').style.top = (Glob_Y + 20) + 'px';
116 if (layer_menu_cur_click) {
117 document.getElementById("layer_menu").style.width = ((Glob_X - dx) >= 150 ? Glob_X - dx : 150) + 'px';
118 //document.getElementById("layer_menu").style.height = Glob_Y - dy>=200?Glob_Y - dy:200;
119 //document.getElementById("id_scroll_tab").style.height = Glob_Y - dy2;
123 function MouseUp(e)
125 if (cur_click != null) {
126 document.getElementById("canvas").style.visibility = 'visible';
127 Re_load();
128 cur_click.style.zIndex = 1;
129 cur_click = null;
131 layer_menu_cur_click = 0;
132 //window.releaseEvents(Event.MOUSEMOVE);
134 //------------------------------------------------------------------------------
135 //------------------------------------------------------------------------------
136 //------------------------------------------------------------------------------
139 //function ToInt(s)
141 // return s.substring(0,s.length-2)*1; //re = /(\d+)\w*/; newstr = str.replace(re, "$1");
144 function Canvas_pos()
146 canvas_width = document.getElementById('canvas').width = osn_tab_width - 3;
147 canvas_height = document.getElementById('canvas').height = osn_tab_height - 3;
149 if (isIE) {
150 document.getElementById('canvas').style.width = ((osn_tab_width - 3)?(osn_tab_width - 3):0) + 'px';
151 document.getElementById('canvas').style.height = ((osn_tab_height - 3)?(osn_tab_height - 3):0) + 'px';
155 function Osn_tab_pos()
157 osn_tab_width = parseInt(document.getElementById('osn_tab').style.width);
158 osn_tab_height = parseInt(document.getElementById('osn_tab').style.height);
162 function Main()
164 //alert( document.getElementById('osn_tab').offsetTop);
165 //---CROSS
166 if (isIE) {
167 document.getElementById('top_menu').style.position = 'absolute';
168 document.getElementById('layer_menu').style.position = 'absolute';
171 document.getElementById("layer_menu").style.top = -1000 + 'px'; //fast scroll
172 sm_x += document.getElementById('osn_tab').offsetLeft;
173 sm_y += document.getElementById('osn_tab').offsetTop;
174 Osn_tab_pos();
175 Canvas_pos();
176 Small_tab_refresh();
177 Re_load();
178 id_hint = document.getElementById('hint');
179 if (isIE) {
180 General_scroll();
185 //-------------------------------- new -----------------------------------------
186 function Rezize_osn_tab()
188 var max_X = 0;
189 var max_Y = 0;
190 for (key in j_tabs) {
191 var k_x = parseInt(document.getElementById(key).style.left) + document.getElementById(key).offsetWidth;
192 var k_y = parseInt(document.getElementById(key).style.top) + document.getElementById(key).offsetHeight;
193 max_X = max_X < k_x ? k_x : max_X;
194 max_Y = max_Y < k_y ? k_y : max_Y;
197 osn_tab_width = max_X + 50;
198 osn_tab_height = max_Y + 50;
199 Canvas_pos();
200 document.getElementById('osn_tab').style.width = osn_tab_width + 'px';
201 document.getElementById('osn_tab').style.height = osn_tab_height + 'px';
203 //------------------------------------------------------------------------------
206 * refreshes display, must be called after state changes
208 function Re_load()
210 Rezize_osn_tab();
211 var n;
212 var x1;
213 var x2;
214 var a = new Array();
215 Clear();
216 for (K in contr)
217 for (key in contr[K]) // contr name
218 for (key2 in contr[K][key]) // table name
219 for (key3 in contr[K][key][key2]) // field name
221 if (!document.getElementById("check_vis_" + key2).checked ||
222 !document.getElementById("check_vis_" + contr[K][key][key2][key3][0]).checked) {
223 // if hide
224 continue;
226 var x1_left = document.getElementById(key2).offsetLeft+1;
227 var x1_right = x1_left + document.getElementById(key2).offsetWidth;
228 var x2_left = document.getElementById(contr[K][key][key2][key3][0]).offsetLeft;
229 var x2_right = x2_left + document.getElementById(contr[K][key][key2][key3][0]).offsetWidth;
230 a[0] = Math.abs(x1_left - x2_left);
231 a[1] = Math.abs(x1_left - x2_right);
232 a[2] = Math.abs(x1_right - x2_left);
233 a[3] = Math.abs(x1_right - x2_right);
234 n = s_left = s_right = 0;
235 for (var i = 1; i < 4; i++) {
236 if (a[n] > a[i]) {
237 n = i;
240 if (n == 1) {
241 x1 = x1_left - sm_s;
242 x2 = x2_right + sm_s;
243 if (x1 < x2) {
244 n = 0;
247 if (n == 2) {
248 x1 = x1_right + sm_s;
249 x2 = x2_left - sm_s;
250 if (x1 > x2) {
251 n = 0;
254 if (n == 3) {
255 x1 = x1_right + sm_s;
256 x2 = x2_right + sm_s;
257 s_right = 1;
259 if (n == 0) {
260 x1 = x1_left - sm_s;
261 x2 = x2_left - sm_s;
262 s_left = 1;
264 //alert(key2 + "." + key3);
266 var row_offset_top = 0;
267 //alert('id_tbody_' + key2);
268 //alert(document.getElementById('id_hide_tbody_' + key2));
269 var tab_hide_button = document.getElementById('id_hide_tbody_' + key2);
271 //alert(tab_hide_button.innerHTML);
272 if (tab_hide_button.innerHTML == 'v') {
273 row_offset_top = document.getElementById(key2 + "." + key3).offsetTop;
276 var y1 = document.getElementById(key2).offsetTop
277 + row_offset_top
278 + height_field;
279 //alert(1);
281 row_offset_top = 0;
282 var tab_hide_button = document.getElementById('id_hide_tbody_' + contr[K][key][key2][key3][0]);
283 if (tab_hide_button.innerHTML == 'v') {
284 row_offset_top = document.getElementById(contr[K][key][key2][key3][0]
285 + '.' + contr[K][key][key2][key3][1]).offsetTop;
288 var y2 =
289 document.getElementById(contr[K][key][key2][key3][0]).offsetTop
290 + row_offset_top
291 + height_field;
293 //alert(y1 + ' - ' + key2 + "." + key3);
294 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] ) );
299 * draws a line from x1:y1 to x2:y2 with color
301 function Line(x1, y1, x2, y2, color_line)
303 var canvas = document.getElementById("canvas");
304 var ctx = canvas.getContext("2d");
305 ctx.strokeStyle = color_line;
306 ctx.lineWidth = 1;
307 ctx.beginPath();
308 ctx.moveTo(x1, y1);
309 ctx.lineTo(x2, y2);
310 ctx.stroke();
314 * draws a relation/constraint line, whether angular or not
316 function Line0(x1, y1, x2, y2, color_line)
318 Circle(x1, y1, 3, 3, color_line);
319 Rect(x2 - 1, y2 - 2, 4, 4, color_line);
321 if (ON_angular_direct) {
322 Line2(x1, y1, x2, y2, color_line);
323 } else {
324 Line3(x1, y1, x2, y2, color_line);
329 * draws a angualr relation/constraint line
331 function Line2(x1, y1, x2, y2, color_line)
333 var x1_ = x1;
334 var x2_ = x2;
336 if (s_right) {
337 x1_ += sm_add;
338 x2_ += sm_add;
339 } else if (s_left) {
340 x1_ -= sm_add;
341 x2_ -= sm_add;
342 } else if (x1 < x2) {
343 x1_ += sm_add;
344 x2_ -= sm_add;
345 } else {
346 x1_ -= sm_add;
347 x2_ += sm_add;
350 Line(x1, y1, x1_, y1, color_line);
351 Line(x2, y2, x2_, y2, color_line);
352 Line(x1_, y1, x2_, y2, color_line);
356 * draws a relation/constraint line
358 function Line3(x1, y1, x2, y2, color_line)
360 var x1_ = x1;
361 var x2_ = x2;
363 if (s_right) {
364 if (x1 < x2) {
365 x1_ += x2 - x1 + sm_add;
366 x2_ += sm_add;
367 } else {
368 x2_ += x1 - x2 + sm_add;
369 x1_ += sm_add;
372 Line(x1, y1, x1_, y1, color_line);
373 Line(x2, y2, x2_, y2, color_line);
374 Line(x1_, y1, x2_, y2, color_line);
375 return;
377 if (s_left) {
378 if (x1 < x2) {
379 x2_ -= x2 - x1 + sm_add;
380 x1_ -= sm_add;
381 } else {
382 x1_ -= x1 - x2 + sm_add;
383 x2_ -= sm_add;
386 Line(x1, y1, x1_, y1, color_line);
387 Line(x2, y2, x2_, y2, color_line);
388 Line(x1_, y1, x2_, y2, color_line);
389 return;
392 var x_s = (x1 + x2) / 2;
393 Line(x1, y1, x_s, y1, color_line);
394 Line(x_s, y2, x2, y2, color_line);
395 Line(x_s, y1, x_s, y2, color_line);
398 function Circle(x, y, r, w, color)
400 var ctx = document.getElementById('canvas').getContext('2d');
401 ctx.beginPath();
402 ctx.moveTo(x, y);
403 ctx.lineWidth = w;
404 ctx.strokeStyle = color;
405 ctx.arc(x, y, r, 0, 2 * Math.PI, true);
406 ctx.stroke();
409 function Clear()
411 var canvas = document.getElementById("canvas");
412 var ctx = canvas.getContext("2d");
413 ctx.clearRect(0, 0, canvas_width, canvas_height);
416 function Rect(x1, y1, w, h, color)
418 var ctx = document.getElementById('canvas').getContext('2d');
419 ctx.fillStyle = color;
420 ctx.fillRect(x1, y1, w, h);
423 //------------------------------ SAVE ------------------------------------------
424 function Save(url) // (del?) no for pdf
426 for (key in j_tabs) {
427 document.getElementById('t_x_' + key + '_').value = parseInt(document.getElementById(key).style.left);
428 document.getElementById('t_y_' + key + '_').value = parseInt(document.getElementById(key).style.top);
429 document.getElementById('t_v_' + key + '_').value = document.getElementById('id_tbody_' + key).style.display == 'none' ? 0 : 1;
430 document.getElementById('t_h_' + key + '_').value = document.getElementById('check_vis_' + key).checked ? 1 : 0;
432 document.form1.action = url;
433 document.form1.submit();
436 function Get_url_pos()
438 var poststr = '';
439 for (key in j_tabs) {
440 poststr += '&t_x[' + key + ']=' + parseInt(document.getElementById(key).style.left);
441 poststr += '&t_y[' + key + ']=' + parseInt(document.getElementById(key).style.top);
442 poststr += '&t_v[' + key + ']=' + (document.getElementById('id_tbody_' + key).style.display == 'none' ? 0 : 1);
443 poststr += '&t_h[' + key + ']=' + (document.getElementById('check_vis_' + key).checked ? 1 : 0);
445 return poststr;
448 function Save2()
450 var poststr = 'IS_AJAX=1&server='+server+'&db=' + db + '&token=' + token + '&die_save_pos=1';
451 poststr += Get_url_pos();
452 makeRequest('pmd_save_pos.php', poststr);
455 function Grid()
457 if (!ON_grid) {
458 ON_grid = 1;
459 document.getElementById('grid_button').className = 'M_butt_Selected_down';
460 } else {
461 document.getElementById('grid_button').className = 'M_butt';
462 ON_grid = 0;
466 function Angular_direct()
468 if (ON_angular_direct) {
469 ON_angular_direct = 0;
470 document.getElementById('angular_direct_button').className = 'M_butt_Selected_down';
471 } else {
472 ON_angular_direct = 1;
473 document.getElementById('angular_direct_button').className = 'M_butt';
475 Re_load();
477 //++++++++++++++++++++++++++++++ RELATION ++++++++++++++++++++++++++++++++++++++
478 function Start_relation()
480 if (ON_display_field) {
481 return;
484 if (!ON_relation) {
485 document.getElementById('foreign_relation').style.display = '';
486 ON_relation = 1;
487 document.getElementById('hint').innerHTML = PMA_messages['strSelectReferencedKey'];
488 document.getElementById('hint').style.visibility = "visible";
489 document.getElementById('rel_button').className = 'M_butt_Selected_down';
490 } else {
491 document.getElementById('hint').innerHTML = "";
492 document.getElementById('hint').style.visibility = "hidden";
493 document.getElementById('rel_button').className = 'M_butt';
494 click_field = 0;
495 ON_relation = 0;
499 function Click_field(T, f, PK) // table field
501 if (ON_relation) {
502 if (!click_field) {
503 //.style.display=='none' .style.visibility = "hidden"
504 if (!PK) {
505 alert(PMA_messages['strPleaseSelectPrimaryOrUniqueKey']);
506 return;// 0;
507 }//PK
508 if (j_tabs[db + '.' + T] != '1') {
509 document.getElementById('foreign_relation').style.display = 'none';
511 click_field = 1;
512 link_relation = "T1=" + T + "&F1=" + f;
513 document.getElementById('hint').innerHTML = PMA_messages['strSelectForeignKey'];
514 } else {
515 Start_relation(); // hidden hint...
516 if (j_tabs[db + '.' + T] != '1' || !PK) {
517 document.getElementById('foreign_relation').style.display = 'none';
519 var left = Glob_X - (document.getElementById('layer_new_relation').offsetWidth>>1);
520 document.getElementById('layer_new_relation').style.left = left + 'px';
521 var top = Glob_Y - document.getElementById('layer_new_relation').offsetHeight - 10;
522 document.getElementById('layer_new_relation').style.top = top + 'px';
523 document.getElementById('layer_new_relation').style.visibility = "visible";
524 link_relation += '&T2=' + T + '&F2=' + f;
528 if (ON_display_field) {
529 // if is display field
530 if (display_field[T] == f) {
531 //alert(T);
532 //s = '';for(k in display_field)s += k + ' = ' + display_field[k] + ',';alert(s);
533 old_class = 'tab_field';
534 //display_field.splice(T, 1);
535 delete display_field[T];
536 //s = '';for(k in display_field)s += k + ' = ' + display_field[k] + ', ';alert(s);
537 //n = 0;for(k in display_field)n++;alert(n);
538 } else {
539 old_class = 'tab_field_3';
540 if (display_field[T]) {
541 document.getElementById('id_tr_' + T + '.' + display_field[T]).className = 'tab_field';
542 //display_field.splice(T, 1);
543 delete display_field[T];
545 display_field[T] = f;
547 ON_display_field = 0;
548 document.getElementById('hint').innerHTML = "";
549 document.getElementById('hint').style.visibility = "hidden";
550 document.getElementById('display_field_button').className = 'M_butt';
551 makeRequest('pmd_display_field.php', 'T=' + T + '&F=' + f + '&server=' + server + '&db=' + db + '&token=' + token);
555 function New_relation()
557 document.getElementById('layer_new_relation').style.visibility = 'hidden';
558 link_relation += '&server=' + server + '&db=' + db + '&token=' + token + '&die_save_pos=0';
559 link_relation += '&on_delete=' + document.getElementById('on_delete').value + '&on_update=' + document.getElementById('on_update').value;
560 link_relation += Get_url_pos();
562 //alert(link_relation);
563 makeRequest('pmd_relation_new.php', link_relation);
566 //-------------------------- create tables -------------------------------------
568 function Start_table_new()
570 window.location.href = 'db_operations.php?server=' + server + '&db=' + db + '&token=' + token;
573 function Start_tab_upd(table)
575 window.location.href = 'tbl_structure.php?server=' + server + '&db=' + db + '&token=' + token + '&table=' + table;
577 //--------------------------- hide tables --------------------------------------
579 function Small_tab_all(id_this) // max/min all tables
581 if (id_this.alt == "v") {
582 for (key in j_tabs) {
583 if (document.getElementById('id_hide_tbody_'+key).innerHTML == "v") {
584 Small_tab(key, 0);
587 id_this.alt = ">";
588 id_this.src = "pmd/images/rightarrow1.png";
589 } else {
590 for (key in j_tabs) {
591 if (document.getElementById('id_hide_tbody_'+key).innerHTML != "v") {
592 Small_tab(key, 0);
595 id_this.alt = "v";
596 id_this.src = "pmd/images/downarrow1.png";
598 Re_load();
601 function Small_tab_invert() // invert max/min all tables
603 for (key in j_tabs) {
604 Small_tab(key, 0);
606 Re_load();
609 function Small_tab_refresh()
611 for (key in j_tabs) {
612 if(document.getElementById('id_hide_tbody_'+key).innerHTML != "v") {
613 Small_tab(key, 0);
614 Small_tab(key, 0);
619 function Small_tab(t, re_load)
621 var id = document.getElementById('id_tbody_' + t);
622 var id_this = document.getElementById('id_hide_tbody_' + t);
623 var id_t = document.getElementById(t);
625 id_t.style.width = id_t.offsetWidth + 'px';
626 if (id_this.innerHTML == "v") {
627 //---CROSS
628 id.style.display = 'none';
629 id_this.innerHTML = '>';
630 } else {
631 id.style.display = '';
632 id_this.innerHTML = 'v';
634 if (re_load) {
635 Re_load();
638 //------------------------------------------------------------------------------
639 function Select_tab(t)
641 var id_zag = document.getElementById('id_zag_' + t);
642 if (id_zag.className != 'tab_zag_3') {
643 document.getElementById('id_zag_' + t).className = 'tab_zag_2';
644 } else {
645 document.getElementById('id_zag_' + t).className = 'tab_zag';
647 //----------
648 var id_t = document.getElementById(t);
649 window.scrollTo(parseInt(id_t.style.left) - 300, parseInt(id_t.style.top) - 300);
651 setTimeout(function(){document.getElementById('id_zag_' + t).className = 'tab_zag';}, 800);
653 //------------------------------------------------------------------------------
655 function Canvas_click(id)
657 var n = 0;
658 var relation_name = 0;
659 var selected = 0;
660 var a = new Array();
661 var Key0, Key1, Key2, Key3, Key, x1, x2;
662 Clear();
663 for (K in contr)
664 for (key in contr[K])
665 for (key2 in contr[K][key])
666 for (key3 in contr[K][key][key2]) {
667 if (!document.getElementById("check_vis_"+key2).checked ||
668 !document.getElementById("check_vis_"+contr[K][key][key2][key3][0]).checked) continue; // if hide
669 var x1_left = document.getElementById(key2).offsetLeft + 1;//document.getElementById(key2+"."+key3).offsetLeft;
670 var x1_right = x1_left + document.getElementById(key2).offsetWidth;
671 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
672 var x2_right = x2_left + document.getElementById(contr[K][key][key2][key3][0]).offsetWidth;
673 a[0] = Math.abs(x1_left - x2_left);
674 a[1] = Math.abs(x1_left - x2_right);
675 a[2] = Math.abs(x1_right - x2_left);
676 a[3] = Math.abs(x1_right - x2_right);
677 n = s_left = s_right = 0;
678 for (var i = 1; i < 4; i++) {
679 if (a[n] > a[i]) {
680 n = i;
683 if (n == 1) {
684 x1 = x1_left - sm_s;
685 x2 = x2_right + sm_s;
686 if (x1 < x2) {
687 n = 0;
690 if (n == 2) {
691 x1 = x1_right + sm_s;
692 x2 = x2_left - sm_s;
693 if (x1 > x2) {
694 n = 0;
697 if (n == 3) {
698 x1 = x1_right + sm_s;
699 x2 = x2_right + sm_s;
700 s_right = 1;
702 if (n == 0) {
703 x1 = x1_left - sm_s;
704 x2 = x2_left - sm_s;
705 s_left = 1;
708 var y1 = document.getElementById(key2).offsetTop + document.getElementById(key2+"."+key3).offsetTop + height_field;
709 var y2 = document.getElementById(contr[K][key][key2][key3][0]).offsetTop +
710 document.getElementById(contr[K][key][key2][key3][0]+"."+contr[K][key][key2][key3][1]).offsetTop + height_field;
711 if (!selected && Glob_X > x1 - 10 && Glob_X < x1 + 10 && Glob_Y > y1 - 7 && Glob_Y < y1 + 7) {
712 Line0(x1 - sm_x, y1 - sm_y, x2 - sm_x, y2 - sm_y, "rgba(255,0,0,1)");
713 selected = 1; // Rect(x1-sm_x,y1-sm_y,10,10,"rgba(0,255,0,1)");
714 relation_name = key; //
715 Key0 = contr[K][key][key2][key3][0];
716 Key1 = contr[K][key][key2][key3][1];
717 Key2 = key2; Key3 = key3;
718 Key = K;
719 } else {
720 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] ));
723 if (selected) {
724 // select relations
725 //alert(Key0+' - '+Key1+' - '+Key2+' - '+Key3);
726 var left = Glob_X - (document.getElementById('layer_upd_relation').offsetWidth>>1);
727 document.getElementById('layer_upd_relation').style.left = left + 'px';
728 var top = Glob_Y - document.getElementById('layer_upd_relation').offsetHeight - 10;
729 document.getElementById('layer_upd_relation').style.top = top + 'px';
730 document.getElementById('layer_upd_relation').style.visibility = 'visible';
731 link_relation = 'T1=' + Key0 + '&F1=' + Key1 + '&T2=' + Key2 + '&F2=' + Key3 + '&K=' + Key;
735 function Upd_relation()
737 document.getElementById('layer_upd_relation').style.visibility = 'hidden';
738 link_relation += '&server=' + server + '&db=' + db + '&token=' + token + '&die_save_pos=0';
739 link_relation += Get_url_pos();
740 makeRequest('pmd_relation_upd.php', link_relation);
743 function VisibleTab(id, t_n)
745 if (id.checked) {
746 document.getElementById(t_n).style.visibility = 'visible';
747 } else {
748 document.getElementById(t_n).style.visibility = 'hidden';
750 Re_load();
753 function Hide_tab_all(id_this) // max/min all tables
755 if (id_this.alt == 'v') {
756 id_this.alt = '>';
757 id_this.src = "pmd/images/rightarrow1.png";
758 } else {
759 id_this.alt = 'v';
760 id_this.src = "pmd/images/downarrow1.png";
762 var E = document.form1;
763 for (i = 0; i < E.elements.length; i++) {
764 if (E.elements[i].type == "checkbox" && E.elements[i].id.substring(0, 10) == 'check_vis_') {
765 if (id_this.alt == 'v') {
766 E.elements[i].checked = true;
767 document.getElementById(E.elements[i].value).style.visibility = 'visible';
768 } else {
769 E.elements[i].checked = false;
770 document.getElementById(E.elements[i].value).style.visibility = 'hidden';
774 Re_load();
777 function in_array_k(x, m)
779 var b = 0;
780 for (u in m) {
781 if (x == u) {
782 b=1;
783 break;
786 return b;
789 function No_have_constr(id_this)
791 var a = new Array();
792 for (K in contr)
793 for (key in contr[K]) // contr name
794 for (key2 in contr[K][key]) // table name
795 for (key3 in contr[K][key][key2]) // field name
796 a[key2] = a[contr[K][key][key2][key3][0]] = 1; // exist constr
799 if (id_this.alt == 'v') {
800 id_this.alt = '>';
801 id_this.src = "pmd/images/rightarrow2.png";
802 } else {
803 id_this.alt = 'v';
804 id_this.src = "pmd/images/downarrow2.png";
806 var E = document.form1;
807 for (i = 0; i < E.elements.length; i++) {
808 if (E.elements[i].type == "checkbox" && E.elements[i].id.substring(0, 10) == 'check_vis_')
810 if (!in_array_k(E.elements[i].value, a))
811 if (id_this.alt == 'v') {
812 E.elements[i].checked = true;
813 document.getElementById(E.elements[i].value).style.visibility = 'visible';
814 } else {
815 E.elements[i].checked = false;
816 document.getElementById(E.elements[i].value).style.visibility = 'hidden';
822 function Help()
824 var WinHelp = window.open("pmd_help.php", "wind1", "top=200,left=400,width=300,height=200,resizable=yes,scrollbars=yes,menubar=no");
827 function PDF_save()
829 // var WinPDF =
830 // window.open("pmd_pdf.php?token="+token+"&db="+db,"wind1", "top=200,left=200,width=200,height=100,resizable=yes,scrollbars=yes,menubar=no");
831 Save('pmd_pdf.php?server=' + server + '&token=' + token + '&db=' + db);
834 function General_scroll()
837 if (!document.getElementById('show_relation_olways').checked) {
838 document.getElementById("canvas").style.visibility = 'hidden';
839 clearTimeout(timeoutID);
840 timeoutID = setTimeout(General_scroll_end, 500);
843 //if (timeoutID)
844 clearTimeout(timeoutID);
845 timeoutID = setTimeout
847 function()
849 document.getElementById('top_menu').style.left = document.body.scrollLeft + 'px';
850 document.getElementById('top_menu').style.top = document.body.scrollTop + 'px';
851 document.getElementById('layer_menu').style.left = document.body.scrollLeft + 'px';
852 document.getElementById('layer_menu').style.top = (document.body.scrollTop + document.getElementById('top_menu').offsetHeight) + 'px';
854 ,200
859 function General_scroll_end()
861 document.getElementById('layer_menu').style.left = document.body.scrollLeft;
862 document.getElementById('layer_menu').style.top = document.body.scrollTop + document.getElementById('top_menu').offsetHeight;
863 if (isIE) {
864 document.getElementById('layer_menu').style.left = document.body.scrollLeft;
865 document.getElementById('layer_menu').style.top = document.body.scrollTop + document.getElementById('top_menu').offsetHeight;
867 document.getElementById("canvas").style.visibility = 'visible';
871 function Show_left_menu(id_this) // max/min all tables
873 if (id_this.alt == "v") {
874 document.getElementById("layer_menu").style.top = document.getElementById('top_menu').offsetHeight + 'px';
875 document.getElementById("layer_menu").style.visibility = 'visible';
876 id_this.alt = ">";
877 id_this.src = "pmd/images/uparrow2_m.png";
878 if (isIE) {
879 General_scroll();
881 } else {
882 document.getElementById("layer_menu").style.top = -1000 + 'px'; //fast scroll
883 document.getElementById("layer_menu").style.visibility = 'hidden';
884 id_this.alt = "v";
885 id_this.src = "pmd/images/downarrow2_m.png";
888 //------------------------------------------------------------------------------
889 function Top_menu_right(id_this)
891 if (id_this.alt == ">") {
892 document.getElementById('top_menu').style.marginLeft = document.getElementById('top_menu').offsetWidth + 'px'; // = 350
893 id_this.alt = "<";
894 id_this.src = "pmd/images/2leftarrow_m.png";
895 } else {
896 document.getElementById('top_menu').style.marginLeft = 0;
897 id_this.alt = ">";
898 id_this.src = "pmd/images/2rightarrow_m.png";
901 //------------------------------------------------------------------------------
902 function Start_display_field()
904 if (ON_relation) {
905 return;
907 if (!ON_display_field) {
908 ON_display_field = 1;
909 document.getElementById('hint').innerHTML = PMA_messages['strChangeDisplay'];
910 document.getElementById('hint').style.visibility = "visible";
911 document.getElementById('display_field_button').className = 'M_butt_Selected_down';//'#FFEE99';gray #AAAAAA
913 if (isIE) { // correct for IE
914 document.getElementById('display_field_button').className = 'M_butt_Selected_down_IE';
916 } else {
917 document.getElementById('hint').innerHTML = "";
918 document.getElementById('hint').style.visibility = "hidden";
919 document.getElementById('display_field_button').className = 'M_butt';
920 ON_display_field = 0;
923 //------------------------------------------------------------------------------
924 var TargetColors = new Array();
925 function getColorByTarget( target )
927 var color = ''; //"rgba(0,100,150,1)";
929 for (i in TargetColors)
930 if (TargetColors[i][0]==target) {
931 color = TargetColors[i][1];
932 break;
936 if (color.length==0)
938 var i = TargetColors.length+1;
939 var d = i % 6;
940 var j = (i - d) / 6;
941 j = j % 4;
942 j++;
943 var color_case = new Array(
944 new Array(1, 0, 0),
945 new Array(0, 1, 0),
946 new Array(0, 0, 1),
947 new Array(1, 1, 0),
948 new Array(1, 0, 1),
949 new Array(0, 1, 1)
951 var a = color_case[d][0];
952 var b = color_case[d][1];
953 var c = color_case[d][2];
954 e = (1 - (j - 1) / 6);
956 var r = Math.round(a * 200 * e);
957 var g = Math.round(b * 200 * e);
958 var b = Math.round(c * 200 * e);
959 var color = "rgba("+r+","+g+","+b+",1)";
961 TargetColors.push( new Array(target, color) );
966 return color;
969 function Click_option(id_this,column_name,table_name)
971 var left = Glob_X - (document.getElementById(id_this).offsetWidth>>1);
972 document.getElementById(id_this).style.left = left + 'px';
973 // var top = Glob_Y - document.getElementById(id_this).offsetHeight - 10;
974 document.getElementById(id_this).style.top = (screen.height / 4) + 'px';
975 document.getElementById(id_this).style.visibility = "visible";
976 document.getElementById('option_col_name').innerHTML = '<strong>Options For "' +column_name+ '" column</strong>';
977 col_name = column_name;
978 tab_name = table_name;
981 function Close_option()
983 document.getElementById('pmd_optionse').style.visibility = "hidden";
986 function Select_all(id_this)
988 var parent= document.form1;
989 for(i = 0; i < parent.elements.length; i++) {
990 if (parent.elements[i].type == "checkbox" && parent.elements[i].id.substring(0,(7 + id_this.length)) == 'select_' + id_this) {
991 if(document.getElementById('select_all_' + id_this).checked == true)
992 parent.elements[i].checked = true;
993 else
994 parent.elements[i].checked = false;
997 Re_load();
1000 function Table_onover(id_this,val)
1002 if(!val) {
1003 document.getElementById("id_zag_" + id_this).className="tab_zag_2";
1004 document.getElementById("id_zag_" + id_this + "_2").className="tab_zag_2";
1006 else {
1007 document.getElementById("id_zag_" + id_this).className="tab_zag";
1008 document.getElementById("id_zag_" + id_this + "_2").className="tab_zag";
1012 function add_object() {
1013 var rel = document.getElementById('rel_opt');
1014 var sum = 0;
1015 var init = history_array.length;
1016 if (rel.value != '--') {
1017 if (document.getElementsByName('Query').value == "") {
1018 document.getElementById('hint').innerHTML = "value/subQuery is empty" ;
1019 document.getElementById('hint').style.visibility = "visible";
1020 return;
1022 var p = document.getElementsByName('Query');
1023 var where_obj = new where(rel.value,p.value);//make where object
1024 history_array.push(new history(col_name,where_obj,tab_name,h_tabs[tab_name],"Where"));
1025 sum = sum + 1;
1026 rel.value = '--';
1027 p.value = "";
1029 if (document.getElementById('new_name').value !="") {
1030 var rename_obj = new rename(document.getElementById('new_name').value);//make Rename object
1031 history_array.push(new history(col_name,rename_obj,tab_name,h_tabs[tab_name],"Rename"));
1032 sum = sum + 1;
1033 document.getElementById('new_name').value = "" ;
1035 if (document.getElementById('operator').value != '---') {
1036 var aggregate_obj = new aggregate(document.getElementById('operator').value) ;
1037 history_array.push(new history(col_name,aggregate_obj,tab_name,h_tabs[tab_name],"Aggregate"));
1038 sum = sum + 1;
1039 document.getElementById('operator').value = '---';
1040 //make aggregate operator
1042 if (document.getElementById('groupby').checked == true ) {
1043 history_array.push(new history(col_name,'GroupBy',tab_name,h_tabs[tab_name],"Group By"));
1044 sum = sum + 1;
1045 document.getElementById('groupby').checked = false;
1046 //make groupby
1048 if (document.getElementById('orderby').checked == true) {
1049 history_array.push(new history(col_name,'OrderBy',tab_name,h_tabs[tab_name],"Order By"));
1050 sum = sum + 1;
1051 document.getElementById('orderby').checked = false;
1052 //make orderby
1054 document.getElementById('hint').innerHTML = sum + "object created" ;
1055 document.getElementById('hint').style.visibility = "visible";
1056 //output sum new objects created
1057 var existingDiv = document.getElementById('ab');
1058 existingDiv.innerHTML = display(init,history_array.length);
1059 Close_option();
1060 panel();