move.js 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232
  1. /* vim: set expandtab sw=4 ts=4 sts=4: */
  2. /**
  3. * @package PhpMyAdmin-Designer
  4. */
  5. var _change = 0; // variable to track any change in designer layout.
  6. var _staying = 0; // variable to check if the user stayed after seeing the confirmation prompt.
  7. var show_relation_lines = true;
  8. var always_show_text = false;
  9. AJAX.registerTeardown('designer/move.js', function () {
  10. $(document).off('fullscreenchange');
  11. $('#selflink').show();
  12. });
  13. AJAX.registerOnload('designer/move.js', function () {
  14. $('#page_content').css({ 'margin-left': '3px' });
  15. $(document).on('fullscreenchange', function () {
  16. if (! $.fn.fullScreen()) {
  17. $('#page_content').removeClass('content_fullscreen')
  18. .css({ 'width': 'auto', 'height': 'auto' });
  19. var $img = $('#toggleFullscreen').find('img');
  20. var $span = $img.siblings('span');
  21. $span.text($span.data('enter'));
  22. $img.attr('src', $img.data('enter'))
  23. .attr('title', $span.data('enter'));
  24. }
  25. });
  26. $('#selflink').hide();
  27. });
  28. function make_zero () { // Function called if the user stays after seeing the confirmation prompt.
  29. _staying = 0;
  30. }
  31. function MarkSaved () {
  32. _change = 0;
  33. $('#saved_state').text('');
  34. }
  35. function MarkUnsaved () {
  36. _change = 1;
  37. $('#saved_state').text('*');
  38. }
  39. var dx;
  40. var dy;
  41. var dy2;
  42. var cur_click = null;
  43. // update in Main()
  44. var sm_x = 2;
  45. var sm_y = 2;
  46. var sm_s = 0;
  47. var sm_add = 10;
  48. var s_left = 0;
  49. var s_right = 0;
  50. var ON_relation = 0;
  51. var ON_grid = 0;
  52. var ON_display_field = 0;
  53. // relation_style: 0 - angular 1 - direct
  54. var ON_angular_direct = 1;
  55. var click_field = 0;
  56. var link_relation = '';
  57. var id_hint;
  58. var canvas_width = 0;
  59. var canvas_height = 0;
  60. var osn_tab_width = 0;
  61. var osn_tab_height = 0;
  62. var height_field = 7;
  63. var Glob_X;
  64. var Glob_Y;
  65. var timeoutID;
  66. var layer_menu_cur_click = 0;
  67. var step = 10;
  68. var from_array = [];
  69. var menu_moved = false;
  70. var grid_size = 10;
  71. // ------------------------------------------------------------------------------
  72. // ------------------------------------------------------------------------------
  73. // ------------------------------------------------------------------------------
  74. // window.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP);
  75. // ---CROSS
  76. var isIE = document.all && !window.opera;
  77. if (isIE) {
  78. window.onscroll = General_scroll;
  79. document.onselectstart = function () {
  80. return false;
  81. };
  82. }
  83. // document.onmouseup = function (){General_scroll_end();}
  84. function MouseDown (e) {
  85. Glob_X = dx = isIE ? e.clientX + document.body.scrollLeft : e.pageX;
  86. Glob_Y = dy = isIE ? e.clientY + document.body.scrollTop : e.pageY;
  87. if (e.target.tagName === 'SPAN') {
  88. cur_click = e.target.parentNode.parentNode.parentNode.parentNode;
  89. } else if (e.target.className === 'tab_zag_2') {
  90. cur_click = e.target.parentNode.parentNode.parentNode;
  91. } else if (e.target.className === 'icon') {
  92. layer_menu_cur_click = 1;
  93. } else if (e.target.className === 'M_butt') {
  94. return false;
  95. }
  96. if (cur_click !== null) {
  97. document.getElementById('canvas').style.display = 'none';
  98. cur_click.style.zIndex = 2;
  99. }
  100. }
  101. function MouseMove (e) {
  102. if (e.preventDefault) {
  103. e.preventDefault();
  104. }
  105. var new_dx = isIE ? e.clientX + document.body.scrollLeft : e.pageX;
  106. var new_dy = isIE ? e.clientY + document.body.scrollTop : e.pageY;
  107. var delta_x = Glob_X - new_dx;
  108. var delta_y = Glob_Y - new_dy;
  109. Glob_X = new_dx;
  110. Glob_Y = new_dy;
  111. if (cur_click !== null) {
  112. MarkUnsaved();
  113. var $cur_click = $(cur_click);
  114. var cur_x = parseFloat($cur_click.attr('data-left') || $cur_click.css('left'));
  115. var cur_y = parseFloat($cur_click.attr('data-top') || $cur_click.css('top'));
  116. var new_x = cur_x - delta_x;
  117. var new_y = cur_y - delta_y;
  118. dx = new_dx;
  119. dy = new_dy;
  120. $cur_click.attr('data-left', new_x);
  121. $cur_click.attr('data-top', new_y);
  122. if (ON_grid) {
  123. new_x = parseInt(new_x / grid_size) * grid_size;
  124. new_y = parseInt(new_y / grid_size) * grid_size;
  125. }
  126. $cur_click.css('left', new_x + 'px');
  127. $cur_click.css('top', new_y + 'px');
  128. } else if (layer_menu_cur_click) {
  129. dx = new_dx;
  130. dy = new_dy;
  131. if (menu_moved) {
  132. delta_x = -delta_x;
  133. }
  134. var $layer_menu = $('#layer_menu');
  135. var new_width = $layer_menu.width() + delta_x;
  136. if (new_width < 150) {
  137. new_width = 150;
  138. } else {
  139. dx = e.pageX;
  140. }
  141. $layer_menu.width(new_width);
  142. }
  143. if (ON_relation || ON_display_field) {
  144. document.getElementById('designer_hint').style.left = (Glob_X + 20) + 'px';
  145. document.getElementById('designer_hint').style.top = (Glob_Y + 20) + 'px';
  146. }
  147. }
  148. function MouseUp (e) {
  149. if (cur_click !== null) {
  150. document.getElementById('canvas').style.display = 'inline-block';
  151. Re_load();
  152. cur_click.style.zIndex = 1;
  153. cur_click = null;
  154. }
  155. layer_menu_cur_click = 0;
  156. // window.releaseEvents(Event.MOUSEMOVE);
  157. }
  158. // ------------------------------------------------------------------------------
  159. // ------------------------------------------------------------------------------
  160. // ------------------------------------------------------------------------------
  161. // function ToInt(s)
  162. // {
  163. // return s.substring(0,s.length-2)*1; //re = /(\d+)\w*/; newstr = str.replace(re, "$1");
  164. // }
  165. function Canvas_pos () {
  166. canvas_width = document.getElementById('canvas').width = osn_tab_width - 3;
  167. canvas_height = document.getElementById('canvas').height = osn_tab_height - 3;
  168. if (isIE) {
  169. document.getElementById('canvas').style.width = ((osn_tab_width - 3) ? (osn_tab_width - 3) : 0) + 'px';
  170. document.getElementById('canvas').style.height = ((osn_tab_height - 3) ? (osn_tab_height - 3) : 0) + 'px';
  171. }
  172. }
  173. function Osn_tab_pos () {
  174. osn_tab_width = parseInt(document.getElementById('osn_tab').style.width, 10);
  175. osn_tab_height = parseInt(document.getElementById('osn_tab').style.height, 10);
  176. }
  177. function setDefaultValuesFromSavedState () {
  178. if ($('#angular_direct_button').attr('class') === 'M_butt') {
  179. ON_angular_direct = 0;
  180. } else {
  181. ON_angular_direct = 1;
  182. }
  183. Angular_direct();
  184. if ($('#grid_button').attr('class') === 'M_butt') {
  185. ON_grid = 1;
  186. } else {
  187. ON_grid = 0;
  188. }
  189. Grid();
  190. var $relLineInvert = $('#relLineInvert');
  191. if ($relLineInvert.attr('class') === 'M_butt') {
  192. show_relation_lines = false;
  193. $relLineInvert.attr('class', 'M_butt');
  194. } else {
  195. show_relation_lines = true;
  196. $relLineInvert.attr('class', 'M_butt_Selected_down');
  197. }
  198. Relation_lines_invert();
  199. if ($('#pin_Text').attr('class') === 'M_butt_Selected_down') {
  200. always_show_text = true;
  201. Show_text();
  202. } else {
  203. always_show_text = false;
  204. }
  205. var $key_SB_all = $('#key_SB_all');
  206. if ($key_SB_all.attr('class') === 'M_butt_Selected_down') {
  207. $key_SB_all.click();
  208. $key_SB_all.toggleClass('M_butt_Selected_down');
  209. $key_SB_all.toggleClass('M_butt');
  210. }
  211. var $key_Left_Right = $('#key_Left_Right');
  212. if ($key_Left_Right.attr('class') === 'M_butt_Selected_down') {
  213. $key_Left_Right.click();
  214. }
  215. }
  216. function Main () {
  217. // ---CROSS
  218. document.getElementById('layer_menu').style.top = -1000 + 'px'; // fast scroll
  219. // sm_x += document.getElementById('osn_tab').offsetLeft;
  220. // sm_y += document.getElementById('osn_tab').offsetTop;
  221. Osn_tab_pos();
  222. Canvas_pos();
  223. Small_tab_refresh();
  224. Re_load();
  225. setDefaultValuesFromSavedState();
  226. id_hint = document.getElementById('designer_hint');
  227. if (isIE) {
  228. General_scroll();
  229. }
  230. }
  231. // -------------------------------- new -----------------------------------------
  232. function Rezize_osn_tab () {
  233. var max_X = 0;
  234. var max_Y = 0;
  235. for (var key in j_tabs) {
  236. var k_x = parseInt(document.getElementById(key).style.left, 10) + document.getElementById(key).offsetWidth;
  237. var k_y = parseInt(document.getElementById(key).style.top, 10) + document.getElementById(key).offsetHeight;
  238. max_X = max_X < k_x ? k_x : max_X;
  239. max_Y = max_Y < k_y ? k_y : max_Y;
  240. }
  241. osn_tab_width = max_X + 50;
  242. osn_tab_height = max_Y + 50;
  243. Canvas_pos();
  244. document.getElementById('osn_tab').style.width = osn_tab_width + 'px';
  245. document.getElementById('osn_tab').style.height = osn_tab_height + 'px';
  246. }
  247. // ------------------------------------------------------------------------------
  248. /**
  249. * refreshes display, must be called after state changes
  250. */
  251. function Re_load () {
  252. Rezize_osn_tab();
  253. var n;
  254. var x1;
  255. var x2;
  256. var a = [];
  257. var K;
  258. var key;
  259. var key2;
  260. var key3;
  261. Clear();
  262. for (K in contr) {
  263. for (key in contr[K]) {
  264. // contr name
  265. for (key2 in contr[K][key]) {
  266. // table name
  267. for (key3 in contr[K][key][key2]) {
  268. // field name
  269. if (!document.getElementById('check_vis_' + key2).checked ||
  270. !document.getElementById('check_vis_' + contr[K][key][key2][key3][0]).checked) {
  271. // if hide
  272. continue;
  273. }
  274. var x1_left = document.getElementById(key2).offsetLeft + 1;
  275. var x1_right = x1_left + document.getElementById(key2).offsetWidth;
  276. var x2_left = document.getElementById(contr[K][key][key2][key3][0]).offsetLeft;
  277. var x2_right = x2_left + document.getElementById(contr[K][key][key2][key3][0]).offsetWidth;
  278. a[0] = Math.abs(x1_left - x2_left);
  279. a[1] = Math.abs(x1_left - x2_right);
  280. a[2] = Math.abs(x1_right - x2_left);
  281. a[3] = Math.abs(x1_right - x2_right);
  282. n = s_left = s_right = 0;
  283. for (var i = 1; i < 4; i++) {
  284. if (a[n] > a[i]) {
  285. n = i;
  286. }
  287. }
  288. if (n === 1) {
  289. x1 = x1_left - sm_s;
  290. x2 = x2_right + sm_s;
  291. if (x1 < x2) {
  292. n = 0;
  293. }
  294. }
  295. if (n === 2) {
  296. x1 = x1_right + sm_s;
  297. x2 = x2_left - sm_s;
  298. if (x1 > x2) {
  299. n = 0;
  300. }
  301. }
  302. if (n === 3) {
  303. x1 = x1_right + sm_s;
  304. x2 = x2_right + sm_s;
  305. s_right = 1;
  306. }
  307. if (n === 0) {
  308. x1 = x1_left - sm_s;
  309. x2 = x2_left - sm_s;
  310. s_left = 1;
  311. }
  312. var row_offset_top = 0;
  313. var tab_hide_button = document.getElementById('id_hide_tbody_' + key2);
  314. if (tab_hide_button.innerHTML === 'v') {
  315. var fromColumn = document.getElementById(key2 + '.' + key3);
  316. if (fromColumn) {
  317. row_offset_top = fromColumn.offsetTop;
  318. } else {
  319. continue;
  320. }
  321. }
  322. var y1 = document.getElementById(key2).offsetTop +
  323. row_offset_top +
  324. height_field;
  325. row_offset_top = 0;
  326. tab_hide_button = document.getElementById('id_hide_tbody_' + contr[K][key][key2][key3][0]);
  327. if (tab_hide_button.innerHTML === 'v') {
  328. var toColumn = document.getElementById(contr[K][key][key2][key3][0] +
  329. '.' + contr[K][key][key2][key3][1]);
  330. if (toColumn) {
  331. row_offset_top = toColumn.offsetTop;
  332. } else {
  333. continue;
  334. }
  335. }
  336. var y2 =
  337. document.getElementById(contr[K][key][key2][key3][0]).offsetTop +
  338. row_offset_top +
  339. height_field;
  340. var osn_tab = document.getElementById('osn_tab');
  341. Line0(
  342. x1 + osn_tab.offsetLeft,
  343. y1 - osn_tab.offsetTop,
  344. x2 + osn_tab.offsetLeft,
  345. y2 - osn_tab.offsetTop,
  346. getColorByTarget(contr[K][key][key2][key3][0] + '.' + contr[K][key][key2][key3][1])
  347. );
  348. }
  349. }
  350. }
  351. }
  352. }
  353. /**
  354. * draws a line from x1:y1 to x2:y2 with color
  355. */
  356. function Line (x1, y1, x2, y2, color_line) {
  357. var canvas = document.getElementById('canvas');
  358. var ctx = canvas.getContext('2d');
  359. ctx.strokeStyle = color_line;
  360. ctx.lineWidth = 1;
  361. ctx.beginPath();
  362. ctx.moveTo(x1, y1);
  363. ctx.lineTo(x2, y2);
  364. ctx.stroke();
  365. }
  366. /**
  367. * draws a relation/constraint line, whether angular or not
  368. */
  369. function Line0 (x1, y1, x2, y2, color_line) {
  370. if (! show_relation_lines) {
  371. return;
  372. }
  373. Circle(x1, y1, 3, 3, color_line);
  374. Rect(x2 - 1, y2 - 2, 4, 4, color_line);
  375. if (ON_angular_direct) {
  376. Line2(x1, y1, x2, y2, color_line);
  377. } else {
  378. Line3(x1, y1, x2, y2, color_line);
  379. }
  380. }
  381. /**
  382. * draws a angular relation/constraint line
  383. */
  384. function Line2 (x1, y1, x2, y2, color_line) {
  385. var x1_ = x1;
  386. var x2_ = x2;
  387. if (s_right) {
  388. x1_ += sm_add;
  389. x2_ += sm_add;
  390. } else if (s_left) {
  391. x1_ -= sm_add;
  392. x2_ -= sm_add;
  393. } else if (x1 < x2) {
  394. x1_ += sm_add;
  395. x2_ -= sm_add;
  396. } else {
  397. x1_ -= sm_add;
  398. x2_ += sm_add;
  399. }
  400. Line(x1, y1, x1_, y1, color_line);
  401. Line(x2, y2, x2_, y2, color_line);
  402. Line(x1_, y1, x2_, y2, color_line);
  403. }
  404. /**
  405. * draws a relation/constraint line
  406. */
  407. function Line3 (x1, y1, x2, y2, color_line) {
  408. var x1_ = x1;
  409. var x2_ = x2;
  410. if (s_right) {
  411. if (x1 < x2) {
  412. x1_ += x2 - x1 + sm_add;
  413. x2_ += sm_add;
  414. } else {
  415. x2_ += x1 - x2 + sm_add;
  416. x1_ += sm_add;
  417. }
  418. Line(x1, y1, x1_, y1, color_line);
  419. Line(x2, y2, x2_, y2, color_line);
  420. Line(x1_, y1, x2_, y2, color_line);
  421. return;
  422. }
  423. if (s_left) {
  424. if (x1 < x2) {
  425. x2_ -= x2 - x1 + sm_add;
  426. x1_ -= sm_add;
  427. } else {
  428. x1_ -= x1 - x2 + sm_add;
  429. x2_ -= sm_add;
  430. }
  431. Line(x1, y1, x1_, y1, color_line);
  432. Line(x2, y2, x2_, y2, color_line);
  433. Line(x1_, y1, x2_, y2, color_line);
  434. return;
  435. }
  436. var x_s = (x1 + x2) / 2;
  437. Line(x1, y1, x_s, y1, color_line);
  438. Line(x_s, y2, x2, y2, color_line);
  439. Line(x_s, y1, x_s, y2, color_line);
  440. }
  441. function Circle (x, y, r, w, color) {
  442. var ctx = document.getElementById('canvas').getContext('2d');
  443. ctx.beginPath();
  444. ctx.moveTo(x, y);
  445. ctx.lineWidth = w;
  446. ctx.strokeStyle = color;
  447. ctx.arc(x, y, r, 0, 2 * Math.PI, true);
  448. ctx.stroke();
  449. }
  450. function Clear () {
  451. var canvas = document.getElementById('canvas');
  452. var ctx = canvas.getContext('2d');
  453. ctx.clearRect(0, 0, canvas_width, canvas_height);
  454. }
  455. function Rect (x1, y1, w, h, color) {
  456. var ctx = document.getElementById('canvas').getContext('2d');
  457. ctx.fillStyle = color;
  458. ctx.fillRect(x1, y1, w, h);
  459. }
  460. // --------------------------- FULLSCREEN -------------------------------------
  461. function Toggle_fullscreen () {
  462. var value_sent = '';
  463. var $img = $('#toggleFullscreen').find('img');
  464. var $span = $img.siblings('span');
  465. var $content = $('#page_content');
  466. if (! $content.fullScreen()) {
  467. $img.attr('src', $img.data('exit'))
  468. .attr('title', $span.data('exit'));
  469. $span.text($span.data('exit'));
  470. $content
  471. .addClass('content_fullscreen')
  472. .css({ 'width': screen.width - 5, 'height': screen.height - 5 });
  473. value_sent = 'on';
  474. $content.fullScreen(true);
  475. } else {
  476. $img.attr('src', $img.data('enter'))
  477. .attr('title', $span.data('enter'));
  478. $span.text($span.data('enter'));
  479. $content.fullScreen(false);
  480. value_sent = 'off';
  481. }
  482. saveValueInConfig('full_screen', value_sent);
  483. }
  484. function addTableToTablesList (index, table_dom) {
  485. var db = $(table_dom).find('.small_tab_pref').attr('db');
  486. var table = $(table_dom).find('.small_tab_pref').attr('table_name');
  487. var db_encoded = $(table_dom).find('.small_tab_pref').attr('db_url');
  488. var table_encoded = $(table_dom).find('.small_tab_pref').attr('table_name_url');
  489. var $new_table_line = $('<tr>' +
  490. ' <td title="' + PMA_messages.strStructure + '"' +
  491. ' width="1px"' +
  492. ' class="L_butt2_1">' +
  493. ' <img alt=""' +
  494. ' db="' + db_encoded + '"' +
  495. ' table_name="' + table_encoded + '"' +
  496. ' class="scroll_tab_struct"' +
  497. ' src="' + pmaThemeImage + 'designer/exec.png"/>' +
  498. ' </td>' +
  499. ' <td width="1px">' +
  500. ' <input class="scroll_tab_checkbox"' +
  501. ' title="' + PMA_messages.strHide + '"' +
  502. ' id="check_vis_' + db_encoded + '.' + table_encoded + '"' +
  503. ' style="margin:0;"' +
  504. ' type="checkbox"' +
  505. ' value="' + db_encoded + '.' + table_encoded + '"' +
  506. ' checked="checked"' +
  507. ' />' +
  508. ' </td>' +
  509. ' <td class="designer_Tabs"' +
  510. ' designer_url_table_name="' + db_encoded + '.' + table_encoded + '">' + $('<div/>').text(db + '.' + table).html() + '</td>' +
  511. '</tr>');
  512. $('#id_scroll_tab table').first().append($new_table_line);
  513. $($new_table_line).find('.scroll_tab_struct').click(function () {
  514. Start_tab_upd(db, table);
  515. });
  516. $($new_table_line).on('click', '.designer_Tabs2,.designer_Tabs', function () {
  517. Select_tab($(this).attr('designer_url_table_name'));
  518. });
  519. $($new_table_line).find('.scroll_tab_checkbox').click(function () {
  520. VisibleTab(this,$(this).val());
  521. });
  522. var $tables_counter = $('#tables_counter');
  523. $tables_counter.text(parseInt($tables_counter.text(), 10) + 1);
  524. }
  525. function Add_Other_db_tables () {
  526. var button_options = {};
  527. button_options[PMA_messages.strGo] = function () {
  528. var db = $('#add_table_from').val();
  529. var table = $('#add_table').val();
  530. // Check if table already imported or not.
  531. var $table = $('[id="' + encodeURIComponent(db) + '.' + encodeURIComponent(table) + '"]');
  532. if ($table.length !== 0) {
  533. PMA_ajaxShowMessage(
  534. PMA_sprintf(PMA_messages.strTableAlreadyExists, db + '.' + table),
  535. undefined,
  536. 'error'
  537. );
  538. return;
  539. }
  540. $.post('db_designer.php', {
  541. 'ajax_request' : true,
  542. 'dialog' : 'add_table',
  543. 'db' : db,
  544. 'table' : table,
  545. 'server': PMA_commonParams.get('server')
  546. }, function (data) {
  547. var $newTableDom = $(data.message);
  548. $newTableDom.find('a').first().remove();
  549. var dbEncoded = $($newTableDom).find('.small_tab_pref').attr('db_url');
  550. var tableEncoded = $($newTableDom).find('.small_tab_pref').attr('table_name_url');
  551. if (typeof dbEncoded === 'string' && typeof tableEncoded === 'string' ) { // Do not try to add if attr not found !
  552. $('#container-form').append($newTableDom);
  553. enableTableEvents(null, $newTableDom);
  554. addTableToTablesList(null, $newTableDom);
  555. j_tabs[dbEncoded + '.' + tableEncoded] = 1;
  556. MarkUnsaved();
  557. }
  558. });
  559. $(this).dialog('close');
  560. };
  561. button_options[PMA_messages.strCancel] = function () {
  562. $(this).dialog('close');
  563. };
  564. var $select_db = $('<select id="add_table_from"></select>');
  565. $select_db.append('<option value="">' + PMA_messages.strNone + '</option>');
  566. var $select_table = $('<select id="add_table"></select>');
  567. $select_table.append('<option value="">' + PMA_messages.strNone + '</option>');
  568. $.post('sql.php', {
  569. 'ajax_request' : true,
  570. 'sql_query' : 'SHOW databases;',
  571. 'server': PMA_commonParams.get('server')
  572. }, function (data) {
  573. $(data.message).find('table.table_results.data.ajax').find('td.data').each(function () {
  574. var val = $(this)[0].innerText;
  575. $select_db.append($('<option></option>').val(val).text(val));
  576. });
  577. });
  578. var $form = $('<form action="" class="ajax"></form>')
  579. .append($select_db).append($select_table);
  580. $('<div id="page_add_tables_dialog"></div>')
  581. .append($form)
  582. .dialog({
  583. appendTo: '#page_content',
  584. title: PMA_messages.strAddTables,
  585. width: 500,
  586. modal: true,
  587. buttons: button_options,
  588. close: function () {
  589. $(this).remove();
  590. }
  591. });
  592. $('#add_table_from').change(function () {
  593. if ($(this).val()) {
  594. var db_name = $(this).val();
  595. var sql_query = 'SHOW tables;';
  596. $.post('sql.php', {
  597. 'ajax_request' : true,
  598. 'sql_query': sql_query,
  599. 'db' : db_name,
  600. 'server': PMA_commonParams.get('server')
  601. }, function (data) {
  602. $select_table.html('');
  603. var rows = $(data.message).find('table.table_results.data.ajax').find('td.data');
  604. if (rows.length === 0) {
  605. $select_table.append('<option value="">' + PMA_messages.strNone + '</option>');
  606. }
  607. rows.each(function () {
  608. var val = $(this)[0].innerText;
  609. $select_table.append($('<option></option>').val(val).text(val));
  610. });
  611. });
  612. }
  613. });
  614. }
  615. // ------------------------------ NEW ------------------------------------------
  616. function New () {
  617. Prompt_to_save_current_page(function () {
  618. Load_page(-1);
  619. });
  620. }
  621. // ------------------------------ SAVE ------------------------------------------
  622. // (del?) no for pdf
  623. function Save (url) {
  624. for (var key in j_tabs) {
  625. document.getElementById('t_x_' + key + '_').value = parseInt(document.getElementById(key).style.left, 10);
  626. document.getElementById('t_y_' + key + '_').value = parseInt(document.getElementById(key).style.top, 10);
  627. document.getElementById('t_v_' + key + '_').value = document.getElementById('id_tbody_' + key).style.display === 'none' ? 0 : 1;
  628. document.getElementById('t_h_' + key + '_').value = document.getElementById('check_vis_' + key).checked ? 1 : 0;
  629. }
  630. document.getElementById('container-form').action = url;
  631. $('#container-form').submit();
  632. }
  633. function Get_url_pos (forceString) {
  634. if (designer_tables_enabled || forceString) {
  635. var poststr = '';
  636. var argsep = PMA_commonParams.get('arg_separator');
  637. var i = 1;
  638. for (var key in j_tabs) {
  639. poststr += argsep + 't_x[' + i + ']=' + parseInt(document.getElementById(key).style.left, 10);
  640. poststr += argsep + 't_y[' + i + ']=' + parseInt(document.getElementById(key).style.top, 10);
  641. poststr += argsep + 't_v[' + i + ']=' + (document.getElementById('id_tbody_' + key).style.display === 'none' ? 0 : 1);
  642. poststr += argsep + 't_h[' + i + ']=' + (document.getElementById('check_vis_' + key).checked ? 1 : 0);
  643. poststr += argsep + 't_db[' + i + ']=' + $(document.getElementById(key)).attr('db_url');
  644. poststr += argsep + 't_tbl[' + i + ']=' + $(document.getElementById(key)).attr('table_name_url');
  645. i++;
  646. }
  647. return poststr;
  648. } else {
  649. var coords = [];
  650. for (var key in j_tabs) {
  651. if (document.getElementById('check_vis_' + key).checked) {
  652. var x = parseInt(document.getElementById(key).style.left, 10);
  653. var y = parseInt(document.getElementById(key).style.top, 10);
  654. var tbCoords = new TableCoordinate(
  655. $(document.getElementById(key)).attr('db_url'),
  656. $(document.getElementById(key)).attr('table_name_url'),
  657. -1, x, y);
  658. coords.push(tbCoords);
  659. }
  660. }
  661. return coords;
  662. }
  663. }
  664. function Save2 (callback) {
  665. if (designer_tables_enabled) {
  666. var argsep = PMA_commonParams.get('arg_separator');
  667. var poststr = 'operation=savePage' + argsep + 'save_page=same' + argsep + 'ajax_request=true';
  668. poststr += argsep + 'server=' + server + argsep + 'db=' + encodeURIComponent(db) + argsep + 'selected_page=' + selected_page;
  669. poststr += Get_url_pos();
  670. var $msgbox = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
  671. $.post('db_designer.php', poststr, function (data) {
  672. if (data.success === false) {
  673. PMA_ajaxShowMessage(data.error, false);
  674. } else {
  675. PMA_ajaxRemoveMessage($msgbox);
  676. PMA_ajaxShowMessage(PMA_messages.strModificationSaved);
  677. MarkSaved();
  678. if (typeof callback !== 'undefined') {
  679. callback();
  680. }
  681. }
  682. });
  683. } else {
  684. var name = $('#page_name').html().trim();
  685. Save_to_selected_page(db, selected_page, name, Get_url_pos(), function (page) {
  686. MarkSaved();
  687. if (typeof callback !== 'undefined') {
  688. callback();
  689. }
  690. });
  691. }
  692. }
  693. function submitSaveDialogAndClose (callback) {
  694. var $form = $('#save_page');
  695. var name = $form.find('input[name="selected_value"]').val().trim();
  696. if (name === '') {
  697. PMA_ajaxShowMessage(PMA_messages.strEnterValidPageName, false);
  698. return;
  699. }
  700. $('#page_save_dialog').dialog('close');
  701. if (designer_tables_enabled) {
  702. var $msgbox = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
  703. PMA_prepareForAjaxRequest($form);
  704. $.post($form.attr('action'), $form.serialize() + Get_url_pos(), function (data) {
  705. if (data.success === false) {
  706. PMA_ajaxShowMessage(data.error, false);
  707. } else {
  708. PMA_ajaxRemoveMessage($msgbox);
  709. MarkSaved();
  710. if (data.id) {
  711. selected_page = data.id;
  712. }
  713. $('#page_name').text(name);
  714. if (typeof callback !== 'undefined') {
  715. callback();
  716. }
  717. }
  718. });
  719. } else {
  720. Save_to_new_page(db, name, Get_url_pos(), function (page) {
  721. MarkSaved();
  722. if (page.pg_nr) {
  723. selected_page = page.pg_nr;
  724. }
  725. $('#page_name').text(page.page_descr);
  726. if (typeof callback !== 'undefined') {
  727. callback();
  728. }
  729. });
  730. }
  731. }
  732. function Save3 (callback) {
  733. if (selected_page !== -1) {
  734. Save2(callback);
  735. } else {
  736. var button_options = {};
  737. button_options[PMA_messages.strGo] = function () {
  738. var $form = $('#save_page');
  739. $form.submit();
  740. };
  741. button_options[PMA_messages.strCancel] = function () {
  742. $(this).dialog('close');
  743. };
  744. var $form = $('<form action="db_designer.php" method="post" name="save_page" id="save_page" class="ajax"></form>')
  745. .append('<input type="hidden" name="server" value="' + server + '" />')
  746. .append($('<input type="hidden" name="db" />').val(db))
  747. .append('<input type="hidden" name="operation" value="savePage" />')
  748. .append('<input type="hidden" name="save_page" value="new" />')
  749. .append('<label for="selected_value">' + PMA_messages.strPageName +
  750. '</label>:<input type="text" name="selected_value" />');
  751. $form.on('submit', function (e) {
  752. e.preventDefault();
  753. submitSaveDialogAndClose(callback);
  754. });
  755. $('<div id="page_save_dialog"></div>')
  756. .append($form)
  757. .dialog({
  758. appendTo: '#page_content',
  759. title: PMA_messages.strSavePage,
  760. width: 300,
  761. modal: true,
  762. buttons: button_options,
  763. close: function () {
  764. $(this).remove();
  765. }
  766. });
  767. }
  768. }
  769. // ------------------------------ EDIT PAGES ------------------------------------------
  770. function Edit_pages () {
  771. Prompt_to_save_current_page(function () {
  772. var button_options = {};
  773. button_options[PMA_messages.strGo] = function () {
  774. var $form = $('#edit_delete_pages');
  775. var selected = $form.find('select[name="selected_page"]').val();
  776. if (selected === '0') {
  777. PMA_ajaxShowMessage(PMA_messages.strSelectPage, 2000);
  778. return;
  779. }
  780. $(this).dialog('close');
  781. Load_page(selected);
  782. };
  783. button_options[PMA_messages.strCancel] = function () {
  784. $(this).dialog('close');
  785. };
  786. var $msgbox = PMA_ajaxShowMessage();
  787. $.post('db_designer.php', {
  788. 'ajax_request': true,
  789. 'server': server,
  790. 'db': db,
  791. 'dialog': 'edit'
  792. }, function (data) {
  793. if (data.success === false) {
  794. PMA_ajaxShowMessage(data.error, false);
  795. } else {
  796. PMA_ajaxRemoveMessage($msgbox);
  797. if (! designer_tables_enabled) {
  798. Create_page_list(db, function (options) {
  799. $('#selected_page').append(options);
  800. });
  801. }
  802. $('<div id="page_edit_dialog"></div>')
  803. .append(data.message)
  804. .dialog({
  805. appendTo: '#page_content',
  806. title: PMA_messages.strOpenPage,
  807. width: 350,
  808. modal: true,
  809. buttons: button_options,
  810. close: function () {
  811. $(this).remove();
  812. }
  813. });
  814. }
  815. }); // end $.post()
  816. });
  817. }
  818. // ----------------------------- DELETE PAGES ---------------------------------------
  819. function Delete_pages () {
  820. var button_options = {};
  821. button_options[PMA_messages.strGo] = function () {
  822. var $form = $('#edit_delete_pages');
  823. var selected = $form.find('select[name="selected_page"]').val();
  824. if (selected === '0') {
  825. PMA_ajaxShowMessage(PMA_messages.strSelectPage, 2000);
  826. return;
  827. }
  828. var $msgbox = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
  829. var deleting_current_page = selected === selected_page;
  830. PMA_prepareForAjaxRequest($form);
  831. if (designer_tables_enabled) {
  832. $.post($form.attr('action'), $form.serialize(), function (data) {
  833. if (data.success === false) {
  834. PMA_ajaxShowMessage(data.error, false);
  835. } else {
  836. PMA_ajaxRemoveMessage($msgbox);
  837. if (deleting_current_page) {
  838. Load_page(null);
  839. } else {
  840. PMA_ajaxShowMessage(PMA_messages.strSuccessfulPageDelete);
  841. }
  842. }
  843. }); // end $.post()
  844. } else {
  845. Delete_page(selected, function (success) {
  846. if (! success) {
  847. PMA_ajaxShowMessage('Error', false);
  848. } else {
  849. PMA_ajaxRemoveMessage($msgbox);
  850. if (deleting_current_page) {
  851. Load_page(null);
  852. } else {
  853. PMA_ajaxShowMessage(PMA_messages.strSuccessfulPageDelete);
  854. }
  855. }
  856. });
  857. }
  858. $(this).dialog('close');
  859. };
  860. button_options[PMA_messages.strCancel] = function () {
  861. $(this).dialog('close');
  862. };
  863. var $msgbox = PMA_ajaxShowMessage();
  864. $.post('db_designer.php', {
  865. 'ajax_request': true,
  866. 'server': server,
  867. 'db': db,
  868. 'dialog': 'delete'
  869. }, function (data) {
  870. if (data.success === false) {
  871. PMA_ajaxShowMessage(data.error, false);
  872. } else {
  873. PMA_ajaxRemoveMessage($msgbox);
  874. if (! designer_tables_enabled) {
  875. Create_page_list(db, function (options) {
  876. $('#selected_page').append(options);
  877. });
  878. }
  879. $('<div id="page_delete_dialog"></div>')
  880. .append(data.message)
  881. .dialog({
  882. appendTo: '#page_content',
  883. title: PMA_messages.strDeletePage,
  884. width: 350,
  885. modal: true,
  886. buttons: button_options,
  887. close: function () {
  888. $(this).remove();
  889. }
  890. });
  891. }
  892. }); // end $.post()
  893. }
  894. // ------------------------------ SAVE AS PAGES ---------------------------------------
  895. function Save_as () {
  896. var button_options = {};
  897. button_options[PMA_messages.strGo] = function () {
  898. var $form = $('#save_as_pages');
  899. var selected_value = $form.find('input[name="selected_value"]').val().trim();
  900. var $selected_page = $form.find('select[name="selected_page"]');
  901. var choice = $form.find('input[name="save_page"]:checked').val();
  902. var name = '';
  903. if (choice === 'same') {
  904. if ($selected_page.val() === '0') {
  905. PMA_ajaxShowMessage(PMA_messages.strSelectPage, 2000);
  906. return;
  907. }
  908. name = $selected_page.find('option:selected').text();
  909. } else if (choice === 'new') {
  910. if (selected_value === '') {
  911. PMA_ajaxShowMessage(PMA_messages.strEnterValidPageName, 2000);
  912. return;
  913. }
  914. name = selected_value;
  915. }
  916. var $msgbox = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
  917. if (designer_tables_enabled) {
  918. PMA_prepareForAjaxRequest($form);
  919. $.post($form.attr('action'), $form.serialize() + Get_url_pos(), function (data) {
  920. if (data.success === false) {
  921. PMA_ajaxShowMessage(data.error, false);
  922. } else {
  923. PMA_ajaxRemoveMessage($msgbox);
  924. MarkSaved();
  925. if (data.id) {
  926. selected_page = data.id;
  927. }
  928. Load_page(selected_page);
  929. }
  930. }); // end $.post()
  931. } else {
  932. if (choice === 'same') {
  933. var selected_page_id = $selected_page.find('option:selected').val();
  934. Save_to_selected_page(db, selected_page_id, name, Get_url_pos(), function (page) {
  935. PMA_ajaxRemoveMessage($msgbox);
  936. MarkSaved();
  937. if (page.pg_nr) {
  938. selected_page = page.pg_nr;
  939. }
  940. Load_page(selected_page);
  941. });
  942. } else if (choice === 'new') {
  943. Save_to_new_page(db, name, Get_url_pos(), function (page) {
  944. PMA_ajaxRemoveMessage($msgbox);
  945. MarkSaved();
  946. if (page.pg_nr) {
  947. selected_page = page.pg_nr;
  948. }
  949. Load_page(selected_page);
  950. });
  951. }
  952. }
  953. $(this).dialog('close');
  954. };
  955. button_options[PMA_messages.strCancel] = function () {
  956. $(this).dialog('close');
  957. };
  958. var $msgbox = PMA_ajaxShowMessage();
  959. $.post('db_designer.php', {
  960. 'ajax_request': true,
  961. 'server': server,
  962. 'db': db,
  963. 'dialog': 'save_as'
  964. }, function (data) {
  965. if (data.success === false) {
  966. PMA_ajaxShowMessage(data.error, false);
  967. } else {
  968. PMA_ajaxRemoveMessage($msgbox);
  969. if (! designer_tables_enabled) {
  970. Create_page_list(db, function (options) {
  971. $('#selected_page').append(options);
  972. });
  973. }
  974. $('<div id="page_save_as_dialog"></div>')
  975. .append(data.message)
  976. .dialog({
  977. appendTo: '#page_content',
  978. title: PMA_messages.strSavePageAs,
  979. width: 450,
  980. modal: true,
  981. buttons: button_options,
  982. close: function () {
  983. $(this).remove();
  984. }
  985. });
  986. // select current page by default
  987. if (selected_page !== -1) {
  988. $('select[name="selected_page"]').val(selected_page);
  989. }
  990. }
  991. }); // end $.post()
  992. }
  993. function Prompt_to_save_current_page (callback) {
  994. if (_change === 1 || selected_page === -1) {
  995. var button_options = {};
  996. button_options[PMA_messages.strYes] = function () {
  997. $(this).dialog('close');
  998. Save3(callback);
  999. };
  1000. button_options[PMA_messages.strNo] = function () {
  1001. $(this).dialog('close');
  1002. callback();
  1003. };
  1004. button_options[PMA_messages.strCancel] = function () {
  1005. $(this).dialog('close');
  1006. };
  1007. $('<div id="prompt_save_dialog"></div>')
  1008. .append('<div>' + PMA_messages.strLeavingPage + '</div>')
  1009. .dialog({
  1010. appendTo: '#page_content',
  1011. title: PMA_messages.strSavePage,
  1012. width: 300,
  1013. modal: true,
  1014. buttons: button_options,
  1015. close: function () {
  1016. $(this).remove();
  1017. }
  1018. });
  1019. } else {
  1020. callback();
  1021. }
  1022. }
  1023. // ------------------------------ EXPORT PAGES ---------------------------------------
  1024. function Export_pages () {
  1025. var button_options = {};
  1026. button_options[PMA_messages.strGo] = function () {
  1027. $('#id_export_pages').submit();
  1028. $(this).dialog('close');
  1029. };
  1030. button_options[PMA_messages.strCancel] = function () {
  1031. $(this).dialog('close');
  1032. };
  1033. var $msgbox = PMA_ajaxShowMessage();
  1034. var argsep = PMA_commonParams.get('arg_separator');
  1035. $.post('db_designer.php', {
  1036. 'ajax_request': true,
  1037. 'server': server,
  1038. 'db': db,
  1039. 'dialog': 'export',
  1040. 'selected_page': selected_page
  1041. }, function (data) {
  1042. if (data.success === false) {
  1043. PMA_ajaxShowMessage(data.error, false);
  1044. } else {
  1045. PMA_ajaxRemoveMessage($msgbox);
  1046. var $form = $(data.message);
  1047. if (!designer_tables_enabled) {
  1048. $form.append('<input type="hidden" name="offline_export" value="true" />');
  1049. }
  1050. $.each(Get_url_pos(true).substring(1).split(argsep), function () {
  1051. var pair = this.split('=');
  1052. var input = $('<input type="hidden" />');
  1053. input.attr('name', pair[0]);
  1054. input.attr('value', pair[1]);
  1055. $form.append(input);
  1056. });
  1057. var $formatDropDown = $form.find('#plugins');
  1058. $formatDropDown.change(function () {
  1059. var format = $formatDropDown.val();
  1060. $form.find('.format_specific_options').hide();
  1061. $form.find('#' + format + '_options').show();
  1062. }).trigger('change');
  1063. $('<div id="page_export_dialog"></div>')
  1064. .append($form)
  1065. .dialog({
  1066. appendTo: '#page_content',
  1067. title: PMA_messages.strExportRelationalSchema,
  1068. width: 550,
  1069. modal: true,
  1070. buttons: button_options,
  1071. close: function () {
  1072. $(this).remove();
  1073. }
  1074. });
  1075. }
  1076. }); // end $.post()
  1077. }// end export pages
  1078. function Load_page (page) {
  1079. if (designer_tables_enabled) {
  1080. var param_page = '';
  1081. var argsep = PMA_commonParams.get('arg_separator');
  1082. if (page !== null) {
  1083. param_page = argsep + 'page=' + page;
  1084. }
  1085. $('<a href="db_designer.php?server=' + server + argsep + 'db=' + encodeURIComponent(db) + param_page + '"></a>')
  1086. .appendTo($('#page_content'))
  1087. .click();
  1088. } else {
  1089. if (page === null) {
  1090. Show_tables_in_landing_page(db);
  1091. } else if (page > -1) {
  1092. Load_HTML_for_page(page);
  1093. } else if (page === -1) {
  1094. Show_new_page_tables(true);
  1095. }
  1096. }
  1097. MarkSaved();
  1098. }
  1099. function Grid () {
  1100. var value_sent = '';
  1101. if (!ON_grid) {
  1102. ON_grid = 1;
  1103. value_sent = 'on';
  1104. document.getElementById('grid_button').className = 'M_butt_Selected_down';
  1105. } else {
  1106. document.getElementById('grid_button').className = 'M_butt';
  1107. ON_grid = 0;
  1108. value_sent = 'off';
  1109. }
  1110. saveValueInConfig('snap_to_grid', value_sent);
  1111. }
  1112. function Angular_direct () {
  1113. var value_sent = '';
  1114. if (ON_angular_direct) {
  1115. ON_angular_direct = 0;
  1116. value_sent = 'angular';
  1117. document.getElementById('angular_direct_button').className = 'M_butt_Selected_down';
  1118. } else {
  1119. ON_angular_direct = 1;
  1120. value_sent = 'direct';
  1121. document.getElementById('angular_direct_button').className = 'M_butt';
  1122. }
  1123. saveValueInConfig('angular_direct', value_sent);
  1124. Re_load();
  1125. }
  1126. function saveValueInConfig (index_sent, value_sent) {
  1127. $.post('db_designer.php',
  1128. { operation: 'save_setting_value', index: index_sent, ajax_request: true, server: server, value: value_sent },
  1129. function (data) {
  1130. if (data.success === false) {
  1131. PMA_ajaxShowMessage(data.error, false);
  1132. }
  1133. });
  1134. }
  1135. // ++++++++++++++++++++++++++++++ RELATION ++++++++++++++++++++++++++++++++++++++
  1136. function Start_relation () {
  1137. if (ON_display_field) {
  1138. return;
  1139. }
  1140. if (!ON_relation) {
  1141. document.getElementById('foreign_relation').style.display = '';
  1142. ON_relation = 1;
  1143. document.getElementById('designer_hint').innerHTML = PMA_messages.strSelectReferencedKey;
  1144. document.getElementById('designer_hint').style.display = 'block';
  1145. document.getElementById('rel_button').className = 'M_butt_Selected_down';
  1146. } else {
  1147. document.getElementById('designer_hint').innerHTML = '';
  1148. document.getElementById('designer_hint').style.display = 'none';
  1149. document.getElementById('rel_button').className = 'M_butt';
  1150. click_field = 0;
  1151. ON_relation = 0;
  1152. }
  1153. }
  1154. // table field
  1155. function Click_field (db, T, f, PK) {
  1156. PK = parseInt(PK);
  1157. var argsep = PMA_commonParams.get('arg_separator');
  1158. if (ON_relation) {
  1159. if (!click_field) {
  1160. // .style.display=='none' .style.display = 'none'
  1161. if (!PK) {
  1162. alert(PMA_messages.strPleaseSelectPrimaryOrUniqueKey);
  1163. return;// 0;
  1164. }// PK
  1165. if (j_tabs[db + '.' + T] !== 1) {
  1166. document.getElementById('foreign_relation').style.display = 'none';
  1167. }
  1168. click_field = 1;
  1169. link_relation = 'DB1=' + db + argsep + 'T1=' + T + argsep + 'F1=' + f;
  1170. document.getElementById('designer_hint').innerHTML = PMA_messages.strSelectForeignKey;
  1171. } else {
  1172. Start_relation(); // hidden hint...
  1173. if (j_tabs[db + '.' + T] !== 1 || !PK) {
  1174. document.getElementById('foreign_relation').style.display = 'none';
  1175. }
  1176. var left = Glob_X - (document.getElementById('layer_new_relation').offsetWidth >> 1);
  1177. document.getElementById('layer_new_relation').style.left = left + 'px';
  1178. var top = Glob_Y - document.getElementById('layer_new_relation').offsetHeight;
  1179. document.getElementById('layer_new_relation').style.top = top + 'px';
  1180. document.getElementById('layer_new_relation').style.display = 'block';
  1181. link_relation += argsep + 'DB2=' + db + argsep + 'T2=' + T + argsep + 'F2=' + f;
  1182. }
  1183. }
  1184. if (ON_display_field) {
  1185. var fieldNameToSend = decodeURIComponent(f);
  1186. var newDisplayFieldClass = 'tab_field';
  1187. var oldTabField = document.getElementById('id_tr_' + T + '.' + display_field[T]);
  1188. // if is display field
  1189. if (display_field[T] === f) {// The display field is already the one defined, user wants to remove it
  1190. newDisplayFieldClass = 'tab_field';
  1191. delete display_field[T];
  1192. if (oldTabField) {// Clear the style
  1193. // Set display field class on old item
  1194. oldTabField.className = 'tab_field';
  1195. }
  1196. fieldNameToSend = '';
  1197. } else {
  1198. newDisplayFieldClass = 'tab_field_3';
  1199. if (display_field[T]) { // Had a previous one, clear it
  1200. if (oldTabField) {
  1201. // Set display field class on old item
  1202. oldTabField.className = 'tab_field';
  1203. }
  1204. delete display_field[T];
  1205. }
  1206. display_field[T] = f;
  1207. var tabField = document.getElementById('id_tr_' + T + '.' + display_field[T]);
  1208. if (tabField) {
  1209. // Set new display field class
  1210. tabField.className = newDisplayFieldClass;
  1211. }
  1212. }
  1213. ON_display_field = 0;
  1214. document.getElementById('designer_hint').innerHTML = '';
  1215. document.getElementById('designer_hint').style.display = 'none';
  1216. document.getElementById('display_field_button').className = 'M_butt';
  1217. var $msgbox = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
  1218. $.post('db_designer.php',
  1219. { operation: 'setDisplayField', ajax_request: true, server: server, db: db, table: T, field: fieldNameToSend },
  1220. function (data) {
  1221. if (data.success === false) {
  1222. PMA_ajaxShowMessage(data.error, false);
  1223. } else {
  1224. PMA_ajaxRemoveMessage($msgbox);
  1225. PMA_ajaxShowMessage(PMA_messages.strModificationSaved);
  1226. }
  1227. });
  1228. }
  1229. }
  1230. function New_relation () {
  1231. document.getElementById('layer_new_relation').style.display = 'none';
  1232. var argsep = PMA_commonParams.get('arg_separator');
  1233. link_relation += argsep + 'server=' + server + argsep + 'db=' + db + argsep + 'db2=p';
  1234. link_relation += argsep + 'on_delete=' + document.getElementById('on_delete').value + argsep + 'on_update=' + document.getElementById('on_update').value;
  1235. link_relation += argsep + 'operation=addNewRelation' + argsep + 'ajax_request=true';
  1236. var $msgbox = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
  1237. $.post('db_designer.php', link_relation, function (data) {
  1238. if (data.success === false) {
  1239. PMA_ajaxShowMessage(data.error, false);
  1240. } else {
  1241. PMA_ajaxRemoveMessage($msgbox);
  1242. Load_page(selected_page);
  1243. }
  1244. }); // end $.post()
  1245. }
  1246. // -------------------------- create tables -------------------------------------
  1247. function Start_table_new () {
  1248. PMA_commonParams.set('table', '');
  1249. PMA_commonActions.refreshMain('tbl_create.php');
  1250. }
  1251. function Start_tab_upd (db, table) {
  1252. PMA_commonParams.set('db', db);
  1253. PMA_commonParams.set('table', table);
  1254. PMA_commonActions.refreshMain('tbl_structure.php');
  1255. }
  1256. // --------------------------- hide tables --------------------------------------
  1257. // max/min all tables
  1258. function Small_tab_all (id_this) {
  1259. var icon = id_this.children[0];
  1260. var value_sent = '';
  1261. if (icon.alt === 'v') {
  1262. $('.designer_tab .small_tab,.small_tab2').each(function(index, element) {
  1263. if ($(element).text() === 'v') {
  1264. Small_tab($(element).attr('table_name'), 0);
  1265. }
  1266. });
  1267. icon.alt = '>';
  1268. icon.src = icon.dataset.right;
  1269. value_sent = 'v';
  1270. } else {
  1271. $('.designer_tab .small_tab,.small_tab2').each(function(index, element) {
  1272. if ($(element).text() !== 'v') {
  1273. Small_tab($(element).attr('table_name'), 0);
  1274. }
  1275. });
  1276. icon.alt = 'v';
  1277. icon.src = icon.dataset.down;
  1278. value_sent = '>';
  1279. }
  1280. saveValueInConfig('small_big_all', value_sent);
  1281. $('#key_SB_all').toggleClass('M_butt_Selected_down');
  1282. $('#key_SB_all').toggleClass('M_butt');
  1283. Re_load();
  1284. }
  1285. // invert max/min all tables
  1286. function Small_tab_invert () {
  1287. $('.designer_tab .small_tab,.small_tab2').each(function(index, element) {
  1288. Small_tab($(element).attr('table_name'), 0);
  1289. });
  1290. Re_load();
  1291. }
  1292. function Relation_lines_invert () {
  1293. show_relation_lines = ! show_relation_lines;
  1294. saveValueInConfig('relation_lines', show_relation_lines);
  1295. $('#relLineInvert').toggleClass('M_butt_Selected_down');
  1296. $('#relLineInvert').toggleClass('M_butt');
  1297. Re_load();
  1298. }
  1299. function Small_tab_refresh () {
  1300. for (var key in j_tabs) {
  1301. if (document.getElementById('id_hide_tbody_' + key).innerHTML !== 'v') {
  1302. Small_tab(key, 0);
  1303. }
  1304. }
  1305. }
  1306. function Small_tab (t, re_load) {
  1307. var id = document.getElementById('id_tbody_' + t);
  1308. var id_this = document.getElementById('id_hide_tbody_' + t);
  1309. var id_t = document.getElementById(t);
  1310. if (id_this.innerHTML === 'v') {
  1311. // ---CROSS
  1312. id.style.display = 'none';
  1313. id_this.innerHTML = '>';
  1314. } else {
  1315. id.style.display = '';
  1316. id_this.innerHTML = 'v';
  1317. }
  1318. if (re_load) {
  1319. Re_load();
  1320. }
  1321. }
  1322. // ------------------------------------------------------------------------------
  1323. function Select_tab (t) {
  1324. var id_zag = document.getElementById('id_zag_' + t);
  1325. if (id_zag.className !== 'tab_zag_3') {
  1326. document.getElementById('id_zag_' + t).className = 'tab_zag_2';
  1327. } else {
  1328. document.getElementById('id_zag_' + t).className = 'tab_zag';
  1329. }
  1330. // ----------
  1331. var id_t = document.getElementById(t);
  1332. window.scrollTo(parseInt(id_t.style.left, 10) - 300, parseInt(id_t.style.top, 10) - 300);
  1333. setTimeout(
  1334. function () {
  1335. document.getElementById('id_zag_' + t).className = 'tab_zag';
  1336. },
  1337. 800
  1338. );
  1339. }
  1340. // ------------------------------------------------------------------------------
  1341. function Canvas_click (id, event) {
  1342. var n = 0;
  1343. var relation_name = 0;
  1344. var selected = 0;
  1345. var a = [];
  1346. var Key0;
  1347. var Key1;
  1348. var Key2;
  1349. var Key3;
  1350. var Key;
  1351. var x1;
  1352. var x2;
  1353. var K;
  1354. var key;
  1355. var key2;
  1356. var key3;
  1357. var Local_X = isIE ? event.clientX + document.body.scrollLeft : event.pageX;
  1358. var Local_Y = isIE ? event.clientY + document.body.scrollTop : event.pageY;
  1359. Local_X -= $('#osn_tab').offset().left;
  1360. Local_Y -= $('#osn_tab').offset().top;
  1361. Clear();
  1362. for (K in contr) {
  1363. for (key in contr[K]) {
  1364. for (key2 in contr[K][key]) {
  1365. for (key3 in contr[K][key][key2]) {
  1366. if (! document.getElementById('check_vis_' + key2).checked ||
  1367. ! document.getElementById('check_vis_' + contr[K][key][key2][key3][0]).checked) {
  1368. continue; // if hide
  1369. }
  1370. var x1_left = document.getElementById(key2).offsetLeft + 1;// document.getElementById(key2+"."+key3).offsetLeft;
  1371. var x1_right = x1_left + document.getElementById(key2).offsetWidth;
  1372. 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
  1373. var x2_right = x2_left + document.getElementById(contr[K][key][key2][key3][0]).offsetWidth;
  1374. a[0] = Math.abs(x1_left - x2_left);
  1375. a[1] = Math.abs(x1_left - x2_right);
  1376. a[2] = Math.abs(x1_right - x2_left);
  1377. a[3] = Math.abs(x1_right - x2_right);
  1378. n = s_left = s_right = 0;
  1379. for (var i = 1; i < 4; i++) {
  1380. if (a[n] > a[i]) {
  1381. n = i;
  1382. }
  1383. }
  1384. if (n === 1) {
  1385. x1 = x1_left - sm_s;
  1386. x2 = x2_right + sm_s;
  1387. if (x1 < x2) {
  1388. n = 0;
  1389. }
  1390. }
  1391. if (n === 2) {
  1392. x1 = x1_right + sm_s;
  1393. x2 = x2_left - sm_s;
  1394. if (x1 > x2) {
  1395. n = 0;
  1396. }
  1397. }
  1398. if (n === 3) {
  1399. x1 = x1_right + sm_s;
  1400. x2 = x2_right + sm_s;
  1401. s_right = 1;
  1402. }
  1403. if (n === 0) {
  1404. x1 = x1_left - sm_s;
  1405. x2 = x2_left - sm_s;
  1406. s_left = 1;
  1407. }
  1408. var y1 = document.getElementById(key2).offsetTop + document.getElementById(key2 + '.' + key3).offsetTop + height_field;
  1409. var y2 = document.getElementById(contr[K][key][key2][key3][0]).offsetTop +
  1410. document.getElementById(contr[K][key][key2][key3][0] + '.' + contr[K][key][key2][key3][1]).offsetTop + height_field;
  1411. if (!selected && Local_X > x1 - 10 && Local_X < x1 + 10 && Local_Y > y1 - 7 && Local_Y < y1 + 7) {
  1412. Line0(
  1413. x1 + osn_tab.offsetLeft,
  1414. y1 - osn_tab.offsetTop,
  1415. x2 + osn_tab.offsetLeft,
  1416. y2 - osn_tab.offsetTop,
  1417. 'rgba(255,0,0,1)');
  1418. selected = 1; // Rect(x1-sm_x,y1-sm_y,10,10,"rgba(0,255,0,1)");
  1419. relation_name = key; //
  1420. Key0 = contr[K][key][key2][key3][0];
  1421. Key1 = contr[K][key][key2][key3][1];
  1422. Key2 = key2;
  1423. Key3 = key3;
  1424. Key = K;
  1425. } else {
  1426. Line0(
  1427. x1 + osn_tab.offsetLeft,
  1428. y1 - osn_tab.offsetTop,
  1429. x2 + osn_tab.offsetLeft,
  1430. y2 - osn_tab.offsetTop,
  1431. getColorByTarget(contr[K][key][key2][key3][0] + '.' + contr[K][key][key2][key3][1])
  1432. );
  1433. }
  1434. }
  1435. }
  1436. }
  1437. }
  1438. if (selected) {
  1439. // select relations
  1440. var left = Glob_X - (document.getElementById('layer_upd_relation').offsetWidth >> 1);
  1441. document.getElementById('layer_upd_relation').style.left = left + 'px';
  1442. var top = Glob_Y - document.getElementById('layer_upd_relation').offsetHeight - 10;
  1443. document.getElementById('layer_upd_relation').style.top = top + 'px';
  1444. document.getElementById('layer_upd_relation').style.display = 'block';
  1445. var argsep = PMA_commonParams.get('arg_separator');
  1446. link_relation = 'T1=' + Key0 + argsep + 'F1=' + Key1 + argsep + 'T2=' + Key2 + argsep + 'F2=' + Key3 + argsep + 'K=' + Key;
  1447. }
  1448. }
  1449. function Upd_relation () {
  1450. document.getElementById('layer_upd_relation').style.display = 'none';
  1451. var argsep = PMA_commonParams.get('arg_separator');
  1452. link_relation += argsep + 'server=' + server + argsep + 'db=' + db;
  1453. link_relation += argsep + 'operation=removeRelation' + argsep + 'ajax_request=true';
  1454. var $msgbox = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
  1455. $.post('db_designer.php', link_relation, function (data) {
  1456. if (data.success === false) {
  1457. PMA_ajaxShowMessage(data.error, false);
  1458. } else {
  1459. PMA_ajaxRemoveMessage($msgbox);
  1460. Load_page(selected_page);
  1461. }
  1462. }); // end $.post()
  1463. }
  1464. function VisibleTab (id, t_n) {
  1465. if (id.checked) {
  1466. document.getElementById(t_n).style.display = 'block';
  1467. } else {
  1468. document.getElementById(t_n).style.display = 'none';
  1469. }
  1470. Re_load();
  1471. }
  1472. // max/min all tables
  1473. function Hide_tab_all (id_this) {
  1474. if (id_this.alt === 'v') {
  1475. id_this.alt = '>';
  1476. id_this.src = id_this.dataset.right;
  1477. } else {
  1478. id_this.alt = 'v';
  1479. id_this.src = id_this.dataset.down;
  1480. }
  1481. var E = document.getElementById('container-form');
  1482. for (var i = 0; i < E.elements.length; i++) {
  1483. if (E.elements[i].type === 'checkbox' && E.elements[i].id.substring(0, 10) === 'check_vis_') {
  1484. if (id_this.alt === 'v') {
  1485. E.elements[i].checked = true;
  1486. document.getElementById(E.elements[i].value).style.display = '';
  1487. } else {
  1488. E.elements[i].checked = false;
  1489. document.getElementById(E.elements[i].value).style.display = 'none';
  1490. }
  1491. }
  1492. }
  1493. Re_load();
  1494. }
  1495. function in_array_k (x, m) {
  1496. var b = 0;
  1497. for (var u in m) {
  1498. if (x === u) {
  1499. b = 1;
  1500. break;
  1501. }
  1502. }
  1503. return b;
  1504. }
  1505. function No_have_constr (id_this) {
  1506. var a = [];
  1507. var K;
  1508. var key;
  1509. var key2;
  1510. var key3;
  1511. for (K in contr) {
  1512. for (key in contr[K]) {
  1513. // contr name
  1514. for (key2 in contr[K][key]) {
  1515. // table name
  1516. for (key3 in contr[K][key][key2]) {
  1517. // field name
  1518. a[key2] = a[contr[K][key][key2][key3][0]] = 1; // exist constr
  1519. }
  1520. }
  1521. }
  1522. }
  1523. if (id_this.alt === 'v') {
  1524. id_this.alt = '>';
  1525. id_this.src = id_this.dataset.right;
  1526. } else {
  1527. id_this.alt = 'v';
  1528. id_this.src = id_this.dataset.down;
  1529. }
  1530. var E = document.getElementById('container-form');
  1531. for (var i = 0; i < E.elements.length; i++) {
  1532. if (E.elements[i].type === 'checkbox' && E.elements[i].id.substring(0, 10) === 'check_vis_') {
  1533. if (!in_array_k(E.elements[i].value, a)) {
  1534. if (id_this.alt === 'v') {
  1535. E.elements[i].checked = true;
  1536. document.getElementById(E.elements[i].value).style.display = '';
  1537. } else {
  1538. E.elements[i].checked = false;
  1539. document.getElementById(E.elements[i].value).style.display = 'none';
  1540. }
  1541. }
  1542. }
  1543. }
  1544. }
  1545. function General_scroll () {
  1546. /*
  1547. if (!document.getElementById('show_relation_olways').checked) {
  1548. document.getElementById("canvas").style.display = 'none';
  1549. clearTimeout(timeoutID);
  1550. timeoutID = setTimeout(General_scroll_end, 500);
  1551. }
  1552. */
  1553. // if (timeoutID)
  1554. clearTimeout(timeoutID);
  1555. timeoutID = setTimeout(
  1556. function () {
  1557. document.getElementById('top_menu').style.left = document.body.scrollLeft + 'px';
  1558. document.getElementById('top_menu').style.top = document.body.scrollTop + 'px';
  1559. },
  1560. 200
  1561. );
  1562. }
  1563. // max/min all tables
  1564. function Show_left_menu (id_this) {
  1565. var icon = id_this.children[0];
  1566. $('#key_Show_left_menu').toggleClass('M_butt_Selected_down');
  1567. if (icon.alt === 'v') {
  1568. document.getElementById('layer_menu').style.top = '0px';
  1569. document.getElementById('layer_menu').style.display = 'block';
  1570. icon.alt = '>';
  1571. icon.src = icon.dataset.up;
  1572. if (isIE) {
  1573. General_scroll();
  1574. }
  1575. } else {
  1576. document.getElementById('layer_menu').style.top = -1000 + 'px'; // fast scroll
  1577. document.getElementById('layer_menu').style.display = 'none';
  1578. icon.alt = 'v';
  1579. icon.src = icon.dataset.down;
  1580. }
  1581. }
  1582. // ------------------------------------------------------------------------------
  1583. function Side_menu_right (id_this) {
  1584. $('#side_menu').toggleClass('right');
  1585. $('#layer_menu').toggleClass('left');
  1586. var icon = $(id_this.childNodes[0]);
  1587. var current = icon.attr('src');
  1588. icon.attr('src', icon.attr('data-right')).attr('data-right', current);
  1589. icon = $(document.getElementById('layer_menu_sizer').childNodes[0])
  1590. .toggleClass('floatleft')
  1591. .toggleClass('floatright')
  1592. .children();
  1593. current = icon.attr('src');
  1594. icon.attr('src', icon.attr('data-right'));
  1595. icon.attr('data-right', current);
  1596. menu_moved = !menu_moved;
  1597. saveValueInConfig('side_menu', $('#side_menu').hasClass('right'));
  1598. $('#key_Left_Right').toggleClass('M_butt_Selected_down');
  1599. $('#key_Left_Right').toggleClass('M_butt');
  1600. }
  1601. // ------------------------------------------------------------------------------
  1602. function Show_text () {
  1603. $('#side_menu').find('.hidable').show();
  1604. }
  1605. function Hide_text () {
  1606. if (!always_show_text) {
  1607. $('#side_menu').find('.hidable').hide();
  1608. }
  1609. }
  1610. function Pin_text () {
  1611. always_show_text = !always_show_text;
  1612. $('#pin_Text').toggleClass('M_butt_Selected_down');
  1613. $('#pin_Text').toggleClass('M_butt');
  1614. saveValueInConfig('pin_text', always_show_text);
  1615. }
  1616. // ------------------------------------------------------------------------------
  1617. function Start_display_field () {
  1618. if (ON_relation) {
  1619. return;
  1620. }
  1621. if (!ON_display_field) {
  1622. ON_display_field = 1;
  1623. document.getElementById('designer_hint').innerHTML = PMA_messages.strChangeDisplay;
  1624. document.getElementById('designer_hint').style.display = 'block';
  1625. document.getElementById('display_field_button').className = 'M_butt_Selected_down';// '#FFEE99';gray #AAAAAA
  1626. if (isIE) { // correct for IE
  1627. document.getElementById('display_field_button').className = 'M_butt_Selected_down_IE';
  1628. }
  1629. } else {
  1630. document.getElementById('designer_hint').innerHTML = '';
  1631. document.getElementById('designer_hint').style.display = 'none';
  1632. document.getElementById('display_field_button').className = 'M_butt';
  1633. ON_display_field = 0;
  1634. }
  1635. }
  1636. // ------------------------------------------------------------------------------
  1637. var TargetColors = [];
  1638. function getColorByTarget (target) {
  1639. var color = ''; // "rgba(0,100,150,1)";
  1640. for (var a in TargetColors) {
  1641. if (TargetColors[a][0] === target) {
  1642. color = TargetColors[a][1];
  1643. break;
  1644. }
  1645. }
  1646. if (color.length === 0) {
  1647. var i = TargetColors.length + 1;
  1648. var d = i % 6;
  1649. var j = (i - d) / 6;
  1650. j = j % 4;
  1651. j++;
  1652. var color_case = [
  1653. [1, 0, 0],
  1654. [0, 1, 0],
  1655. [0, 0, 1],
  1656. [1, 1, 0],
  1657. [1, 0, 1],
  1658. [0, 1, 1]
  1659. ];
  1660. var a = color_case[d][0];
  1661. var b = color_case[d][1];
  1662. var c = color_case[d][2];
  1663. var e = (1 - (j - 1) / 6);
  1664. var r = Math.round(a * 200 * e);
  1665. var g = Math.round(b * 200 * e);
  1666. b = Math.round(c * 200 * e);
  1667. color = 'rgba(' + r + ',' + g + ',' + b + ',1)';
  1668. TargetColors.push([target, color]);
  1669. }
  1670. return color;
  1671. }
  1672. function Click_option (dbName, tableName, columnName, tableDbNameUrl, optionColNameString) {
  1673. var designerOptions = document.getElementById('designer_optionse');
  1674. var left = Glob_X - (designerOptions.offsetWidth >> 1);
  1675. designerOptions.style.left = left + 'px';
  1676. // var top = Glob_Y - designerOptions.offsetHeight - 10;
  1677. designerOptions.style.top = (screen.height / 4) + 'px';
  1678. designerOptions.style.display = 'block';
  1679. document.getElementById('ok_add_object_db_and_table_name_url').value = tableDbNameUrl;
  1680. document.getElementById('ok_add_object_db_name').value = dbName;
  1681. document.getElementById('ok_add_object_table_name').value = tableName;
  1682. document.getElementById('ok_add_object_col_name').value = columnName;
  1683. document.getElementById('option_col_name').innerHTML = optionColNameString;
  1684. }
  1685. function Close_option () {
  1686. document.getElementById('designer_optionse').style.display = 'none';
  1687. document.getElementById('rel_opt').value = '--';
  1688. document.getElementById('Query').value = '';
  1689. document.getElementById('new_name').value = '';
  1690. document.getElementById('operator').value = '---';
  1691. document.getElementById('groupby').checked = false;
  1692. document.getElementById('h_rel_opt').value = '--';
  1693. document.getElementById('h_operator').value = '---';
  1694. document.getElementById('having').value = '';
  1695. document.getElementById('orderby').value = '---';
  1696. }
  1697. function Select_all (tableName, dbName, idSelectAll) {
  1698. var parentIsChecked = $('#' + idSelectAll).is(':checked');
  1699. var checkboxAll = $('#container-form input[id_check_all=\'' + idSelectAll + '\']:checkbox');
  1700. checkboxAll.each(function () {
  1701. // already checked and then check parent
  1702. if (parentIsChecked === true && this.checked) {
  1703. // was checked, removing column from selected fields
  1704. // trigger unchecked event
  1705. this.click();
  1706. }
  1707. this.checked = parentIsChecked;
  1708. this.disabled = parentIsChecked;
  1709. });
  1710. if (parentIsChecked) {
  1711. select_field.push('`' + tableName + '`.*');
  1712. from_array.push(tableName);
  1713. } else {
  1714. var i;
  1715. for (i = 0; i < select_field.length; i++) {
  1716. if (select_field[i] === ('`' + tableName + '`.*')) {
  1717. select_field.splice(i, 1);
  1718. }
  1719. }
  1720. var k;
  1721. for (k = 0; k < from_array.length; k++) {
  1722. if (from_array[k] === tableName) {
  1723. from_array.splice(k, 1);
  1724. break;
  1725. }
  1726. }
  1727. }
  1728. Re_load();
  1729. }
  1730. function Table_onover (id_this, val, buil) {
  1731. buil = parseInt(buil);
  1732. if (!val) {
  1733. document.getElementById('id_zag_' + id_this).className = 'tab_zag_2';
  1734. if (buil) {
  1735. document.getElementById('id_zag_' + id_this + '_2').className = 'tab_zag_2';
  1736. }
  1737. } else {
  1738. document.getElementById('id_zag_' + id_this).className = 'tab_zag';
  1739. if (buil) {
  1740. document.getElementById('id_zag_' + id_this + '_2').className = 'tab_zag';
  1741. }
  1742. }
  1743. }
  1744. /* This function stores selected column information in select_field[]
  1745. * In case column is checked it add else it deletes
  1746. *
  1747. */
  1748. function store_column (tableName, colName, checkboxId) {
  1749. var i;
  1750. var k;
  1751. var selectKeyField = '`' + tableName + '`.`' + colName + '`';
  1752. if (document.getElementById(checkboxId).checked === true) {
  1753. select_field.push(selectKeyField);
  1754. from_array.push(tableName);
  1755. } else {
  1756. for (i = 0; i < select_field.length; i++) {
  1757. if (select_field[i] === selectKeyField) {
  1758. select_field.splice(i, 1);
  1759. break;
  1760. }
  1761. }
  1762. for (k = 0; k < from_array.length; k++) {
  1763. if (from_array[k] === tableName) {
  1764. from_array.splice(k, 1);
  1765. break;
  1766. }
  1767. }
  1768. }
  1769. }
  1770. /**
  1771. * This function builds object and adds them to history_array
  1772. * first it does a few checks on each object, then makes an object(where,rename,groupby,aggregate,orderby)
  1773. * then a new history object is made and finally all these history objects are added to history_array[]
  1774. *
  1775. **/
  1776. function add_object (dbName, tableName, colName, dbTableNameUrl) {
  1777. var p;
  1778. var where_obj;
  1779. var rel = document.getElementById('rel_opt');
  1780. var sum = 0;
  1781. var init = history_array.length;
  1782. if (rel.value !== '--') {
  1783. if (document.getElementById('Query').value === '') {
  1784. PMA_ajaxShowMessage(PMA_sprintf(PMA_messages.strQueryEmpty));
  1785. return;
  1786. }
  1787. p = document.getElementById('Query');
  1788. where_obj = new where(rel.value, p.value);// make where object
  1789. history_array.push(new history_obj(colName, where_obj, tableName, h_tabs[dbTableNameUrl], 'Where'));
  1790. sum = sum + 1;
  1791. }
  1792. if (document.getElementById('new_name').value !== '') {
  1793. var rename_obj = new rename(document.getElementById('new_name').value);// make Rename object
  1794. history_array.push(new history_obj(colName, rename_obj, tableName, h_tabs[dbTableNameUrl], 'Rename'));
  1795. sum = sum + 1;
  1796. }
  1797. if (document.getElementById('operator').value !== '---') {
  1798. var aggregate_obj = new aggregate(document.getElementById('operator').value);
  1799. history_array.push(new history_obj(colName, aggregate_obj, tableName, h_tabs[dbTableNameUrl], 'Aggregate'));
  1800. sum = sum + 1;
  1801. // make aggregate operator
  1802. }
  1803. if (document.getElementById('groupby').checked === true) {
  1804. history_array.push(new history_obj(colName, 'GroupBy', tableName, h_tabs[dbTableNameUrl], 'GroupBy'));
  1805. sum = sum + 1;
  1806. // make groupby
  1807. }
  1808. if (document.getElementById('h_rel_opt').value !== '--') {
  1809. if (document.getElementById('having').value === '') {
  1810. return;
  1811. }
  1812. where_obj = new having(
  1813. document.getElementById('h_rel_opt').value,
  1814. document.getElementById('having').value,
  1815. document.getElementById('h_operator').value
  1816. );// make where object
  1817. history_array.push(new history_obj(col_name, where_obj, tableName, h_tabs[dbTableNameUrl], 'Having'));
  1818. sum = sum + 1;
  1819. // make having
  1820. }
  1821. if (document.getElementById('orderby').value !== '---') {
  1822. var oderby_obj = new orderby(document.getElementById('orderby').value);
  1823. history_array.push(new history_obj(col_name, oderby_obj, tableName, h_tabs[dbTableNameUrl], 'OrderBy'));
  1824. sum = sum + 1;
  1825. // make orderby
  1826. }
  1827. PMA_ajaxShowMessage(PMA_sprintf(PMA_messages.strObjectsCreated, sum));
  1828. // output sum new objects created
  1829. var existingDiv = document.getElementById('ab');
  1830. existingDiv.innerHTML = display(init, history_array.length);
  1831. Close_option();
  1832. $('#ab').accordion('refresh');
  1833. }
  1834. function enablePageContentEvents() {
  1835. $('#page_content').off('mousedown', MouseDown);
  1836. $('#page_content').off('mouseup', MouseUp);
  1837. $('#page_content').off('mousemove', MouseMove);
  1838. $('#page_content').on('mousedown', MouseDown);
  1839. $('#page_content').on('mouseup', MouseUp);
  1840. $('#page_content').on('mousemove', MouseMove);
  1841. }
  1842. /**
  1843. * This function enables the events on table items.
  1844. * It helps to enable them on page loading and when a table is added on the fly.
  1845. */
  1846. function enableTableEvents(index, element) {
  1847. $(element).on('click', '.select_all_1', function () {
  1848. Select_all($(this).attr('table_name'), $(this).attr('db_name'), $(this).attr('id'));
  1849. });
  1850. $(element).on('click', '.small_tab,.small_tab2', function () {
  1851. Small_tab($(this).attr('table_name'), 1);
  1852. });
  1853. $(element).on('click', '.small_tab_pref_1', function () {
  1854. Start_tab_upd($(this).attr('db_url'), $(this).attr('table_name_url'));
  1855. });
  1856. $(element).on('click', '.select_all_store_col', function () {
  1857. store_column($(this).attr('table_name'), $(this).attr('col_name'), $(this).attr('id'));
  1858. });
  1859. $(element).on('click', '.small_tab_pref_click_opt', function () {
  1860. Click_option(
  1861. $(this).attr('db_name'),
  1862. $(this).attr('table_name'),
  1863. $(this).attr('col_name'),
  1864. $(this).attr('db_table_name_url'),
  1865. $(this).attr('option_col_name_modal')
  1866. );
  1867. });
  1868. $(element).on('click', '.tab_field_2,.tab_field_3,.tab_field', function () {
  1869. var params = ($(this).attr('click_field_param')).split(',');
  1870. Click_field(params[3], params[0], params[1], params[2]);
  1871. });
  1872. $(element).find('.tab_zag_noquery').mouseover(function () {
  1873. Table_onover($(this).attr('table_name'),0, $(this).attr('query_set'));
  1874. });
  1875. $(element).find('.tab_zag_noquery').mouseout(function () {
  1876. Table_onover($(this).attr('table_name'),1, $(this).attr('query_set'));
  1877. });
  1878. $(element).find('.tab_zag_query').mouseover(function () {
  1879. Table_onover($(this).attr('table_name'),0, 1);
  1880. });
  1881. $(element).find('.tab_zag_query').mouseout(function () {
  1882. Table_onover($(this).attr('table_name'),1, 1);
  1883. });
  1884. enablePageContentEvents();
  1885. }
  1886. AJAX.registerTeardown('designer/move.js', function () {
  1887. $('#side_menu').off('mouseenter mouseleave');
  1888. $('#key_Show_left_menu').off('click');
  1889. $('#toggleFullscreen').off('click');
  1890. $('#newPage').off('click');
  1891. $('#editPage').off('click');
  1892. $('#savePos').off('click');
  1893. $('#SaveAs').off('click');
  1894. $('#delPages').off('click');
  1895. $('#StartTableNew').off('click');
  1896. $('#rel_button').off('click');
  1897. $('#StartTableNew').off('click');
  1898. $('#display_field_button').off('click');
  1899. $('#reloadPage').off('click');
  1900. $('#angular_direct_button').off('click');
  1901. $('#grid_button').off('click');
  1902. $('#key_SB_all').off('click');
  1903. $('#SmallTabInvert').off('click');
  1904. $('#relLineInvert').off('click');
  1905. $('#exportPages').off('click');
  1906. $('#query_builder').off('click');
  1907. $('#key_Left_Right').off('click');
  1908. $('#pin_Text').off('click');
  1909. $('#canvas').off('click');
  1910. $('#key_HS_all').off('click');
  1911. $('#key_HS').off('click');
  1912. $('.scroll_tab_struct').off('click');
  1913. $('.scroll_tab_checkbox').off('click');
  1914. $('#id_scroll_tab').find('tr').off('click', '.designer_Tabs2,.designer_Tabs');
  1915. $('.designer_tab').off('click', '.select_all_1');
  1916. $('.designer_tab').off('click', '.small_tab,.small_tab2');
  1917. $('.designer_tab').off('click', '.small_tab_pref_1');
  1918. $('.tab_zag_noquery').off('mouseover');
  1919. $('.tab_zag_noquery').off('mouseout');
  1920. $('.tab_zag_query').off('mouseover');
  1921. $('.tab_zag_query').off('mouseout');
  1922. $('.designer_tab').off('click','.tab_field_2,.tab_field_3,.tab_field');
  1923. $('.designer_tab').off('click', '.select_all_store_col');
  1924. $('.designer_tab').off('click', '.small_tab_pref_click_opt');
  1925. $('#del_button').off('click');
  1926. $('#cancel_button').off('click');
  1927. $('#ok_add_object').off('click');
  1928. $('#cancel_close_option').off('click');
  1929. $('#ok_new_rel_panel').off('click');
  1930. $('#cancel_new_rel_panel').off('click');
  1931. $('#page_content').off('mouseup');
  1932. $('#page_content').off('mousedown');
  1933. $('#page_content').off('mousemove');
  1934. });
  1935. AJAX.registerOnload('designer/move.js', function () {
  1936. $('#key_Show_left_menu').click(function () {
  1937. Show_left_menu(this);
  1938. return false;
  1939. });
  1940. $('#toggleFullscreen').click(function () {
  1941. Toggle_fullscreen();
  1942. return false;
  1943. });
  1944. $('#addOtherDbTables').click(function () {
  1945. Add_Other_db_tables();
  1946. return false;
  1947. });
  1948. $('#newPage').click(function () {
  1949. New();
  1950. return false;
  1951. });
  1952. $('#editPage').click(function () {
  1953. Edit_pages();
  1954. return false;
  1955. });
  1956. $('#savePos').click(function () {
  1957. Save3();
  1958. return false;
  1959. });
  1960. $('#SaveAs').click(function () {
  1961. Save_as();
  1962. return false;
  1963. });
  1964. $('#delPages').click(function () {
  1965. Delete_pages();
  1966. return false;
  1967. });
  1968. $('#StartTableNew').click(function () {
  1969. Start_table_new();
  1970. return false;
  1971. });
  1972. $('#rel_button').click(function () {
  1973. Start_relation();
  1974. return false;
  1975. });
  1976. $('#display_field_button').click(function () {
  1977. Start_display_field();
  1978. return false;
  1979. });
  1980. $('#reloadPage').click(function () {
  1981. Load_page(selected_page);
  1982. });
  1983. $('#angular_direct_button').click(function () {
  1984. Angular_direct();
  1985. return false;
  1986. });
  1987. $('#grid_button').click(function () {
  1988. Grid();
  1989. return false;
  1990. });
  1991. $('#key_SB_all').click(function () {
  1992. Small_tab_all(this);
  1993. return false;
  1994. });
  1995. $('#SmallTabInvert').click(function () {
  1996. Small_tab_invert();
  1997. return false;
  1998. });
  1999. $('#relLineInvert').click(function () {
  2000. Relation_lines_invert();
  2001. return false;
  2002. });
  2003. $('#exportPages').click(function () {
  2004. Export_pages();
  2005. return false;
  2006. });
  2007. $('#query_builder').click(function () {
  2008. build_query('SQL Query on Database', 0);
  2009. });
  2010. $('#key_Left_Right').click(function () {
  2011. Side_menu_right(this);
  2012. return false;
  2013. });
  2014. $('#side_menu').hover(function () {
  2015. Show_text();
  2016. return false;
  2017. }, function () {
  2018. Hide_text();
  2019. return false;
  2020. });
  2021. $('#pin_Text').click(function () {
  2022. Pin_text(this);
  2023. return false;
  2024. });
  2025. $('#canvas').click(function (event) {
  2026. Canvas_click(this, event);
  2027. });
  2028. $('#key_HS_all').click(function () {
  2029. Hide_tab_all(this);
  2030. return false;
  2031. });
  2032. $('#key_HS').click(function () {
  2033. No_have_constr(this);
  2034. return false;
  2035. });
  2036. $('.designer_tab').each(enableTableEvents);
  2037. $('.designer_tab').each(addTableToTablesList);
  2038. $('input#del_button').click(function () {
  2039. Upd_relation();
  2040. });
  2041. $('input#cancel_button').click(function () {
  2042. document.getElementById('layer_upd_relation').style.display = 'none';
  2043. Re_load();
  2044. });
  2045. $('input#ok_add_object').click(function () {
  2046. add_object(
  2047. $('#ok_add_object_db_name').val(),
  2048. $('#ok_add_object_table_name').val(),
  2049. $('#ok_add_object_col_name').val(),
  2050. $('#ok_add_object_db_and_table_name_url').val()
  2051. );
  2052. });
  2053. $('input#cancel_close_option').click(function () {
  2054. Close_option();
  2055. });
  2056. $('input#ok_new_rel_panel').click(function () {
  2057. New_relation();
  2058. });
  2059. $('input#cancel_new_rel_panel').click(function () {
  2060. document.getElementById('layer_new_relation').style.display = 'none';
  2061. });
  2062. enablePageContentEvents();
  2063. });