Exclude node_modules from PHP code coverage
[phpmyadmin.git] / js / normalization.js
blob57f3451c0ec8e94f4eaf50a271faebf86cf1a994
1 /**
2  * @fileoverview   events handling from normalization page
3  * @name            normalization
4  *
5  * @requires    jQuery
6  */
8 // eslint-disable-next-line no-unused-vars
9 /* global centralColumnList:writable */ // js/functions.js
11 /**
12  * AJAX scripts for normalization
13  *
14  */
16 var normalizeto = '1nf';
17 var primaryKey;
18 var dataParsed = null;
20 function appendHtmlColumnsList () {
21     $.post(
22         'index.php?route=/normalization',
23         {
24             'ajax_request': true,
25             'db': CommonParams.get('db'),
26             'table': CommonParams.get('table'),
27             'server': CommonParams.get('server'),
28             'getColumns': true
29         },
30         function (data) {
31             if (data.success === true) {
32                 $('select[name=makeAtomic]').html(data.message);
33             }
34         }
35     );
38 function goTo3NFStep1 (newTables) {
39     var tables = newTables;
40     if (Object.keys(tables).length === 1) {
41         tables = [CommonParams.get('table')];
42     }
43     $.post(
44         'index.php?route=/normalization',
45         {
46             'ajax_request': true,
47             'db': CommonParams.get('db'),
48             'server': CommonParams.get('server'),
49             'tables': tables,
50             'step': '3.1'
51         }, function (data) {
52             $('#page_content').find('h3').html(Messages.str3NFNormalization);
53             $('#mainContent').find('legend').html(data.legendText);
54             $('#mainContent').find('h4').html(data.headText);
55             $('#mainContent').find('p').html(data.subText);
56             $('#mainContent').find('#extra').html(data.extra);
57             $('#extra').find('form').each(function () {
58                 var formId = $(this).attr('id');
59                 var colName = $(this).data('colname');
60                 $('#' + formId + ' input[value=\'' + colName + '\']').next().remove();
61                 $('#' + formId + ' input[value=\'' + colName + '\']').remove();
62             });
63             $('#mainContent').find('#newCols').html('');
64             $('.tblFooters').html('');
66             if (data.subText !== '') {
67                 $('<input>')
68                     .attr({ type: 'button', value: Messages.strDone })
69                     .on('click', function () {
70                         processDependencies('', true);
71                     })
72                     .appendTo('.tblFooters');
73             }
74         }
75     );
78 function goTo2NFStep1 () {
79     $.post(
80         'index.php?route=/normalization',
81         {
82             'ajax_request': true,
83             'db': CommonParams.get('db'),
84             'table': CommonParams.get('table'),
85             'server': CommonParams.get('server'),
86             'step': '2.1'
87         }, function (data) {
88             $('#page_content h3').html(Messages.str2NFNormalization);
89             $('#mainContent legend').html(data.legendText);
90             $('#mainContent h4').html(data.headText);
91             $('#mainContent p').html(data.subText);
92             $('#mainContent #extra').html(data.extra);
93             $('#mainContent #newCols').html('');
94             if (data.subText !== '') {
95                 $('<input>')
96                     .attr({ type: 'submit', value: Messages.strDone, })
97                     .on('click', function () {
98                         processDependencies(data.primary_key);
99                     })
100                     .appendTo('.tblFooters');
101             } else {
102                 if (normalizeto === '3nf') {
103                     $('#mainContent #newCols').html(Messages.strToNextStep);
104                     setTimeout(function () {
105                         goTo3NFStep1([CommonParams.get('table')]);
106                     }, 3000);
107                 }
108             }
109         });
112 function goToFinish1NF () {
113     if (normalizeto !== '1nf') {
114         goTo2NFStep1();
115         return true;
116     }
117     $('#mainContent legend').html(Messages.strEndStep);
118     $('#mainContent h4').html(
119         '<h3>' + Functions.sprintf(Messages.strFinishMsg, Functions.escapeHtml(CommonParams.get('table'))) + '</h3>'
120     );
121     $('#mainContent p').html('');
122     $('#mainContent #extra').html('');
123     $('#mainContent #newCols').html('');
124     $('.tblFooters').html('');
127 // eslint-disable-next-line no-unused-vars
128 function goToStep4 () {
129     $.post(
130         'index.php?route=/normalization',
131         {
132             'ajax_request': true,
133             'db': CommonParams.get('db'),
134             'table': CommonParams.get('table'),
135             'server': CommonParams.get('server'),
136             'step4': true
137         }, function (data) {
138             $('#mainContent legend').html(data.legendText);
139             $('#mainContent h4').html(data.headText);
140             $('#mainContent p').html(data.subText);
141             $('#mainContent #extra').html(data.extra);
142             $('#mainContent #newCols').html('');
143             $('.tblFooters').html('');
144             for (var pk in primaryKey) {
145                 $('#extra input[value=\'' + Functions.escapeJsString(primaryKey[pk]) + '\']').attr('disabled','disabled');
146             }
147         }
148     );
151 function goToStep3 () {
152     $.post(
153         'index.php?route=/normalization',
154         {
155             'ajax_request': true,
156             'db': CommonParams.get('db'),
157             'table': CommonParams.get('table'),
158             'server': CommonParams.get('server'),
159             'step3': true
160         }, function (data) {
161             $('#mainContent legend').html(data.legendText);
162             $('#mainContent h4').html(data.headText);
163             $('#mainContent p').html(data.subText);
164             $('#mainContent #extra').html(data.extra);
165             $('#mainContent #newCols').html('');
166             $('.tblFooters').html('');
167             primaryKey = JSON.parse(data.primary_key);
168             for (var pk in primaryKey) {
169                 $('#extra input[value=\'' + Functions.escapeJsString(primaryKey[pk]) + '\']').attr('disabled','disabled');
170             }
171         }
172     );
175 function goToStep2 (extra) {
176     $.post(
177         'index.php?route=/normalization',
178         {
179             'ajax_request': true,
180             'db': CommonParams.get('db'),
181             'table': CommonParams.get('table'),
182             'server': CommonParams.get('server'),
183             'step2': true
184         }, function (data) {
185             $('#mainContent legend').html(data.legendText);
186             $('#mainContent h4').html(data.headText);
187             $('#mainContent p').html(data.subText);
188             $('#mainContent #extra,#mainContent #newCols').html('');
189             $('.tblFooters').html('');
190             if (data.hasPrimaryKey === '1') {
191                 if (extra === 'goToStep3') {
192                     $('#mainContent h4').html(Messages.strPrimaryKeyAdded);
193                     $('#mainContent p').html(Messages.strToNextStep);
194                 }
195                 if (extra === 'goToFinish1NF') {
196                     goToFinish1NF();
197                 } else {
198                     setTimeout(function () {
199                         goToStep3();
200                     }, 3000);
201                 }
202             } else {
203                 // form to select columns to make primary
204                 $('#mainContent #extra').html(data.extra);
205             }
206         }
207     );
210 function goTo2NFFinish (pd) {
211     var tables = {};
212     for (var dependson in pd) {
213         tables[dependson] = $('#extra input[name="' + dependson + '"]').val();
214     }
215     var datastring = {
216         'ajax_request': true,
217         'db': CommonParams.get('db'),
218         'table': CommonParams.get('table'),
219         'server': CommonParams.get('server'),
220         'pd': JSON.stringify(pd),
221         'newTablesName':JSON.stringify(tables),
222         'createNewTables2NF':1 };
223     $.ajax({
224         type: 'POST',
225         url: 'index.php?route=/normalization',
226         data: datastring,
227         async:false,
228         success: function (data) {
229             if (data.success === true) {
230                 if (data.queryError === false) {
231                     if (normalizeto === '3nf') {
232                         $('#pma_navigation_reload').trigger('click');
233                         goTo3NFStep1(tables);
234                         return true;
235                     }
236                     $('#mainContent legend').html(data.legendText);
237                     $('#mainContent h4').html(data.headText);
238                     $('#mainContent p').html('');
239                     $('#mainContent #extra').html('');
240                     $('.tblFooters').html('');
241                 } else {
242                     Functions.ajaxShowMessage(data.extra, false);
243                 }
244                 $('#pma_navigation_reload').trigger('click');
245             } else {
246                 Functions.ajaxShowMessage(data.error, false);
247             }
248         }
249     });
252 function goTo3NFFinish (newTables) {
253     for (var table in newTables) {
254         for (var newtbl in newTables[table]) {
255             var updatedname = $('#extra input[name="' + newtbl + '"]').val();
256             newTables[table][updatedname] = newTables[table][newtbl];
257             if (updatedname !== newtbl) {
258                 delete newTables[table][newtbl];
259             }
260         }
261     }
262     var datastring = {
263         'ajax_request': true,
264         'db': CommonParams.get('db'),
265         'server': CommonParams.get('server'),
266         'newTables':JSON.stringify(newTables),
267         'createNewTables3NF':1 };
268     $.ajax({
269         type: 'POST',
270         url: 'index.php?route=/normalization',
271         data: datastring,
272         async:false,
273         success: function (data) {
274             if (data.success === true) {
275                 if (data.queryError === false) {
276                     $('#mainContent legend').html(data.legendText);
277                     $('#mainContent h4').html(data.headText);
278                     $('#mainContent p').html('');
279                     $('#mainContent #extra').html('');
280                     $('.tblFooters').html('');
281                 } else {
282                     Functions.ajaxShowMessage(data.extra, false);
283                 }
284                 $('#pma_navigation_reload').trigger('click');
285             } else {
286                 Functions.ajaxShowMessage(data.error, false);
287             }
288         }
289     });
292 var backup = '';
294 function goTo2NFStep2 (pd, primaryKey) {
295     $('#newCols').html('');
296     $('#mainContent legend').html(Messages.strStep + ' 2.2 ' + Messages.strConfirmPd);
297     $('#mainContent h4').html(Messages.strSelectedPd);
298     $('#mainContent p').html(Messages.strPdHintNote);
299     var extra = '<div class="dependencies_box">';
300     var pdFound = false;
301     for (var dependson in pd) {
302         if (dependson !== primaryKey) {
303             pdFound = true;
304             extra += '<p class="displayblock desc">' + Functions.escapeHtml(dependson) + ' -> ' + Functions.escapeHtml(pd[dependson].toString()) + '</p>';
305         }
306     }
307     if (!pdFound) {
308         extra += '<p class="displayblock desc">' + Messages.strNoPdSelected + '</p>';
309         extra += '</div>';
310     } else {
311         extra += '</div>';
312         var datastring = {
313             'ajax_request': true,
314             'db': CommonParams.get('db'),
315             'table': CommonParams.get('table'),
316             'server': CommonParams.get('server'),
317             'pd': JSON.stringify(pd),
318             'getNewTables2NF':1 };
319         $.ajax({
320             type: 'POST',
321             url: 'index.php?route=/normalization',
322             data: datastring,
323             async:false,
324             success: function (data) {
325                 if (data.success === true) {
326                     extra += data.message;
327                 } else {
328                     Functions.ajaxShowMessage(data.error, false);
329                 }
330             }
331         });
332     }
333     $('#mainContent #extra').html(extra);
334     $('.tblFooters').html('<input type="button" class="btn btn-primary" value="' + Messages.strBack + '" id="backEditPd"><input type="button" class="btn btn-primary" id="goTo2NFFinish" value="' + Messages.strGo + '">');
335     $('#goTo2NFFinish').on('click', function () {
336         goTo2NFFinish(pd);
337     });
340 function goTo3NFStep2 (pd, tablesTds) {
341     $('#newCols').html('');
342     $('#mainContent legend').html(Messages.strStep + ' 3.2 ' + Messages.strConfirmTd);
343     $('#mainContent h4').html(Messages.strSelectedTd);
344     $('#mainContent p').html(Messages.strPdHintNote);
345     var extra = '<div class="dependencies_box">';
346     var pdFound = false;
347     for (var table in tablesTds) {
348         for (var i in tablesTds[table]) {
349             var dependson = tablesTds[table][i];
350             if (dependson !== '' && dependson !== table) {
351                 pdFound = true;
352                 extra += '<p class="displayblock desc">' + Functions.escapeHtml(dependson) + ' -> ' + Functions.escapeHtml(pd[dependson].toString()) + '</p>';
353             }
354         }
355     }
356     if (!pdFound) {
357         extra += '<p class="displayblock desc">' + Messages.strNoTdSelected + '</p>';
358         extra += '</div>';
359     } else {
360         extra += '</div>';
361         var datastring = {
362             'ajax_request': true,
363             'db': CommonParams.get('db'),
364             'tables': JSON.stringify(tablesTds),
365             'server': CommonParams.get('server'),
366             'pd': JSON.stringify(pd),
367             'getNewTables3NF':1 };
368         $.ajax({
369             type: 'POST',
370             url: 'index.php?route=/normalization',
371             data: datastring,
372             async:false,
373             success: function (data) {
374                 dataParsed = data;
375                 if (data.success === true) {
376                     extra += dataParsed.html;
377                 } else {
378                     Functions.ajaxShowMessage(data.error, false);
379                 }
380             }
381         });
382     }
383     $('#mainContent #extra').html(extra);
384     $('.tblFooters').html('<input type="button" class="btn btn-primary" value="' + Messages.strBack + '" id="backEditPd"><input type="button" class="btn btn-primary" id="goTo3NFFinish" value="' + Messages.strGo + '">');
385     $('#goTo3NFFinish').on('click', function () {
386         if (!pdFound) {
387             goTo3NFFinish([]);
388         } else {
389             goTo3NFFinish(dataParsed.newTables);
390         }
391     });
393 function processDependencies (primaryKey, isTransitive) {
394     var pk = primaryKey;
395     var pd = {};
396     var tablesTds = {};
397     var dependsOn;
398     pd[pk] = [];
399     $('#extra form').each(function () {
400         var tblname;
401         if (isTransitive === true) {
402             tblname = $(this).data('tablename');
403             pk = tblname;
404             if (!(tblname in tablesTds)) {
405                 tablesTds[tblname] = [];
406             }
407             tablesTds[tblname].push(pk);
408         }
409         var formId = $(this).attr('id');
410         $('#' + formId + ' input[type=checkbox]:not(:checked)').prop('checked', false);
411         dependsOn = '';
412         $('#' + formId + ' input[type=checkbox]:checked').each(function () {
413             dependsOn += $(this).val() + ', ';
414             $(this).attr('checked','checked');
415         });
416         if (dependsOn === '') {
417             dependsOn = pk;
418         } else {
419             dependsOn = dependsOn.slice(0, -2);
420         }
421         if (! (dependsOn in pd)) {
422             pd[dependsOn] = [];
423         }
424         pd[dependsOn].push($(this).data('colname'));
425         if (isTransitive === true) {
426             if (!(tblname in tablesTds)) {
427                 tablesTds[tblname] = [];
428             }
429             if ($.inArray(dependsOn, tablesTds[tblname]) === -1) {
430                 tablesTds[tblname].push(dependsOn);
431             }
432         }
433     });
434     backup = $('#mainContent').html();
435     if (isTransitive === true) {
436         goTo3NFStep2(pd, tablesTds);
437     } else {
438         goTo2NFStep2(pd, pk);
439     }
440     return false;
443 function moveRepeatingGroup (repeatingCols) {
444     var newTable = $('input[name=repeatGroupTable]').val();
445     var newColumn = $('input[name=repeatGroupColumn]').val();
446     if (!newTable) {
447         $('input[name=repeatGroupTable]').trigger('focus');
448         return false;
449     }
450     if (!newColumn) {
451         $('input[name=repeatGroupColumn]').trigger('focus');
452         return false;
453     }
454     var datastring = {
455         'ajax_request': true,
456         'db': CommonParams.get('db'),
457         'table': CommonParams.get('table'),
458         'server': CommonParams.get('server'),
459         'repeatingColumns': repeatingCols,
460         'newTable':newTable,
461         'newColumn':newColumn,
462         'primary_columns':primaryKey.toString()
463     };
464     $.ajax({
465         type: 'POST',
466         url: 'index.php?route=/normalization',
467         data: datastring,
468         async:false,
469         success: function (data) {
470             if (data.success === true) {
471                 if (data.queryError === false) {
472                     goToStep3();
473                 }
474                 Functions.ajaxShowMessage(data.message, false);
475                 $('#pma_navigation_reload').trigger('click');
476             } else {
477                 Functions.ajaxShowMessage(data.error, false);
478             }
479         }
480     });
482 AJAX.registerTeardown('normalization.js', function () {
483     $('#extra').off('click', '#selectNonAtomicCol');
484     $('#splitGo').off('click');
485     $('.tblFooters').off('click', '#saveSplit');
486     $('#extra').off('click', '#addNewPrimary');
487     $('.tblFooters').off('click', '#saveNewPrimary');
488     $('#extra').off('click', '#removeRedundant');
489     $('#mainContent p').off('click', '#createPrimaryKey');
490     $('#mainContent').off('click', '#backEditPd');
491     $('#mainContent').off('click', '#showPossiblePd');
492     $('#mainContent').off('click', '.pickPd');
495 AJAX.registerOnload('normalization.js', function () {
496     var selectedCol;
497     normalizeto = $('#mainContent').data('normalizeto');
498     $('#extra').on('click', '#selectNonAtomicCol', function () {
499         if ($(this).val() === 'no_such_col') {
500             goToStep2();
501         } else {
502             selectedCol = $(this).val();
503         }
504     });
506     $('#splitGo').on('click', function () {
507         if (!selectedCol || selectedCol === '') {
508             return false;
509         }
510         var numField = $('#numField').val();
511         $.post(
512             'index.php?route=/normalization',
513             {
514                 'ajax_request': true,
515                 'db': CommonParams.get('db'),
516                 'table': CommonParams.get('table'),
517                 'server': CommonParams.get('server'),
518                 'splitColumn': true,
519                 'numFields': numField
520             },
521             function (data) {
522                 if (data.success === true) {
523                     $('#newCols').html(data.message);
524                     $('.default_value').hide();
525                     $('.enum_notice').hide();
527                     $('<input>')
528                         .attr({ type: 'submit', id: 'saveSplit', value: Messages.strSave })
529                         .appendTo('.tblFooters');
531                     $('<input>')
532                         .attr({ type: 'submit', id: 'cancelSplit', value: Messages.strCancel })
533                         .on('click', function () {
534                             $('#newCols').html('');
535                             $(this).parent().html('');
536                         })
537                         .appendTo('.tblFooters');
538                 }
539             }
540         );
541         return false;
542     });
543     $('.tblFooters').on('click','#saveSplit', function () {
544         centralColumnList = [];
545         if ($('#newCols #field_0_1').val() === '') {
546             $('#newCols #field_0_1').trigger('focus');
547             return false;
548         }
549         var argsep = CommonParams.get('arg_separator');
550         var datastring = $('#newCols :input').serialize();
551         datastring += argsep + 'ajax_request=1' + argsep + 'do_save_data=1' + argsep + 'field_where=last';
552         $.post('index.php?route=/table/add-field', datastring, function (data) {
553             if (data.success) {
554                 $.post(
555                     'index.php?route=/sql',
556                     {
557                         'ajax_request': true,
558                         'db': CommonParams.get('db'),
559                         'table': CommonParams.get('table'),
560                         'server': CommonParams.get('server'),
561                         'dropped_column': selectedCol,
562                         'purge' : 1,
563                         'sql_query': 'ALTER TABLE `' + CommonParams.get('table') + '` DROP `' + selectedCol + '`;',
564                         'is_js_confirmed': 1
565                     },
566                     function (data) {
567                         if (data.success === true) {
568                             appendHtmlColumnsList();
569                             $('#newCols').html('');
570                             $('.tblFooters').html('');
571                         } else {
572                             Functions.ajaxShowMessage(data.error, false);
573                         }
574                         selectedCol = '';
575                     }
576                 );
577             } else {
578                 Functions.ajaxShowMessage(data.error, false);
579             }
580         });
581     });
583     $('#extra').on('click', '#addNewPrimary', function () {
584         $.post(
585             'index.php?route=/normalization',
586             {
587                 'ajax_request': true,
588                 'db': CommonParams.get('db'),
589                 'table': CommonParams.get('table'),
590                 'server': CommonParams.get('server'),
591                 'addNewPrimary': true
592             },
593             function (data) {
594                 if (data.success === true) {
595                     $('#newCols').html(data.message);
596                     $('.default_value').hide();
597                     $('.enum_notice').hide();
599                     $('<input>')
600                         .attr({ type: 'submit', id: 'saveNewPrimary', value: Messages.strSave })
601                         .appendTo('.tblFooters');
602                     $('<input>')
603                         .attr({ type: 'submit', id: 'cancelSplit', value: Messages.strCancel })
604                         .on('click', function () {
605                             $('#newCols').html('');
606                             $(this).parent().html('');
607                         })
608                         .appendTo('.tblFooters');
609                 } else {
610                     Functions.ajaxShowMessage(data.error, false);
611                 }
612             }
613         );
614         return false;
615     });
616     $('.tblFooters').on('click', '#saveNewPrimary', function () {
617         var datastring = $('#newCols :input').serialize();
618         var argsep = CommonParams.get('arg_separator');
619         datastring += argsep + 'field_key[0]=primary_0' + argsep + 'ajax_request=1' + argsep + 'do_save_data=1' + argsep + 'field_where=last';
620         $.post('index.php?route=/table/add-field', datastring, function (data) {
621             if (data.success === true) {
622                 $('#mainContent h4').html(Messages.strPrimaryKeyAdded);
623                 $('#mainContent p').html(Messages.strToNextStep);
624                 $('#mainContent #extra').html('');
625                 $('#mainContent #newCols').html('');
626                 $('.tblFooters').html('');
627                 setTimeout(function () {
628                     goToStep3();
629                 }, 2000);
630             } else {
631                 Functions.ajaxShowMessage(data.error, false);
632             }
633         });
634     });
635     $('#extra').on('click', '#removeRedundant', function () {
636         var dropQuery = 'ALTER TABLE `' + CommonParams.get('table') + '` ';
637         $('#extra input[type=checkbox]:checked').each(function () {
638             dropQuery += 'DROP `' + $(this).val() + '`, ';
639         });
640         dropQuery = dropQuery.slice(0, -2);
641         $.post(
642             'index.php?route=/sql',
643             {
644                 'ajax_request': true,
645                 'db': CommonParams.get('db'),
646                 'table': CommonParams.get('table'),
647                 'server': CommonParams.get('server'),
648                 'sql_query': dropQuery,
649                 'is_js_confirmed': 1
650             },
651             function (data) {
652                 if (data.success === true) {
653                     goToStep2('goToFinish1NF');
654                 } else {
655                     Functions.ajaxShowMessage(data.error, false);
656                 }
657             }
658         );
659     });
660     $('#extra').on('click', '#moveRepeatingGroup', function () {
661         var repeatingCols = '';
662         $('#extra input[type=checkbox]:checked').each(function () {
663             repeatingCols += $(this).val() + ', ';
664         });
666         if (repeatingCols !== '') {
667             var newColName = $('#extra input[type=checkbox]:checked').first().val();
668             repeatingCols = repeatingCols.slice(0, -2);
669             var confirmStr = Functions.sprintf(Messages.strMoveRepeatingGroup, Functions.escapeHtml(repeatingCols), Functions.escapeHtml(CommonParams.get('table')));
670             confirmStr += '<input type="text" name="repeatGroupTable" placeholder="' + Messages.strNewTablePlaceholder + '">' +
671                 '( ' + Functions.escapeHtml(primaryKey.toString()) + ', <input type="text" name="repeatGroupColumn" placeholder="' + Messages.strNewColumnPlaceholder + '" value="' + Functions.escapeHtml(newColName) + '">)' +
672                 '</ol>';
673             $('#newCols').html(confirmStr);
675             $('<input>')
676                 .attr({ type: 'submit', value: Messages.strCancel })
677                 .on('click', function () {
678                     $('#newCols').html('');
679                     $('#extra input[type=checkbox]').prop('checked', false);
680                 })
681                 .appendTo('.tblFooters');
682             $('<input>')
683                 .attr({ type: 'submit', value: Messages.strGo })
684                 .on('click', function () {
685                     moveRepeatingGroup(repeatingCols);
686                 })
687                 .appendTo('.tblFooters');
688         }
689     });
690     $('#mainContent p').on('click', '#createPrimaryKey', function (event) {
691         event.preventDefault();
692         var url = {
693             'create_index': 1,
694             'server':  CommonParams.get('server'),
695             'db': CommonParams.get('db'),
696             'table': CommonParams.get('table'),
697             'added_fields': 1,
698             'add_fields':1,
699             'index': { 'Key_name':'PRIMARY' },
700             'ajax_request': true
701         };
702         var title = Messages.strAddPrimaryKey;
703         Functions.indexEditorDialog(url, title, function () {
704             // on success
705             $('.sqlqueryresults').remove();
706             $('.result_query').remove();
707             $('.tblFooters').html('');
708             goToStep2('goToStep3');
709         });
710         return false;
711     });
712     $('#mainContent').on('click', '#backEditPd', function () {
713         $('#mainContent').html(backup);
714     });
715     $('#mainContent').on('click', '#showPossiblePd', function () {
716         if ($(this).hasClass('hideList')) {
717             $(this).html('+ ' + Messages.strShowPossiblePd);
718             $(this).removeClass('hideList');
719             $('#newCols').slideToggle('slow');
720             return false;
721         }
722         if ($('#newCols').html() !== '') {
723             $('#showPossiblePd').html('- ' + Messages.strHidePd);
724             $('#showPossiblePd').addClass('hideList');
725             $('#newCols').slideToggle('slow');
726             return false;
727         }
728         $('#newCols').insertAfter('#mainContent h4');
729         $('#newCols').html('<div class="text-center">' + Messages.strLoading + '<br>' + Messages.strWaitForPd + '</div>');
730         $.post(
731             'index.php?route=/normalization',
732             {
733                 'ajax_request': true,
734                 'db': CommonParams.get('db'),
735                 'table': CommonParams.get('table'),
736                 'server': CommonParams.get('server'),
737                 'findPdl': true
738             }, function (data) {
739                 $('#showPossiblePd').html('- ' + Messages.strHidePd);
740                 $('#showPossiblePd').addClass('hideList');
741                 $('#newCols').html(data.message);
742             });
743     });
744     $('#mainContent').on('click', '.pickPd', function () {
745         var strColsLeft = $(this).next('.determinants').html();
746         var colsLeft = strColsLeft.split(',');
747         var strColsRight = $(this).next().next().html();
748         var colsRight = strColsRight.split(',');
749         for (var i in colsRight) {
750             $('form[data-colname="' + colsRight[i].trim() + '"] input[type="checkbox"]').prop('checked', false);
751             for (var j in colsLeft) {
752                 $('form[data-colname="' + colsRight[i].trim() + '"] input[value="' + colsLeft[j].trim() + '"]').prop('checked', true);
753             }
754         }
755     });