From 0f7ddfd276928c711dc510fe19841234556a2b11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Wed, 22 May 2019 21:52:14 -0300 Subject: [PATCH] Refactor js/designer/move.js to use a module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds DesignerMove module in js/designer/move.js to reduce the number of global variables. Signed-off-by: MaurĂ­cio Meneghini Fauth --- js/designer/init.js | 2 +- js/designer/move.js | 604 +++++++++++++++++++++----------------------- js/designer/page.js | 8 +- 3 files changed, 295 insertions(+), 319 deletions(-) diff --git a/js/designer/init.js b/js/designer/init.js index 29224aecd35c..11a185c28b4a 100644 --- a/js/designer/init.js +++ b/js/designer/init.js @@ -34,7 +34,7 @@ AJAX.registerOnload('designer/init.js', function () { selected_page = designer_config.displayPage; designer_tables_enabled = designer_config.tablesEnabled; - Main(); + DesignerMove.main(); if (! designer_tables_enabled) { DesignerOfflineDB.open(function (success) { diff --git a/js/designer/move.js b/js/designer/move.js index 51ab5d77680b..0857451ddf8a 100644 --- a/js/designer/move.js +++ b/js/designer/move.js @@ -2,6 +2,9 @@ /** * @package PhpMyAdmin-Designer */ + +var DesignerMove = {}; + var _change = 0; // variable to track any change in designer layout. var _staying = 0; // variable to check if the user stayed after seeing the confirmation prompt. var show_relation_lines = true; @@ -29,25 +32,25 @@ AJAX.registerOnload('designer/move.js', function () { $('#selflink').hide(); }); -function make_zero () { // Function called if the user stays after seeing the confirmation prompt. +DesignerMove.makeZero = function () { // Function called if the user stays after seeing the confirmation prompt. _staying = 0; -} +}; -function MarkSaved () { +DesignerMove.markSaved = function () { _change = 0; $('#saved_state').text(''); -} +}; -function MarkUnsaved () { +DesignerMove.markUnsaved = function () { _change = 1; $('#saved_state').text('*'); -} +}; var dx; var dy; var dy2; var cur_click = null; -// update in Main() +// update in DesignerMove.main() var sm_x = 2; var sm_y = 2; var sm_s = 0; @@ -79,24 +82,17 @@ var menu_moved = false; var grid_size = 10; // ------------------------------------------------------------------------------ -// ------------------------------------------------------------------------------ -// ------------------------------------------------------------------------------ - - -// window.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP); -// ---CROSS var isIE = document.all && !window.opera; if (isIE) { - window.onscroll = General_scroll; + window.onscroll = DesignerMove.generalScroll; document.onselectstart = function () { return false; }; } -// document.onmouseup = function (){General_scroll_end();} -function MouseDown (e) { +DesignerMove.mouseDown = function (e) { Glob_X = dx = isIE ? e.clientX + document.body.scrollLeft : e.pageX; Glob_Y = dy = isIE ? e.clientY + document.body.scrollTop : e.pageY; @@ -114,9 +110,9 @@ function MouseDown (e) { document.getElementById('canvas').style.display = 'none'; cur_click.style.zIndex = 2; } -} +}; -function MouseMove (e) { +DesignerMove.mouseMove = function (e) { if (e.preventDefault) { e.preventDefault(); } @@ -131,7 +127,7 @@ function MouseMove (e) { Glob_Y = new_dy; if (cur_click !== null) { - MarkUnsaved(); + DesignerMove.markUnsaved(); var $cur_click = $(cur_click); @@ -179,29 +175,22 @@ function MouseMove (e) { document.getElementById('designer_hint').style.left = (Glob_X + 20) + 'px'; document.getElementById('designer_hint').style.top = (Glob_Y + 20) + 'px'; } -} +}; -function MouseUp (e) { +DesignerMove.mouseUp = function (e) { if (cur_click !== null) { document.getElementById('canvas').style.display = 'inline-block'; - Re_load(); + DesignerMove.reload(); cur_click.style.zIndex = 1; cur_click = null; } layer_menu_cur_click = 0; // window.releaseEvents(Event.MOUSEMOVE); -} -// ------------------------------------------------------------------------------ -// ------------------------------------------------------------------------------ -// ------------------------------------------------------------------------------ +}; +// ------------------------------------------------------------------------------ -// function ToInt(s) -// { -// return s.substring(0,s.length-2)*1; //re = /(\d+)\w*/; newstr = str.replace(re, "$1"); -// } - -function Canvas_pos () { +DesignerMove.canvasPos = function () { canvas_width = document.getElementById('canvas').width = osn_tab_width - 3; canvas_height = document.getElementById('canvas').height = osn_tab_height - 3; @@ -209,27 +198,27 @@ function Canvas_pos () { document.getElementById('canvas').style.width = ((osn_tab_width - 3) ? (osn_tab_width - 3) : 0) + 'px'; document.getElementById('canvas').style.height = ((osn_tab_height - 3) ? (osn_tab_height - 3) : 0) + 'px'; } -} +}; -function Osn_tab_pos () { +DesignerMove.osnTabPos = function () { osn_tab_width = parseInt(document.getElementById('osn_tab').style.width, 10); osn_tab_height = parseInt(document.getElementById('osn_tab').style.height, 10); -} +}; -function setDefaultValuesFromSavedState () { +DesignerMove.setDefaultValuesFromSavedState = function () { if ($('#angular_direct_button').attr('class') === 'M_butt') { ON_angular_direct = 0; } else { ON_angular_direct = 1; } - Angular_direct(); + DesignerMove.angularDirect(); if ($('#grid_button').attr('class') === 'M_butt') { ON_grid = 1; } else { ON_grid = 0; } - Grid(); + DesignerMove.grid(); var $relLineInvert = $('#relLineInvert'); if ($relLineInvert.attr('class') === 'M_butt') { @@ -239,11 +228,11 @@ function setDefaultValuesFromSavedState () { show_relation_lines = true; $relLineInvert.attr('class', 'M_butt_Selected_down'); } - Relation_lines_invert(); + DesignerMove.relationLinesInvert(); if ($('#pin_Text').attr('class') === 'M_butt_Selected_down') { always_show_text = true; - Show_text(); + DesignerMove.showText(); } else { always_show_text = false; } @@ -259,28 +248,26 @@ function setDefaultValuesFromSavedState () { if ($key_Left_Right.attr('class') === 'M_butt_Selected_down') { $key_Left_Right.trigger('click'); } -} +}; -function Main () { +DesignerMove.main = function () { // ---CROSS document.getElementById('layer_menu').style.top = -1000 + 'px'; // fast scroll // sm_x += document.getElementById('osn_tab').offsetLeft; // sm_y += document.getElementById('osn_tab').offsetTop; - Osn_tab_pos(); - Canvas_pos(); - Small_tab_refresh(); - Re_load(); - setDefaultValuesFromSavedState(); + DesignerMove.osnTabPos(); + DesignerMove.canvasPos(); + DesignerMove.smallTabRefresh(); + DesignerMove.reload(); + DesignerMove.setDefaultValuesFromSavedState(); id_hint = document.getElementById('designer_hint'); if (isIE) { - General_scroll(); + DesignerMove.generalScroll(); } -} - +}; -// -------------------------------- new ----------------------------------------- -function Rezize_osn_tab () { +DesignerMove.resizeOsnTab = function () { var max_X = 0; var max_Y = 0; for (var key in j_tabs) { @@ -292,17 +279,16 @@ function Rezize_osn_tab () { osn_tab_width = max_X + 50; osn_tab_height = max_Y + 50; - Canvas_pos(); + DesignerMove.canvasPos(); document.getElementById('osn_tab').style.width = osn_tab_width + 'px'; document.getElementById('osn_tab').style.height = osn_tab_height + 'px'; -} -// ------------------------------------------------------------------------------ +}; /** * refreshes display, must be called after state changes */ -function Re_load () { - Rezize_osn_tab(); +DesignerMove.reload = function () { + DesignerMove.resizeOsnTab(); var n; var x1; var x2; @@ -311,7 +297,7 @@ function Re_load () { var key; var key2; var key3; - Clear(); + DesignerMove.clear(); for (K in contr) { for (key in contr[K]) { // contr name @@ -399,23 +385,23 @@ function Re_load () { var osn_tab = document.getElementById('osn_tab'); - Line0( + DesignerMove.line0( x1 + osn_tab.offsetLeft, y1 - osn_tab.offsetTop, x2 + osn_tab.offsetLeft, y2 - osn_tab.offsetTop, - getColorByTarget(contr[K][key][key2][key3][0] + '.' + contr[K][key][key2][key3][1]) + DesignerMove.getColorByTarget(contr[K][key][key2][key3][0] + '.' + contr[K][key][key2][key3][1]) ); } } } } -} +}; /** * draws a line from x1:y1 to x2:y2 with color */ -function Line (x1, y1, x2, y2, color_line) { +DesignerMove.line = function (x1, y1, x2, y2, color_line) { var canvas = document.getElementById('canvas'); var ctx = canvas.getContext('2d'); ctx.strokeStyle = color_line; @@ -424,29 +410,29 @@ function Line (x1, y1, x2, y2, color_line) { ctx.moveTo(x1, y1); ctx.lineTo(x2, y2); ctx.stroke(); -} +}; /** * draws a relation/constraint line, whether angular or not */ -function Line0 (x1, y1, x2, y2, color_line) { +DesignerMove.line0 = function (x1, y1, x2, y2, color_line) { if (! show_relation_lines) { return; } - Circle(x1, y1, 3, 3, color_line); - Rect(x2 - 1, y2 - 2, 4, 4, color_line); + DesignerMove.circle(x1, y1, 3, 3, color_line); + DesignerMove.rect(x2 - 1, y2 - 2, 4, 4, color_line); if (ON_angular_direct) { - Line2(x1, y1, x2, y2, color_line); + DesignerMove.line2(x1, y1, x2, y2, color_line); } else { - Line3(x1, y1, x2, y2, color_line); + DesignerMove.line3(x1, y1, x2, y2, color_line); } -} +}; /** * draws a angular relation/constraint line */ -function Line2 (x1, y1, x2, y2, color_line) { +DesignerMove.line2 = function (x1, y1, x2, y2, color_line) { var x1_ = x1; var x2_ = x2; @@ -464,15 +450,15 @@ function Line2 (x1, y1, x2, y2, color_line) { x2_ += sm_add; } - Line(x1, y1, x1_, y1, color_line); - Line(x2, y2, x2_, y2, color_line); - Line(x1_, y1, x2_, y2, color_line); -} + DesignerMove.line(x1, y1, x1_, y1, color_line); + DesignerMove.line(x2, y2, x2_, y2, color_line); + DesignerMove.line(x1_, y1, x2_, y2, color_line); +}; /** * draws a relation/constraint line */ -function Line3 (x1, y1, x2, y2, color_line) { +DesignerMove.line3 = function (x1, y1, x2, y2, color_line) { var x1_ = x1; var x2_ = x2; @@ -485,9 +471,9 @@ function Line3 (x1, y1, x2, y2, color_line) { x1_ += sm_add; } - Line(x1, y1, x1_, y1, color_line); - Line(x2, y2, x2_, y2, color_line); - Line(x1_, y1, x2_, y2, color_line); + DesignerMove.line(x1, y1, x1_, y1, color_line); + DesignerMove.line(x2, y2, x2_, y2, color_line); + DesignerMove.line(x1_, y1, x2_, y2, color_line); return; } if (s_left) { @@ -499,19 +485,19 @@ function Line3 (x1, y1, x2, y2, color_line) { x2_ -= sm_add; } - Line(x1, y1, x1_, y1, color_line); - Line(x2, y2, x2_, y2, color_line); - Line(x1_, y1, x2_, y2, color_line); + DesignerMove.line(x1, y1, x1_, y1, color_line); + DesignerMove.line(x2, y2, x2_, y2, color_line); + DesignerMove.line(x1_, y1, x2_, y2, color_line); return; } var x_s = (x1 + x2) / 2; - Line(x1, y1, x_s, y1, color_line); - Line(x_s, y2, x2, y2, color_line); - Line(x_s, y1, x_s, y2, color_line); -} + DesignerMove.line(x1, y1, x_s, y1, color_line); + DesignerMove.line(x_s, y2, x2, y2, color_line); + DesignerMove.line(x_s, y1, x_s, y2, color_line); +}; -function Circle (x, y, r, w, color) { +DesignerMove.circle = function (x, y, r, w, color) { var ctx = document.getElementById('canvas').getContext('2d'); ctx.beginPath(); ctx.moveTo(x, y); @@ -519,21 +505,22 @@ function Circle (x, y, r, w, color) { ctx.strokeStyle = color; ctx.arc(x, y, r, 0, 2 * Math.PI, true); ctx.stroke(); -} +}; -function Clear () { +DesignerMove.clear = function () { var canvas = document.getElementById('canvas'); var ctx = canvas.getContext('2d'); ctx.clearRect(0, 0, canvas_width, canvas_height); -} +}; -function Rect (x1, y1, w, h, color) { +DesignerMove.rect = function (x1, y1, w, h, color) { var ctx = document.getElementById('canvas').getContext('2d'); ctx.fillStyle = color; ctx.fillRect(x1, y1, w, h); -} +}; + // --------------------------- FULLSCREEN ------------------------------------- -function Toggle_fullscreen () { +DesignerMove.toggleFullscreen = function () { var value_sent = ''; var $img = $('#toggleFullscreen').find('img'); var $span = $img.siblings('span'); @@ -551,10 +538,10 @@ function Toggle_fullscreen () { $content.fullScreen(false); value_sent = 'off'; } - saveValueInConfig('full_screen', value_sent); -} + DesignerMove.saveValueInConfig('full_screen', value_sent); +}; -function Add_Other_db_tables () { +DesignerMove.addOtherDbTables = function () { var button_options = {}; button_options[Messages.strGo] = function () { var db = $('#add_table_from').val(); @@ -571,15 +558,15 @@ function Add_Other_db_tables () { $('#container-form').append($new_table_dom); $('.designer_tab').on('click','.tab_field_2,.tab_field_3,.tab_field', function () { var params = ($(this).attr('click_field_param')).split(','); - Click_field(params[3], params[0], params[1], params[2]); + DesignerMove.clickField(params[3], params[0], params[1], params[2]); }); $('.designer_tab').on('click', '.select_all_store_col', function () { var params = ($(this).attr('store_column_param')).split(','); - store_column(params[0], params[1], params[2]); + DesignerMove.storeColumn(params[0], params[1], params[2]); }); $('.designer_tab').on('click', '.small_tab_pref_click_opt', function () { var params = ($(this).attr('Click_option_param')).split(','); - Click_option(params[0], params[1], params[2]); + DesignerMove.clickOption(params[0], params[1], params[2]); }); }); $(this).dialog('close'); @@ -638,20 +625,18 @@ function Add_Other_db_tables () { }); } }); -} - +}; // ------------------------------ NEW ------------------------------------------ - -function New () { - Prompt_to_save_current_page(function () { - Load_page(-1); +DesignerMove.new = function () { + DesignerMove.promptToSaveCurrentPage(function () { + DesignerMove.loadPage(-1); }); -} +}; // ------------------------------ SAVE ------------------------------------------ // (del?) no for pdf -function Save (url) { +DesignerMove.save = function (url) { for (var key in j_tabs) { document.getElementById('t_x_' + key + '_').value = parseInt(document.getElementById(key).style.left, 10); document.getElementById('t_y_' + key + '_').value = parseInt(document.getElementById(key).style.top, 10); @@ -660,9 +645,9 @@ function Save (url) { } document.form1.action = url; $(document.form1).submit(); -} +}; -function Get_url_pos (forceString) { +DesignerMove.getUrlPos = function (forceString) { if (designer_tables_enabled || forceString) { var poststr = ''; var argsep = CommonParams.get('arg_separator'); @@ -685,14 +670,14 @@ function Get_url_pos (forceString) { } return coords; } -} +}; -function Save2 (callback) { +DesignerMove.save2 = function (callback) { if (designer_tables_enabled) { var argsep = CommonParams.get('arg_separator'); var poststr = argsep + 'operation=savePage' + argsep + 'save_page=same' + argsep + 'ajax_request=true'; poststr += argsep + 'server=' + server + argsep + 'db=' + db + argsep + 'selected_page=' + selected_page; - poststr += Get_url_pos(); + poststr += DesignerMove.getUrlPos(); var $msgbox = Functions.ajaxShowMessage(Messages.strProcessingRequest); $.post('db_designer.php', poststr, function (data) { @@ -701,7 +686,7 @@ function Save2 (callback) { } else { Functions.ajaxRemoveMessage($msgbox); Functions.ajaxShowMessage(Messages.strModificationSaved); - MarkSaved(); + DesignerMove.markSaved(); if (typeof callback !== 'undefined') { callback(); } @@ -709,17 +694,16 @@ function Save2 (callback) { }); } else { var name = $('#page_name').html().trim(); - Save_to_selected_page(db, selected_page, name, Get_url_pos(), function (page) { - MarkSaved(); + Save_to_selected_page(db, selected_page, name, DesignerMove.getUrlPos(), function (page) { + DesignerMove.markSaved(); if (typeof callback !== 'undefined') { callback(); } }); } -} +}; - -function submitSaveDialogAndClose (callback) { +DesignerMove.submitSaveDialogAndClose = function (callback) { var $form = $('#save_page'); var name = $form.find('input[name="selected_value"]').val().trim(); if (name === '') { @@ -731,12 +715,12 @@ function submitSaveDialogAndClose (callback) { if (designer_tables_enabled) { var $msgbox = Functions.ajaxShowMessage(Messages.strProcessingRequest); Functions.prepareForAjaxRequest($form); - $.post($form.attr('action'), $form.serialize() + Get_url_pos(), function (data) { + $.post($form.attr('action'), $form.serialize() + DesignerMove.getUrlPos(), function (data) { if (data.success === false) { Functions.ajaxShowMessage(data.error, false); } else { Functions.ajaxRemoveMessage($msgbox); - MarkSaved(); + DesignerMove.markSaved(); if (data.id) { selected_page = data.id; } @@ -747,8 +731,8 @@ function submitSaveDialogAndClose (callback) { } }); } else { - Save_to_new_page(db, name, Get_url_pos(), function (page) { - MarkSaved(); + Save_to_new_page(db, name, DesignerMove.getUrlPos(), function (page) { + DesignerMove.markSaved(); if (page.pg_nr) { selected_page = page.pg_nr; } @@ -758,11 +742,11 @@ function submitSaveDialogAndClose (callback) { } }); } -} +}; -function Save3 (callback) { +DesignerMove.save3 = function (callback) { if (parseInt(selected_page) !== -1) { - Save2(callback); + DesignerMove.save2(callback); } else { var button_options = {}; button_options[Messages.strGo] = function () { @@ -782,7 +766,7 @@ function Save3 (callback) { ':'); $form.on('submit', function (e) { e.preventDefault(); - submitSaveDialogAndClose(callback); + DesignerMove.submitSaveDialogAndClose(callback); }); $('
') .append($form) @@ -797,11 +781,11 @@ function Save3 (callback) { } }); } -} +}; // ------------------------------ EDIT PAGES ------------------------------------------ -function Edit_pages () { - Prompt_to_save_current_page(function () { +DesignerMove.editPages = function () { + DesignerMove.promptToSaveCurrentPage(function () { var button_options = {}; button_options[Messages.strGo] = function () { var $form = $('#edit_delete_pages'); @@ -811,7 +795,7 @@ function Edit_pages () { return; } $(this).dialog('close'); - Load_page(selected); + DesignerMove.loadPage(selected); }; button_options[Messages.strCancel] = function () { $(this).dialog('close'); @@ -849,10 +833,10 @@ function Edit_pages () { } }); // end $.get() }); -} +}; // ----------------------------- DELETE PAGES --------------------------------------- -function Delete_pages () { +DesignerMove.deletePages = function () { var button_options = {}; button_options[Messages.strGo] = function () { var $form = $('#edit_delete_pages'); @@ -873,7 +857,7 @@ function Delete_pages () { } else { Functions.ajaxRemoveMessage($msgbox); if (deleting_current_page) { - Load_page(null); + DesignerMove.loadPage(null); } else { Functions.ajaxShowMessage(Messages.strSuccessfulPageDelete); } @@ -886,7 +870,7 @@ function Delete_pages () { } else { Functions.ajaxRemoveMessage($msgbox); if (deleting_current_page) { - Load_page(null); + DesignerMove.loadPage(null); } else { Functions.ajaxShowMessage(Messages.strSuccessfulPageDelete); } @@ -932,10 +916,10 @@ function Delete_pages () { }); } }); // end $.get() -} +}; // ------------------------------ SAVE AS PAGES --------------------------------------- -function Save_as () { +DesignerMove.saveAs = function () { var button_options = {}; button_options[Messages.strGo] = function () { var $form = $('#save_as_pages'); @@ -961,12 +945,12 @@ function Save_as () { var $msgbox = Functions.ajaxShowMessage(Messages.strProcessingRequest); if (designer_tables_enabled) { Functions.prepareForAjaxRequest($form); - $.post($form.attr('action'), $form.serialize() + Get_url_pos(), function (data) { + $.post($form.attr('action'), $form.serialize() + DesignerMove.getUrlPos(), function (data) { if (data.success === false) { Functions.ajaxShowMessage(data.error, false); } else { Functions.ajaxRemoveMessage($msgbox); - MarkSaved(); + DesignerMove.markSaved(); if (data.id) { selected_page = data.id; } @@ -976,18 +960,18 @@ function Save_as () { } else { if (choice === 'same') { var selected_page_id = $selected_page.find('option:selected').val(); - Save_to_selected_page(db, selected_page_id, name, Get_url_pos(), function (page) { + Save_to_selected_page(db, selected_page_id, name, DesignerMove.getUrlPos(), function (page) { Functions.ajaxRemoveMessage($msgbox); - MarkSaved(); + DesignerMove.markSaved(); if (page.pg_nr) { selected_page = page.pg_nr; } $('#page_name').text(page.page_descr); }); } else if (choice === 'new') { - Save_to_new_page(db, name, Get_url_pos(), function (page) { + Save_to_new_page(db, name, DesignerMove.getUrlPos(), function (page) { Functions.ajaxRemoveMessage($msgbox); - MarkSaved(); + DesignerMove.markSaved(); if (page.pg_nr) { selected_page = page.pg_nr; } @@ -1038,14 +1022,14 @@ function Save_as () { } } }); // end $.get() -} +}; -function Prompt_to_save_current_page (callback) { +DesignerMove.promptToSaveCurrentPage = function (callback) { if (_change === 1 || selected_page === '-1') { var button_options = {}; button_options[Messages.strYes] = function () { $(this).dialog('close'); - Save3(callback); + DesignerMove.save3(callback); }; button_options[Messages.strNo] = function () { $(this).dialog('close'); @@ -1069,10 +1053,10 @@ function Prompt_to_save_current_page (callback) { } else { callback(); } -} +}; // ------------------------------ EXPORT PAGES --------------------------------------- -function Export_pages () { +DesignerMove.exportPages = function () { var button_options = {}; button_options[Messages.strGo] = function () { $('#id_export_pages').submit(); @@ -1100,7 +1084,7 @@ function Export_pages () { if (!designer_tables_enabled) { $form.append(''); } - $.each(Get_url_pos(true).substring(1).split(argsep), function () { + $.each(DesignerMove.getUrlPos(true).substring(1).split(argsep), function () { var pair = this.split('='); var input = $(''); input.attr('name', pair[0]); @@ -1128,9 +1112,9 @@ function Export_pages () { }); } }); // end $.get() -}// end export pages +}; -function Load_page (page) { +DesignerMove.loadPage = function (page) { if (designer_tables_enabled) { var param_page = ''; var argsep = CommonParams.get('arg_separator'); @@ -1149,10 +1133,10 @@ function Load_page (page) { Show_new_page_tables(true); } } - MarkSaved(); -} + DesignerMove.markSaved(); +}; -function Grid () { +DesignerMove.grid = function () { var value_sent = ''; if (!ON_grid) { ON_grid = 1; @@ -1163,10 +1147,10 @@ function Grid () { ON_grid = 0; value_sent = 'off'; } - saveValueInConfig('snap_to_grid', value_sent); -} + DesignerMove.saveValueInConfig('snap_to_grid', value_sent); +}; -function Angular_direct () { +DesignerMove.angularDirect = function () { var value_sent = ''; if (ON_angular_direct) { ON_angular_direct = 0; @@ -1177,11 +1161,11 @@ function Angular_direct () { value_sent = 'direct'; document.getElementById('angular_direct_button').className = 'M_butt'; } - saveValueInConfig('angular_direct', value_sent); - Re_load(); -} + DesignerMove.saveValueInConfig('angular_direct', value_sent); + DesignerMove.reload(); +}; -function saveValueInConfig (index_sent, value_sent) { +DesignerMove.saveValueInConfig = function (index_sent, value_sent) { $.post('db_designer.php', { operation: 'save_setting_value', index: index_sent, ajax_request: true, server: server, value: value_sent }, function (data) { @@ -1189,10 +1173,10 @@ function saveValueInConfig (index_sent, value_sent) { Functions.ajaxShowMessage(data.error, false); } }); -} +}; // ++++++++++++++++++++++++++++++ RELATION ++++++++++++++++++++++++++++++++++++++ -function Start_relation () { +DesignerMove.startRelation = function () { if (ON_display_field) { return; } @@ -1210,10 +1194,10 @@ function Start_relation () { click_field = 0; ON_relation = 0; } -} +}; // table field -function Click_field (db, T, f, PK) { +DesignerMove.clickField = function (db, T, f, PK) { PK = parseInt(PK); var argsep = CommonParams.get('arg_separator'); if (ON_relation) { @@ -1230,7 +1214,7 @@ function Click_field (db, T, f, PK) { link_relation = 'DB1=' + db + argsep + 'T1=' + T + argsep + 'F1=' + f; document.getElementById('designer_hint').innerHTML = Messages.strSelectForeignKey; } else { - Start_relation(); // hidden hint... + DesignerMove.startRelation(); // hidden hint... if (j_tabs[db + '.' + T] !== 1 || !PK) { document.getElementById('foreign_relation').style.display = 'none'; } @@ -1273,9 +1257,9 @@ function Click_field (db, T, f, PK) { } }); } -} +}; -function New_relation () { +DesignerMove.newRelation = function () { document.getElementById('layer_new_relation').style.display = 'none'; var argsep = CommonParams.get('arg_separator'); link_relation += argsep + 'server=' + server + argsep + 'db=' + db + argsep + 'db2=p'; @@ -1288,26 +1272,25 @@ function New_relation () { Functions.ajaxShowMessage(data.error, false); } else { Functions.ajaxRemoveMessage($msgbox); - Load_page(selected_page); + DesignerMove.loadPage(selected_page); } }); // end $.post() -} +}; // -------------------------- create tables ------------------------------------- - -function Start_table_new () { +DesignerMove.startTableNew = function () { CommonParams.set('table', ''); CommonActions.refreshMain('tbl_create.php'); -} +}; -function Start_tab_upd (table) { +DesignerMove.startTabUpd = function (table) { CommonParams.set('table', table); CommonActions.refreshMain('tbl_structure.php'); -} -// --------------------------- hide tables -------------------------------------- +}; +// --------------------------- hide tables -------------------------------------- // max/min all tables -function Small_tab_all (id_this) { +DesignerMove.smallTabAll = function (id_this) { var icon = id_this.children[0]; var key; var value_sent = ''; @@ -1315,7 +1298,7 @@ function Small_tab_all (id_this) { if (icon.alt === 'v') { for (key in j_tabs) { if (document.getElementById('id_hide_tbody_' + key).innerHTML === 'v') { - Small_tab(key, 0); + DesignerMove.smallTab(key, 0); } } icon.alt = '>'; @@ -1324,44 +1307,44 @@ function Small_tab_all (id_this) { } else { for (key in j_tabs) { if (document.getElementById('id_hide_tbody_' + key).innerHTML !== 'v') { - Small_tab(key, 0); + DesignerMove.smallTab(key, 0); } } icon.alt = 'v'; icon.src = icon.dataset.down; value_sent = '>'; } - saveValueInConfig('small_big_all', value_sent); + DesignerMove.saveValueInConfig('small_big_all', value_sent); $('#key_SB_all').toggleClass('M_butt_Selected_down'); $('#key_SB_all').toggleClass('M_butt'); - Re_load(); -} + DesignerMove.reload(); +}; // invert max/min all tables -function Small_tab_invert () { +DesignerMove.smallTabInvert = function () { for (var key in j_tabs) { - Small_tab(key, 0); + DesignerMove.smallTab(key, 0); } - Re_load(); -} + DesignerMove.reload(); +}; -function Relation_lines_invert () { +DesignerMove.relationLinesInvert = function () { show_relation_lines = ! show_relation_lines; - saveValueInConfig('relation_lines', show_relation_lines); + DesignerMove.saveValueInConfig('relation_lines', show_relation_lines); $('#relLineInvert').toggleClass('M_butt_Selected_down'); $('#relLineInvert').toggleClass('M_butt'); - Re_load(); -} + DesignerMove.reload(); +}; -function Small_tab_refresh () { +DesignerMove.smallTabRefresh = function () { for (var key in j_tabs) { if (document.getElementById('id_hide_tbody_' + key).innerHTML !== 'v') { - Small_tab(key, 0); + DesignerMove.smallTab(key, 0); } } -} +}; -function Small_tab (t, re_load) { +DesignerMove.smallTab = function (t, re_load) { var id = document.getElementById('id_tbody_' + t); var id_this = document.getElementById('id_hide_tbody_' + t); var id_t = document.getElementById(t); @@ -1374,11 +1357,11 @@ function Small_tab (t, re_load) { id_this.innerHTML = 'v'; } if (re_load) { - Re_load(); + DesignerMove.reload(); } -} -// ------------------------------------------------------------------------------ -function Select_tab (t) { +}; + +DesignerMove.selectTab = function (t) { var id_zag = document.getElementById('id_zag_' + t); if (id_zag.className !== 'tab_zag_3') { document.getElementById('id_zag_' + t).className = 'tab_zag_2'; @@ -1394,10 +1377,9 @@ function Select_tab (t) { }, 800 ); -} -// ------------------------------------------------------------------------------ +}; -function Canvas_click (id, event) { +DesignerMove.canvasClick = function (id, event) { var n = 0; var relation_name = 0; var selected = 0; @@ -1417,7 +1399,7 @@ function Canvas_click (id, event) { var Local_Y = isIE ? event.clientY + document.body.scrollTop : event.pageY; Local_X -= $('#osn_tab').offset().left; Local_Y -= $('#osn_tab').offset().top; - Clear(); + DesignerMove.clear(); for (K in contr) { for (key in contr[K]) { for (key2 in contr[K][key]) { @@ -1470,27 +1452,27 @@ function Canvas_click (id, event) { document.getElementById(contr[K][key][key2][key3][0] + '.' + contr[K][key][key2][key3][1]).offsetTop + height_field; if (!selected && Local_X > x1 - 10 && Local_X < x1 + 10 && Local_Y > y1 - 7 && Local_Y < y1 + 7) { - Line0( + DesignerMove.line0( x1 + osn_tab.offsetLeft, y1 - osn_tab.offsetTop, x2 + osn_tab.offsetLeft, y2 - osn_tab.offsetTop, 'rgba(255,0,0,1)'); - selected = 1; // Rect(x1-sm_x,y1-sm_y,10,10,"rgba(0,255,0,1)"); - relation_name = key; // + selected = 1; + relation_name = key; Key0 = contr[K][key][key2][key3][0]; Key1 = contr[K][key][key2][key3][1]; Key2 = key2; Key3 = key3; Key = K; } else { - Line0( + DesignerMove.line0( x1 + osn_tab.offsetLeft, y1 - osn_tab.offsetTop, x2 + osn_tab.offsetLeft, y2 - osn_tab.offsetTop, - getColorByTarget(contr[K][key][key2][key3][0] + '.' + contr[K][key][key2][key3][1]) + DesignerMove.getColorByTarget(contr[K][key][key2][key3][0] + '.' + contr[K][key][key2][key3][1]) ); } } @@ -1507,9 +1489,9 @@ function Canvas_click (id, event) { var argsep = CommonParams.get('arg_separator'); link_relation = 'T1=' + Key0 + argsep + 'F1=' + Key1 + argsep + 'T2=' + Key2 + argsep + 'F2=' + Key3 + argsep + 'K=' + Key; } -} +}; -function Upd_relation () { +DesignerMove.updRelation = function () { document.getElementById('layer_upd_relation').style.display = 'none'; var argsep = CommonParams.get('arg_separator'); link_relation += argsep + 'server=' + server + argsep + 'db=' + db; @@ -1521,22 +1503,22 @@ function Upd_relation () { Functions.ajaxShowMessage(data.error, false); } else { Functions.ajaxRemoveMessage($msgbox); - Load_page(selected_page); + DesignerMove.loadPage(selected_page); } }); // end $.post() -} +}; -function VisibleTab (id, t_n) { +DesignerMove.visibleTab = function (id, t_n) { if (id.checked) { document.getElementById(t_n).style.display = 'block'; } else { document.getElementById(t_n).style.display = 'none'; } - Re_load(); -} + DesignerMove.reload(); +}; // max/min all tables -function Hide_tab_all (id_this) { +DesignerMove.hideTabAll = function (id_this) { if (id_this.alt === 'v') { id_this.alt = '>'; id_this.src = id_this.dataset.right; @@ -1556,10 +1538,10 @@ function Hide_tab_all (id_this) { } } } - Re_load(); -} + DesignerMove.reload(); +}; -function in_array_k (x, m) { +DesignerMove.inArrayK = function (x, m) { var b = 0; for (var u in m) { if (x === u) { @@ -1568,9 +1550,9 @@ function in_array_k (x, m) { } } return b; -} +}; -function No_have_constr (id_this) { +DesignerMove.noHaveConstr = function (id_this) { var a = []; var K; var key; @@ -1599,7 +1581,7 @@ function No_have_constr (id_this) { var E = document.form1; for (var i = 0; i < E.elements.length; i++) { if (E.elements[i].type === 'checkbox' && E.elements[i].id.substring(0, 10) === 'check_vis_') { - if (!in_array_k(E.elements[i].value, a)) { + if (!DesignerMove.inArrayK(E.elements[i].value, a)) { if (id_this.alt === 'v') { E.elements[i].checked = true; document.getElementById(E.elements[i].value).style.display = ''; @@ -1610,16 +1592,9 @@ function No_have_constr (id_this) { } } } -} +}; -function General_scroll () { - /* - if (!document.getElementById('show_relation_olways').checked) { - document.getElementById("canvas").style.display = 'none'; - clearTimeout(timeoutID); - timeoutID = setTimeout(General_scroll_end, 500); - } - */ +DesignerMove.generalScroll = function () { // if (timeoutID) clearTimeout(timeoutID); timeoutID = setTimeout( @@ -1629,10 +1604,10 @@ function General_scroll () { }, 200 ); -} +}; // max/min all tables -function Show_left_menu (id_this) { +DesignerMove.showLeftMenu = function (id_this) { var icon = id_this.children[0]; $('#key_Show_left_menu').toggleClass('M_butt_Selected_down'); if (icon.alt === 'v') { @@ -1641,7 +1616,7 @@ function Show_left_menu (id_this) { icon.alt = '>'; icon.src = icon.dataset.up; if (isIE) { - General_scroll(); + DesignerMove.generalScroll(); } } else { document.getElementById('layer_menu').style.top = -1000 + 'px'; // fast scroll @@ -1649,9 +1624,9 @@ function Show_left_menu (id_this) { icon.alt = 'v'; icon.src = icon.dataset.down; } -} -// ------------------------------------------------------------------------------ -function Side_menu_right (id_this) { +}; + +DesignerMove.sideMenuRight = function (id_this) { $('#side_menu').toggleClass('right'); $('#layer_menu').toggleClass('left'); var icon = $(id_this.childNodes[0]); @@ -1666,27 +1641,29 @@ function Side_menu_right (id_this) { icon.attr('src', icon.attr('data-right')); icon.attr('data-right', current); menu_moved = !menu_moved; - saveValueInConfig('side_menu', $('#side_menu').hasClass('right')); + DesignerMove.saveValueInConfig('side_menu', $('#side_menu').hasClass('right')); $('#key_Left_Right').toggleClass('M_butt_Selected_down'); $('#key_Left_Right').toggleClass('M_butt'); -} -// ------------------------------------------------------------------------------ -function Show_text () { +}; + +DesignerMove.showText = function () { $('#side_menu').find('.hidable').show(); -} -function Hide_text () { +}; + +DesignerMove.hideText = function () { if (!always_show_text) { $('#side_menu').find('.hidable').hide(); } -} -function Pin_text () { +}; + +DesignerMove.pinText = function () { always_show_text = !always_show_text; $('#pin_Text').toggleClass('M_butt_Selected_down'); $('#pin_Text').toggleClass('M_butt'); - saveValueInConfig('pin_text', always_show_text); -} -// ------------------------------------------------------------------------------ -function Start_display_field () { + DesignerMove.saveValueInConfig('pin_text', always_show_text); +}; + +DesignerMove.startDisplayField = function () { if (ON_relation) { return; } @@ -1705,10 +1682,11 @@ function Start_display_field () { document.getElementById('display_field_button').className = 'M_butt'; ON_display_field = 0; } -} -// ------------------------------------------------------------------------------ +}; + var TargetColors = []; -function getColorByTarget (target) { + +DesignerMove.getColorByTarget = function (target) { var color = ''; // "rgba(0,100,150,1)"; for (var a in TargetColors) { @@ -1746,9 +1724,9 @@ function getColorByTarget (target) { } return color; -} +}; -function Click_option (id_this, column_name, table_name) { +DesignerMove.clickOption = function (id_this, column_name, table_name) { var left = Glob_X - (document.getElementById(id_this).offsetWidth >> 1); document.getElementById(id_this).style.left = left + 'px'; // var top = Glob_Y - document.getElementById(id_this).offsetHeight - 10; @@ -1757,9 +1735,9 @@ function Click_option (id_this, column_name, table_name) { document.getElementById('option_col_name').innerHTML = '' + Functions.sprintf(Messages.strAddOption, decodeURI(column_name)) + ''; col_name = column_name; tab_name = table_name; -} +}; -function Close_option () { +DesignerMove.closeOption = function () { document.getElementById('designer_optionse').style.display = 'none'; document.getElementById('rel_opt').value = '--'; document.getElementById('Query').value = ''; @@ -1770,9 +1748,9 @@ function Close_option () { document.getElementById('h_operator').value = '---'; document.getElementById('having').value = ''; document.getElementById('orderby').value = '---'; -} +}; -function Select_all (id_this, owner) { +DesignerMove.selectAll = function (id_this, owner) { var parent = document.form1; downer = owner; var i; @@ -1807,10 +1785,10 @@ function Select_all (id_this, owner) { } } } - Re_load(); -} + DesignerMove.reload(); +}; -function Table_onover (id_this, val, buil) { +DesignerMove.tableOnOver = function (id_this, val, buil) { buil = parseInt(buil); if (!val) { document.getElementById('id_zag_' + id_this).className = 'tab_zag_2'; @@ -1823,13 +1801,13 @@ function Table_onover (id_this, val, buil) { document.getElementById('id_zag_' + id_this + '_2').className = 'tab_zag'; } } -} +}; -/* This function stores selected column information in select_field[] +/** + * This function stores selected column information in select_field[] * In case column is checked it add else it deletes - * */ -function store_column (id_this, owner, col) { +DesignerMove.storeColumn = function (id_this, owner, col) { var i; var k; if (document.getElementById('select_' + owner + '.' + id_this + '._' + col).checked === true) { @@ -1849,16 +1827,14 @@ function store_column (id_this, owner, col) { } } } -} +}; /** * This function builds object and adds them to history_array * first it does a few checks on each object, then makes an object(where,rename,groupby,aggregate,orderby) * then a new history object is made and finally all these history objects are added to history_array[] - * -**/ - -function add_object () { + */ +DesignerMove.addObject = function () { var p; var where_obj; var rel = document.getElementById('rel_opt'); @@ -1913,9 +1889,9 @@ function add_object () { // output sum new objects created var existingDiv = document.getElementById('ab'); existingDiv.innerHTML = display(init, history_array.length); - Close_option(); + DesignerMove.closeOption(); $('#ab').accordion('refresh'); -} +}; AJAX.registerTeardown('designer/move.js', function () { $('#side_menu').off('mouseenter mouseleave'); @@ -1969,173 +1945,173 @@ AJAX.registerTeardown('designer/move.js', function () { AJAX.registerOnload('designer/move.js', function () { $('#key_Show_left_menu').on('click', function () { - Show_left_menu(this); + DesignerMove.showLeftMenu(this); return false; }); $('#toggleFullscreen').on('click', function () { - Toggle_fullscreen(); + DesignerMove.toggleFullscreen(); return false; }); $('#addOtherDbTables').on('click', function () { - Add_Other_db_tables(); + DesignerMove.addOtherDbTables(); return false; }); $('#newPage').on('click', function () { - New(); + DesignerMove.new(); return false; }); $('#editPage').on('click', function () { - Edit_pages(); + DesignerMove.editPages(); return false; }); $('#savePos').on('click', function () { - Save3(); + DesignerMove.save3(); return false; }); $('#SaveAs').on('click', function () { - Save_as(); + DesignerMove.saveAs(); return false; }); $('#delPages').on('click', function () { - Delete_pages(); + DesignerMove.deletePages(); return false; }); $('#StartTableNew').on('click', function () { - Start_table_new(); + DesignerMove.startTableNew(); return false; }); $('#rel_button').on('click', function () { - Start_relation(); + DesignerMove.startRelation(); return false; }); $('#display_field_button').on('click', function () { - Start_display_field(); + DesignerMove.startDisplayField(); return false; }); $('#reloadPage').on('click', function () { $('#designer_tab').trigger('click'); }); $('#angular_direct_button').on('click', function () { - Angular_direct(); + DesignerMove.angularDirect(); return false; }); $('#grid_button').on('click', function () { - Grid(); + DesignerMove.grid(); return false; }); $('#key_SB_all').on('click', function () { - Small_tab_all(this); + DesignerMove.smallTabAll(this); return false; }); $('#SmallTabInvert').on('click', function () { - Small_tab_invert(); + DesignerMove.smallTabInvert(); return false; }); $('#relLineInvert').on('click', function () { - Relation_lines_invert(); + DesignerMove.relationLinesInvert(); return false; }); $('#exportPages').on('click', function () { - Export_pages(); + DesignerMove.exportPages(); return false; }); $('#query_builder').on('click', function () { build_query('SQL Query on Database', 0); }); $('#key_Left_Right').on('click', function () { - Side_menu_right(this); + DesignerMove.sideMenuRight(this); return false; }); $('#side_menu').hover(function () { - Show_text(); + DesignerMove.showText(); return false; }, function () { - Hide_text(); + DesignerMove.hideText(); return false; }); $('#pin_Text').on('click', function () { - Pin_text(this); + DesignerMove.pinText(this); return false; }); $('#canvas').on('click', function (event) { - Canvas_click(this, event); + DesignerMove.canvasClick(this, event); }); $('#key_HS_all').on('click', function () { - Hide_tab_all(this); + DesignerMove.hideTabAll(this); return false; }); $('#key_HS').on('click', function () { - No_have_constr(this); + DesignerMove.noHaveConstr(this); return false; }); $('.scroll_tab_struct').on('click', function () { - Start_tab_upd($(this).attr('table_name')); + DesignerMove.startTabUpd($(this).attr('table_name')); }); $('.scroll_tab_checkbox').on('click', function () { - VisibleTab(this,$(this).val()); + DesignerMove.visibleTab(this,$(this).val()); }); $('#id_scroll_tab').find('tr').on('click', '.designer_Tabs2,.designer_Tabs', function () { - Select_tab($(this).attr('designer_url_table_name')); + DesignerMove.selectTab($(this).attr('designer_url_table_name')); }); $('.designer_tab').on('click', '.select_all_1', function () { - Select_all($(this).attr('designer_url_table_name'), $(this).attr('designer_out_owner')); + DesignerMove.selectAll($(this).attr('designer_url_table_name'), $(this).attr('designer_out_owner')); }); $('.designer_tab').on('click', '.small_tab,.small_tab2', function () { - Small_tab($(this).attr('table_name'), 1); + DesignerMove.smallTab($(this).attr('table_name'), 1); }); $('.designer_tab').on('click', '.small_tab_pref_1', function () { - Start_tab_upd($(this).attr('table_name_small')); + DesignerMove.startTabUpd($(this).attr('table_name_small')); }); $('.tab_zag_noquery').mouseover(function () { - Table_onover($(this).attr('table_name'),0, $(this).attr('query_set')); + DesignerMove.tableOnOver($(this).attr('table_name'),0, $(this).attr('query_set')); }); $('.tab_zag_noquery').mouseout(function () { - Table_onover($(this).attr('table_name'),1, $(this).attr('query_set')); + DesignerMove.tableOnOver($(this).attr('table_name'),1, $(this).attr('query_set')); }); $('.tab_zag_query').mouseover(function () { - Table_onover($(this).attr('table_name'),0, 1); + DesignerMove.tableOnOver($(this).attr('table_name'),0, 1); }); $('.tab_zag_query').mouseout(function () { - Table_onover($(this).attr('table_name'),1, 1); + DesignerMove.tableOnOver($(this).attr('table_name'),1, 1); }); $('.designer_tab').on('click','.tab_field_2,.tab_field_3,.tab_field', function () { var params = ($(this).attr('click_field_param')).split(','); - Click_field(params[3], params[0], params[1], params[2]); + DesignerMove.clickField(params[3], params[0], params[1], params[2]); }); $('.designer_tab').on('click', '.select_all_store_col', function () { var params = ($(this).attr('store_column_param')).split(','); - store_column(params[0], params[1], params[2]); + DesignerMove.storeColumn(params[0], params[1], params[2]); }); $('.designer_tab').on('click', '.small_tab_pref_click_opt', function () { var params = ($(this).attr('Click_option_param')).split(','); - Click_option(params[0], params[1], params[2]); + DesignerMove.clickOption(params[0], params[1], params[2]); }); $('input#del_button').on('click', function () { - Upd_relation(); + DesignerMove.updRelation(); }); $('input#cancel_button').on('click', function () { document.getElementById('layer_upd_relation').style.display = 'none'; - Re_load(); + DesignerMove.reload(); }); $('input#ok_add_object').on('click', function () { - add_object(); + DesignerMove.addObject(); }); $('input#cancel_close_option').on('click', function () { - Close_option(); + DesignerMove.closeOption(); }); $('input#ok_new_rel_panel').on('click', function () { - New_relation(); + DesignerMove.newRelation(); }); $('input#cancel_new_rel_panel').on('click', function () { document.getElementById('layer_new_relation').style.display = 'none'; }); $('#page_content').on('mousedown', function (e) { - MouseDown(e); + DesignerMove.mouseDown(e); }); $('#page_content').on('mouseup', function (e) { - MouseUp(e); + DesignerMove.mouseUp(e); }); $('#page_content').on('mousemove', function (e) { - MouseMove(e); + DesignerMove.mouseMove(e); }); }); diff --git a/js/designer/page.js b/js/designer/page.js index e6e5585492a1..c60d5bf7ed8c 100644 --- a/js/designer/page.js +++ b/js/designer/page.js @@ -110,19 +110,19 @@ function Show_new_page_tables (check) { var element = document.getElementById(input.value); element.style.top = Get_random(550, 20) + 'px'; element.style.left = Get_random(700, 20) + 'px'; - VisibleTab(input, input.value); + DesignerMove.visibleTab(input, input.value); } } selected_page = -1; $('#page_name').text(Messages.strUntitled); - MarkUnsaved(); + DesignerMove.markUnsaved(); } function Load_HTML_for_page (page_id) { Show_new_page_tables(false); Load_page_objects(page_id, function (page, tbl_cords) { $('#name-panel').find('#page_name').text(page.page_descr); - MarkSaved(); + DesignerMove.markSaved(); for (var t = 0; t < tbl_cords.length; t++) { var tb_id = db + '.' + tbl_cords[t].table_name; var table = document.getElementById(tb_id); @@ -131,7 +131,7 @@ function Load_HTML_for_page (page_id) { var checkbox = document.getElementById('check_vis_' + tb_id); checkbox.checked = true; - VisibleTab(checkbox, checkbox.value); + DesignerMove.visibleTab(checkbox, checkbox.value); } selected_page = page.pg_nr; });