Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshutosh Dhundhara <ashutoshdhundhara@yahoo.com>2014-07-31 19:22:39 +0400
committerAshutosh Dhundhara <ashutoshdhundhara@yahoo.com>2014-08-01 18:20:12 +0400
commit508f0a752b372539dd8dd2e045988a292c75e15d (patch)
tree607c979fba741099ca3cfd6c49a56fd49e7c31a1 /js/tbl_relation.js
parent549f0c3214a92674e1188c337b025f399fdffd84 (diff)
RFE#919: Multiple-column foreign key relation.
Signed-off-by: Ashutosh Dhundhara <ashutoshdhundhara@yahoo.com> Fix missing master column. Signed-off-by: Ashutosh Dhundhara <ashutoshdhundhara@yahoo.com> Fix failing test. Signed-off-by: Ashutosh Dhundhara <ashutoshdhundhara@yahoo.com> Fix coding styles. Signed-off-by: Ashutosh Dhundhara <ashutoshdhundhara@yahoo.com> Fix function doc. Signed-off-by: Ashutosh Dhundhara <ashutoshdhundhara@yahoo.com> Fix coding styles. Signed-off-by: Ashutosh Dhundhara <ashutoshdhundhara@yahoo.com>
Diffstat (limited to 'js/tbl_relation.js')
-rw-r--r--js/tbl_relation.js102
1 files changed, 80 insertions, 22 deletions
diff --git a/js/tbl_relation.js b/js/tbl_relation.js
index d6ceb1dbd5..67522ed6d0 100644
--- a/js/tbl_relation.js
+++ b/js/tbl_relation.js
@@ -39,8 +39,8 @@ function getDropdownValues($dropdown) {
var foreign = '';
// if the changed dropdown is for foreign key constraints
if ($dropdown.is('select[name^="destination_foreign"]')) {
- $tableDd = $dropdown.parent().find('select[name^="destination_foreign_table"]');
- $columnDd = $dropdown.parent().find('select[name^="destination_foreign_column"]');
+ $tableDd = $dropdown.parent().parent().parent().find('select[name^="destination_foreign_table"]');
+ $columnDd = $dropdown.parent().parent().parent().find('select[name^="destination_foreign_column"]');
foreign = '_foreign';
} else { // internal relations
$tableDd = $dropdown.parent().find('select[name^="destination_table"]');
@@ -57,7 +57,7 @@ function getDropdownValues($dropdown) {
return;
}
} else { // if a table selector
- foreignDb = $dropdown.parent()
+ foreignDb = $dropdown.parent().parent().parent()
.find('select[name^="destination' + foreign + '_db"]').val();
foreignTable = $dropdown.val();
// if no table is selected empty the column dropdown
@@ -107,29 +107,87 @@ function getDropdownValues($dropdown) {
* Unbind all event handlers before tearing down a page
*/
AJAX.registerTeardown('tbl_relation.js', function () {
- $('select[name^="destination_foreign"]').unbind('change');
- $('select[name^="destination_db"],' +
- ' select[name^="destination_table"],' +
- ' select[name^="destination_foreign_db"],' +
- ' select[name^="destination_foreign_table"]'
- ).unbind('change');
+ $('body').off('change',
+ 'select[name^="destination_db"], ' +
+ 'select[name^="destination_table"], ' +
+ 'select[name^="destination_foreign_db"], ' +
+ 'select[name^="destination_foreign_table"]'
+ );
+ $('body').off('click', 'a.add_foreign_key_field');
+ $('body').off('click', 'a.add_foreign_key');
});
AJAX.registerOnload('tbl_relation.js', function () {
- // initial display
- $('select[name^="destination_foreign_column"]').each(function (index, one_dropdown) {
- show_hide_clauses($(one_dropdown));
- });
- // change
- $('select[name^="destination_foreign"]').change(function () {
- show_hide_clauses($(this));
- });
- $('select[name^="destination_db"],' +
- ' select[name^="destination_table"],' +
- ' select[name^="destination_foreign_db"],' +
- ' select[name^="destination_foreign_table"]'
- ).change(function () {
+ /**
+ * Ajax event handler to fetch table/column dropdown values.
+ */
+ $('body').on('change',
+ 'select[name^="destination_db"], ' +
+ 'select[name^="destination_table"], ' +
+ 'select[name^="destination_foreign_db"], ' +
+ 'select[name^="destination_foreign_table"]',
+ function () {
getDropdownValues($(this));
+ }
+ );
+
+ /**
+ * Ajax event handler to add a column to a foreign key constraint.
+ */
+ $('body').on('click', 'a.add_foreign_key_field', function (event) {
+ event.preventDefault();
+ event.stopPropagation();
+
+ // Add field.
+ $(this)
+ .prev('span')
+ .clone(true, true)
+ .insertBefore($(this))
+ .find('select')
+ .val('');
+
+ // Add foreign field.
+ var $source_elem = $('select[name^="destination_foreign_column[' +
+ $(this).attr('data-index') + ']"]:last').parent();
+ $source_elem
+ .clone(true, true)
+ .insertAfter($source_elem)
+ .find('select')
+ .val('');
+ });
+
+ /**
+ * Ajax event handler to add a foreign key constraint.
+ */
+ $('body').on('click', 'a.add_foreign_key', function (event) {
+ event.preventDefault();
+ event.stopPropagation();
+
+ var $prev_row = $(this).closest('tr').prev('tr');
+ var odd_even = ($prev_row.attr('class') == 'odd') ? 'even' : 'odd';
+ var $new_row = $prev_row.clone(true, true).attr('class', odd_even);
+
+ // Update serial number.
+ var curr_index = $new_row
+ .find('a.add_foreign_key_field')
+ .attr('data-index');
+ var new_index = parseInt(curr_index) + 1;
+ $new_row.find('a.add_foreign_key_field').attr('data-index', new_index);
+
+ // Update form parameter names.
+ $new_row.find('select[name^="foreign_key_fields_name"]:not(:first), ' +
+ 'select[name^="destination_foreign_column"]:not(:first)'
+ ).each(function () {
+ $(this).parent().remove();
});
+ $new_row.find('input, select').each(function () {
+ $(this).attr('name',
+ $(this).attr('name').replace(/\d/, new_index)
+ );
+ });
+
+ // Finally add the row.
+ $new_row.insertAfter($prev_row);
+ });
});