1 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 * for server_synchronize.php
7 // Global variable row_class is set to even
8 var row_class = 'even';
11 * Generates a row dynamically in the differences table displaying
12 * the complete statistics of difference in table like number of
13 * rows to be updated, number of rows to be inserted, number of
14 * columns to be added, number of columns to be removed, etc.
16 * @param index index of matching table
17 * @param update_size number of rows/column to be updated
18 * @param insert_size number of rows/coulmns to be inserted
19 * @param remove_size number of columns to be removed
20 * @param insert_index number of indexes to be inserted
21 * @param remove_index number of indexes to be removed
22 * @param img_obj image object
23 * @param table_name name of the table
26 function showDetails(i, update_size, insert_size, remove_size, insert_index, remove_index, img_obj, table_name)
29 var $img = $(img_obj);
31 $img.toggleClass('selected');
33 // The image source is changed when the showDetails function is called.
34 if ($img.hasClass('selected')) {
35 if ($img.hasClass('struct_img')) {
36 $img.attr('src', pmaThemeImage + 'new_struct_selected.jpg');
38 if ($img.hasClass('data_img')) {
39 $img.attr('src', pmaThemeImage + 'new_data_selected.jpg');
42 if ($img.hasClass('struct_img')) {
43 $img.attr('src', pmaThemeImage + 'new_struct.jpg');
45 if ($img.hasClass('data_img')) {
46 $img.attr('src', pmaThemeImage + 'new_data.jpg');
50 var div = document.getElementById("list");
51 var table = div.getElementsByTagName("table")[0];
52 var table_body = table.getElementsByTagName("tbody")[0];
54 //Global variable row_class is being used
55 if (row_class == 'even') {
60 // If the red or green button against a table name is pressed then append a new row to show the details of differences of this table.
61 if ($img.hasClass('selected')) {
62 var newRow = document.createElement("tr");
63 newRow.setAttribute("class", row_class);
64 newRow.className = row_class;
65 // Id assigned to this row element is same as the index of this table name in the matching_tables/source_tables_uncommon array
66 newRow.setAttribute("id" , i);
68 var table_name_cell = document.createElement("td");
69 table_name_cell.align = "center";
70 table_name_cell.innerHTML = table_name ;
72 newRow.appendChild(table_name_cell);
74 var create_table = document.createElement("td");
75 create_table.align = "center";
77 var add_cols = document.createElement("td");
78 add_cols.align = "center";
80 var remove_cols = document.createElement("td");
81 remove_cols.align = "center";
83 var alter_cols = document.createElement("td");
84 alter_cols.align = "center";
86 var add_index = document.createElement("td");
87 add_index.align = "center";
89 var delete_index = document.createElement("td");
90 delete_index.align = "center";
92 var update_rows = document.createElement("td");
93 update_rows.align = "center";
95 var insert_rows = document.createElement("td");
96 insert_rows.align = "center";
98 var tick_image = document.createElement("img");
99 tick_image.src = pmaThemeImage + "s_success.png";
101 if (update_size == '' && insert_size == '' && remove_size == '') {
103 This is the case when the table needs to be created in target database.
105 create_table.appendChild(tick_image);
106 add_cols.innerHTML = "--";
107 remove_cols.innerHTML = "--";
108 alter_cols.innerHTML = "--";
109 delete_index.innerHTML = "--";
110 add_index.innerHTML = "--";
111 update_rows.innerHTML = "--";
112 insert_rows.innerHTML = "--";
114 newRow.appendChild(create_table);
115 newRow.appendChild(add_cols);
116 newRow.appendChild(remove_cols);
117 newRow.appendChild(alter_cols);
118 newRow.appendChild(delete_index);
119 newRow.appendChild(add_index);
120 newRow.appendChild(update_rows);
121 newRow.appendChild(insert_rows);
123 } else if (update_size == '' && remove_size == '') {
125 This is the case when data difference is displayed in the
126 table which is present in source but absent from target database
128 create_table.innerHTML = "--";
129 add_cols.innerHTML = "--";
130 remove_cols.innerHTML = "--";
131 alter_cols.innerHTML = "--";
132 add_index.innerHTML = "--";
133 delete_index.innerHTML = "--";
134 update_rows.innerHTML = "--";
135 insert_rows.innerHTML = insert_size;
137 newRow.appendChild(create_table);
138 newRow.appendChild(add_cols);
139 newRow.appendChild(remove_cols);
140 newRow.appendChild(alter_cols);
141 newRow.appendChild(delete_index);
142 newRow.appendChild(add_index);
143 newRow.appendChild(update_rows);
144 newRow.appendChild(insert_rows);
146 } else if (remove_size == '') {
148 This is the case when data difference between matching_tables is displayed.
150 create_table.innerHTML = "--";
151 add_cols.innerHTML = "--";
152 remove_cols.innerHTML = "--";
153 alter_cols.innerHTML = "--";
154 add_index.innerHTML = "--";
155 delete_index.innerHTML = "--";
156 update_rows.innerHTML = update_size;
157 insert_rows.innerHTML = insert_size;
159 newRow.appendChild(create_table);
160 newRow.appendChild(add_cols);
161 newRow.appendChild(remove_cols);
162 newRow.appendChild(alter_cols);
163 newRow.appendChild(delete_index);
164 newRow.appendChild(add_index);
165 newRow.appendChild(update_rows);
166 newRow.appendChild(insert_rows);
170 This is the case when structure difference between matching_tables id displayed
172 create_table.innerHTML = "--";
173 add_cols.innerHTML = insert_size;
174 remove_cols.innerHTML = remove_size;
175 alter_cols.innerHTML = update_size;
176 delete_index.innerHTML = remove_index;
177 add_index.innerHTML = insert_index;
178 update_rows.innerHTML = "--";
179 insert_rows.innerHTML = "--";
181 newRow.appendChild(create_table);
182 newRow.appendChild(add_cols);
183 newRow.appendChild(remove_cols);
184 newRow.appendChild(alter_cols);
185 newRow.appendChild(delete_index);
186 newRow.appendChild(add_index);
187 newRow.appendChild(update_rows);
188 newRow.appendChild(insert_rows);
190 table_body.appendChild(newRow);
193 //The case when the row showing the details need to be removed from the table i.e. the difference button is deselected now.
194 var table_rows = table_body.getElementsByTagName("tr");
197 for (j=0; j < table_rows.length; j++)
199 if (table_rows[j].id == i) {
201 table_rows[j].parentNode.removeChild(table_rows[j]);
204 //The table row css is being adjusted. Class "odd" for odd rows and "even" for even rows should be maintained.
205 for(index = 0; index < table_rows.length; index++)
207 row_class_element = table_rows[index].getAttribute('class');
208 if (row_class_element == "even") {
209 table_rows[index].setAttribute("class","odd"); // for Mozilla firefox
210 table_rows[index].className = "odd"; // for IE browser
212 table_rows[index].setAttribute("class","even"); // for Mozilla firefox
213 table_rows[index].className = "even"; // for IE browser
220 * Generates the URL containing the list of selected table ids for synchronization and
221 * a variable checked for confirmation of deleting previous rows from target tables
223 * @param token the token generated for each PMA form
226 function ApplySelectedChanges(token)
228 var div = document.getElementById("list");
229 var table = div.getElementsByTagName('table')[0];
230 var table_body = table.getElementsByTagName('tbody')[0];
231 // Get all the rows from the details table
232 var table_rows = table_body.getElementsByTagName('tr');
233 var x = table_rows.length;
236 Append the token at the beginning of the query string followed by
237 Table_ids that shows that "Apply Selected Changes" button is pressed
239 var append_string = "?token="+token+"&Table_ids="+1;
241 append_string += "&";
242 append_string += i+"="+table_rows[i].id;
245 // Getting the value of checkbox delete_rows
246 var checkbox = document.getElementById("delete_rows");
247 if (checkbox.checked){
248 append_string += "&checked=true";
250 append_string += "&checked=false";
252 //Appending the token and list of table ids in the URL
253 location.href += token;
254 location.href += append_string;
259 * Validates a partial form (source part or target part)
261 * @param which 'src' or 'trg'
262 * @return boolean whether the partial form is valid
265 function validateSourceOrTarget(which)
267 var partial_form_is_ok = true;
269 if ($("#" + which + "_type").val() != 'cur') {
270 // did not choose "current connection"
271 if ($("input[name='" + which + "_username']").val() == ''
272 || $("input[name='" + which + "_pass']").val() == ''
273 || $("input[name='" + which + "_db']").val() == ''
274 // must have at least a host or a socket
275 || ($("input[name='" + which + "_host']").val() == ''
276 && $("input[name='" + which + "_socket']").val() == '')
279 partial_form_is_ok = false;
282 return partial_form_is_ok;
285 * Displays an error message if any text field
286 * is left empty other than the port field, unless
287 * we are dealing with the "current connection" choice
289 * @return boolean whether the form is valid
291 function validateConnectionParams()
293 var form_is_ok = true;
295 if (! validateSourceOrTarget('src') || ! validateSourceOrTarget('trg')) {
299 alert(PMA_messages['strFormEmpty']);
304 $(document).ready(function() {
305 $('.server_selector').change(function(evt) {
306 var server = $(evt.target).val();
307 if (server == 'cur') {
308 $(this).closest('tbody').children('.current-server').css('display', '');
309 $(this).closest('tbody').children('.remote-server').css('display', 'none');
310 } else if (server == 'rmt') {
311 $(this).closest('tbody').children('.current-server').css('display', 'none');
312 $(this).closest('tbody').children('.remote-server').css('display', '');
314 $(this).closest('tbody').children('.current-server').css('display', 'none');
315 $(this).closest('tbody').children('.remote-server').css('display', '');
316 var parts = server.split('||||');
317 $(this).closest('tbody').find('.server-host').val(parts[0]);
318 $(this).closest('tbody').find('.server-port').val(parts[1]);
319 $(this).closest('tbody').find('.server-socket').val(parts[2]);
320 $(this).closest('tbody').find('.server-user').val(parts[3]);
321 $(this).closest('tbody').find('.server-pass').val('');
322 $(this).closest('tbody').find('.server-db').val(parts[4])
326 $('.struct_img').hover(
327 // pmaThemeImage comes from js/messages.php
329 // mouse enters the element
331 $img.addClass('hover');
332 if ($img.hasClass('selected')) {
333 $img.attr('src', pmaThemeImage + 'new_struct_selected_hovered.jpg');
335 $img.attr('src', pmaThemeImage + 'new_struct_hovered.jpg');
339 // mouse leaves the element
341 $img.removeClass('hover');
342 if ($img.hasClass('selected')) {
343 $img.attr('src', pmaThemeImage + 'new_struct_selected.jpg');
345 $img.attr('src', pmaThemeImage + 'new_struct.jpg');
350 $('.data_img').hover(
352 // mouse enters the element
354 $img.addClass('hover');
355 if ($img.hasClass('selected')) {
356 $img.attr('src', pmaThemeImage + 'new_data_selected_hovered.jpg');
358 $img.attr('src', pmaThemeImage + 'new_data_hovered.jpg');
362 // mouse leaves the element
364 $img.removeClass('hover');
365 if ($img.hasClass('selected')) {
366 $img.attr('src', pmaThemeImage + 'new_data_selected.jpg');
368 $img.attr('src', pmaThemeImage + 'new_data.jpg');
373 $('#buttonGo').click(function(event) {
374 if (! validateConnectionParams()) {
375 event.preventDefault();