From 2142f5f70be44da2a169da402bf262ad654b8212 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 9 Apr 2010 16:09:29 +0200 Subject: [PATCH] Rewrite generating master configuration. - Avoid code duplication. - Fix case when user unselected all databases. --- js/replication.js | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/js/replication.js b/js/replication.js index c3e77e83f..1a7c785b0 100644 --- a/js/replication.js +++ b/js/replication.js @@ -3,30 +3,31 @@ * for server_replication.php * */ -$(document).ready(function() { - var conf_database_list = ""; - var random_server_id = Math.floor(Math.random() * 10000000); - var conf_prefix = "server-id=" + random_server_id + "
log-bin=mysql-bin
log-error=mysql-bin.err
"; + +var random_server_id = Math.floor(Math.random() * 10000000); +var conf_prefix = "server-id=" + random_server_id + "
log-bin=mysql-bin
log-error=mysql-bin.err
"; + +function update_config() { var conf_ignore = "binlog_ignore_db="; var conf_do = "binlog_do_db="; + var database_list = $('#db_select option:selected:first').val(); + $('#db_select option:selected:not(:first)').each(function() { + database_list += ',' + $(this).val(); + }); + + if ($('#db_select option:selected').size() == 0) { + $('#rep').html(conf_prefix); + } else if ($('#db_type option:selected').val() == 'all') { + $('#rep').html(conf_prefix + conf_ignore + database_list); + } else { + $('#rep').html(conf_prefix + conf_do + database_list); + } +} + +$(document).ready(function() { $('#rep').html(conf_prefix); - $('#db_type').change(function() { - if ($('#db_type option:selected').val() == 'all') - $('#rep').html(conf_prefix + conf_ignore + conf_database_list); - else - $('#rep').html(conf_prefix + conf_do + conf_database_list); - }); - $('#db_select').change(function() { - conf_database_list = $('#db_select option:selected:first').val(); - $('#db_select option:selected:not(:first)').each(function() { - conf_database_list += ',' + $(this).val(); - }); - // todo: avoid repeating these 5 lines: - if ($('#db_type option:selected').val() == 'all') - $('#rep').html(conf_prefix + conf_ignore + conf_database_list); - else - $('#rep').html(conf_prefix + conf_do + conf_database_list); - }); + $('#db_type').change(update_config); + $('#db_select').change(update_config); $('#master_status_href').click(function() { $('#replication_master_section').toggle();