Improve storing columns on designer and add a translation
[phpmyadmin.git] / js / tbl_change.js
blob18742fd1e3aadb54625270038eb0f5b89a91c8f0
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3  * @fileoverview    function used in table data manipulation pages
4  *
5  * @requires    jQuery
6  * @requires    jQueryUI
7  * @requires    js/functions.js
8  *
9  */
11 /**
12  * Modify form controls when the "NULL" checkbox is checked
13  *
14  * @param theType     string   the MySQL field type
15  * @param urlField    string   the urlencoded field name - OBSOLETE
16  * @param md5Field    string   the md5 hashed field name
17  * @param multi_edit  string   the multi_edit row sequence number
18  *
19  * @return boolean  always true
20  */
21 function nullify (theType, urlField, md5Field, multi_edit) {
22     var rowForm = document.forms.insertForm;
24     if (typeof(rowForm.elements['funcs' + multi_edit + '[' + md5Field + ']']) !== 'undefined') {
25         rowForm.elements['funcs' + multi_edit + '[' + md5Field + ']'].selectedIndex = -1;
26     }
28     // "ENUM" field with more than 20 characters
29     if (Number(theType) === 1) {
30         rowForm.elements['fields' + multi_edit + '[' + md5Field +  ']'][1].selectedIndex = -1;
31     // Other "ENUM" field
32     } else if (Number(theType) === 2) {
33         var elts     = rowForm.elements['fields' + multi_edit + '[' + md5Field + ']'];
34         // when there is just one option in ENUM:
35         if (elts.checked) {
36             elts.checked = false;
37         } else {
38             var elts_cnt = elts.length;
39             for (var i = 0; i < elts_cnt; i++) {
40                 elts[i].checked = false;
41             } // end for
42         } // end if
43     // "SET" field
44     } else if (Number(theType) === 3) {
45         rowForm.elements['fields' + multi_edit + '[' + md5Field +  '][]'].selectedIndex = -1;
46     // Foreign key field (drop-down)
47     } else if (Number(theType) === 4) {
48         rowForm.elements['fields' + multi_edit + '[' + md5Field +  ']'].selectedIndex = -1;
49     // foreign key field (with browsing icon for foreign values)
50     } else if (Number(theType) === 6) {
51         rowForm.elements['fields' + multi_edit + '[' + md5Field + ']'].value = '';
52     // Other field types
53     } else /* if (theType === 5)*/ {
54         rowForm.elements['fields' + multi_edit + '[' + md5Field + ']'].value = '';
55     } // end if... else if... else
57     return true;
58 } // end of the 'nullify()' function
61 /**
62  * javascript DateTime format validation.
63  * its used to prevent adding default (0000-00-00 00:00:00) to database when user enter wrong values
64  * Start of validation part
65  */
66 // function checks the number of days in febuary
67 function daysInFebruary (year) {
68     return (((year % 4 === 0) && (((year % 100 !== 0)) || (year % 400 === 0))) ? 29 : 28);
70 // function to convert single digit to double digit
71 function fractionReplace (num) {
72     num = parseInt(num, 10);
73     return num >= 1 && num <= 9 ? '0' + num : '00';
76 /* function to check the validity of date
77 * The following patterns are accepted in this validation (accepted in mysql as well)
78 * 1) 2001-12-23
79 * 2) 2001-1-2
80 * 3) 02-12-23
81 * 4) And instead of using '-' the following punctuations can be used (+,.,*,^,@,/) All these are accepted by mysql as well. Therefore no issues
83 function isDate (val, tmstmp) {
84     val = val.replace(/[.|*|^|+|//|@]/g, '-');
85     var arrayVal = val.split('-');
86     for (var a = 0; a < arrayVal.length; a++) {
87         if (arrayVal[a].length === 1) {
88             arrayVal[a] = fractionReplace(arrayVal[a]);
89         }
90     }
91     val = arrayVal.join('-');
92     var pos = 2;
93     var dtexp = new RegExp(/^([0-9]{4})-(((01|03|05|07|08|10|12)-((0[0-9])|([1-2][0-9])|(3[0-1])))|((02|04|06|09|11)-((0[0-9])|([1-2][0-9])|30))|((00)-(00)))$/);
94     if (val.length === 8) {
95         pos = 0;
96     }
97     if (dtexp.test(val)) {
98         var month = parseInt(val.substring(pos + 3, pos + 5), 10);
99         var day = parseInt(val.substring(pos + 6, pos + 8), 10);
100         var year = parseInt(val.substring(0, pos + 2), 10);
101         if (month === 2 && day > daysInFebruary(year)) {
102             return false;
103         }
104         if (val.substring(0, pos + 2).length === 2) {
105             year = parseInt('20' + val.substring(0, pos + 2), 10);
106         }
107         if (tmstmp === true) {
108             if (year < 1978) {
109                 return false;
110             }
111             if (year > 2038 || (year > 2037 && day > 19 && month >= 1) || (year > 2037 && month > 1)) {
112                 return false;
113             }
114         }
115     } else {
116         return false;
117     }
118     return true;
121 /* function to check the validity of time
122 * The following patterns are accepted in this validation (accepted in mysql as well)
123 * 1) 2:3:4
124 * 2) 2:23:43
125 * 3) 2:23:43.123456
127 function isTime (val) {
128     var arrayVal = val.split(':');
129     for (var a = 0, l = arrayVal.length; a < l; a++) {
130         if (arrayVal[a].length === 1) {
131             arrayVal[a] = fractionReplace(arrayVal[a]);
132         }
133     }
134     val = arrayVal.join(':');
135     var tmexp = new RegExp(/^(-)?(([0-7]?[0-9][0-9])|(8[0-2][0-9])|(83[0-8])):((0[0-9])|([1-5][0-9])):((0[0-9])|([1-5][0-9]))(\.[0-9]{1,6}){0,1}$/);
136     return tmexp.test(val);
140  * To check whether insert section is ignored or not
141  */
142 function checkForCheckbox (multi_edit) {
143     if ($('#insert_ignore_' + multi_edit).length) {
144         return $('#insert_ignore_' + multi_edit).is(':unchecked');
145     }
146     return true;
149 function verificationsAfterFieldChange (urlField, multi_edit, theType) {
150     var evt = window.event || arguments.callee.caller.arguments[0];
151     var target = evt.target || evt.srcElement;
152     var $this_input = $(':input[name^=\'fields[multi_edit][' + multi_edit + '][' +
153         urlField + ']\']');
154     // the function drop-down that corresponds to this input field
155     var $this_function = $('select[name=\'funcs[multi_edit][' + multi_edit + '][' +
156         urlField + ']\']');
157     var function_selected = false;
158     if (typeof $this_function.val() !== 'undefined' &&
159         $this_function.val() !== null &&
160         $this_function.val().length > 0
161     ) {
162         function_selected = true;
163     }
165     // To generate the textbox that can take the salt
166     var new_salt_box = '<br><input type=text name=salt[multi_edit][' + multi_edit + '][' + urlField + ']' +
167         ' id=salt_' + target.id + ' placeholder=\'' + PMA_messages.strEncryptionKey + '\'>';
169     // If encrypting or decrypting functions that take salt as input is selected append the new textbox for salt
170     if (target.value === 'AES_ENCRYPT' ||
171             target.value === 'AES_DECRYPT' ||
172             target.value === 'DES_ENCRYPT' ||
173             target.value === 'DES_DECRYPT' ||
174             target.value === 'ENCRYPT') {
175         if (!($('#salt_' + target.id).length)) {
176             $this_input.after(new_salt_box);
177         }
178     } else {
179         // Remove the textbox for salt
180         $('#salt_' + target.id).prev('br').remove();
181         $('#salt_' + target.id).remove();
182     }
184     if (target.value === 'AES_DECRYPT'
185             || target.value === 'AES_ENCRYPT'
186             || target.value === 'MD5') {
187         $('#' + target.id).rules('add', {
188             validationFunctionForFuns: {
189                 param: $this_input,
190                 depends: function () {
191                     return checkForCheckbox(multi_edit);
192                 }
193             }
194         });
195     }
197     // Unchecks the corresponding "NULL" control
198     $('input[name=\'fields_null[multi_edit][' + multi_edit + '][' + urlField + ']\']').prop('checked', false);
200     // Unchecks the Ignore checkbox for the current row
201     $('input[name=\'insert_ignore_' + multi_edit + '\']').prop('checked', false);
203     var charExceptionHandling;
204     if (theType.substring(0,4) === 'char') {
205         charExceptionHandling = theType.substring(5,6);
206     } else if (theType.substring(0,7) === 'varchar') {
207         charExceptionHandling = theType.substring(8,9);
208     }
209     if (function_selected) {
210         $this_input.removeAttr('min');
211         $this_input.removeAttr('max');
212         // @todo: put back attributes if corresponding function is deselected
213     }
215     if ($this_input.data('rulesadded') === null && ! function_selected) {
216         // call validate before adding rules
217         $($this_input[0].form).validate();
218         // validate for date time
219         if (theType === 'datetime' || theType === 'time' || theType === 'date' || theType === 'timestamp') {
220             $this_input.rules('add', {
221                 validationFunctionForDateTime: {
222                     param: theType,
223                     depends: function () {
224                         return checkForCheckbox(multi_edit);
225                     }
226                 }
227             });
228         }
229         // validation for integer type
230         if ($this_input.data('type') === 'INT') {
231             var mini = parseInt($this_input.attr('min'));
232             var maxi = parseInt($this_input.attr('max'));
233             $this_input.rules('add', {
234                 number: {
235                     param : true,
236                     depends: function () {
237                         return checkForCheckbox(multi_edit);
238                     }
239                 },
240                 min: {
241                     param: mini,
242                     depends: function () {
243                         if (isNaN($this_input.val())) {
244                             return false;
245                         } else {
246                             return checkForCheckbox(multi_edit);
247                         }
248                     }
249                 },
250                 max: {
251                     param: maxi,
252                     depends: function () {
253                         if (isNaN($this_input.val())) {
254                             return false;
255                         } else {
256                             return checkForCheckbox(multi_edit);
257                         }
258                     }
259                 }
260             });
261             // validation for CHAR types
262         } else if ($this_input.data('type') === 'CHAR') {
263             var maxlen = $this_input.data('maxlength');
264             if (typeof maxlen !== 'undefined') {
265                 if (maxlen <= 4) {
266                     maxlen = charExceptionHandling;
267                 }
268                 $this_input.rules('add', {
269                     maxlength: {
270                         param: maxlen,
271                         depends: function () {
272                             return checkForCheckbox(multi_edit);
273                         }
274                     }
275                 });
276             }
277             // validate binary & blob types
278         } else if ($this_input.data('type') === 'HEX') {
279             $this_input.rules('add', {
280                 validationFunctionForHex: {
281                     param: true,
282                     depends: function () {
283                         return checkForCheckbox(multi_edit);
284                     }
285                 }
286             });
287         }
288         $this_input.data('rulesadded', true);
289     } else if ($this_input.data('rulesadded') === true && function_selected) {
290         // remove any rules added
291         $this_input.rules('remove');
292         // remove any error messages
293         $this_input
294             .removeClass('error')
295             .removeAttr('aria-invalid')
296             .siblings('.error')
297             .remove();
298         $this_input.data('rulesadded', null);
299     }
301 /* End of fields validation*/
304  * Unbind all event handlers before tearing down a page
305  */
306 AJAX.registerTeardown('tbl_change.js', function () {
307     $(document).off('click', 'span.open_gis_editor');
308     $(document).off('click', 'input[name^=\'insert_ignore_\']');
309     $(document).off('click', 'input[name=\'gis_data[save]\']');
310     $(document).off('click', 'input.checkbox_null');
311     $('select[name="submit_type"]').off('change');
312     $(document).off('change', '#insert_rows');
316  * Ajax handlers for Change Table page
318  * Actions Ajaxified here:
319  * Submit Data to be inserted into the table.
320  * Restart insertion with 'N' rows.
321  */
322 AJAX.registerOnload('tbl_change.js', function () {
323     if ($('#insertForm').length) {
324         // validate the comment form when it is submitted
325         $('#insertForm').validate();
326         jQuery.validator.addMethod('validationFunctionForHex', function (value, element) {
327             return value.match(/^[a-f0-9]*$/i) !== null;
328         });
330         jQuery.validator.addMethod('validationFunctionForFuns', function (value, element, options) {
331             if (value.substring(0, 3) === 'AES' && options.data('type') !== 'HEX') {
332                 return false;
333             }
335             return !(value.substring(0, 3) === 'MD5' &&
336                 typeof options.data('maxlength') !== 'undefined' &&
337                 options.data('maxlength') < 32);
338         });
340         jQuery.validator.addMethod('validationFunctionForDateTime', function (value, element, options) {
341             var dt_value = value;
342             var theType = options;
343             if (theType === 'date') {
344                 return isDate(dt_value);
345             } else if (theType === 'time') {
346                 return isTime(dt_value);
347             } else if (theType === 'datetime' || theType === 'timestamp') {
348                 var tmstmp = false;
349                 dt_value = dt_value.trim();
350                 if (dt_value === 'CURRENT_TIMESTAMP' || dt_value === 'current_timestamp()') {
351                     return true;
352                 }
353                 if (theType === 'timestamp') {
354                     tmstmp = true;
355                 }
356                 if (dt_value === '0000-00-00 00:00:00') {
357                     return true;
358                 }
359                 var dv = dt_value.indexOf(' ');
360                 if (dv === -1) { // Only the date component, which is valid
361                     return isDate(dt_value, tmstmp);
362                 }
364                 return isDate(dt_value.substring(0, dv), tmstmp) &&
365                     isTime(dt_value.substring(dv + 1));
366             }
367         });
368         /*
369          * message extending script must be run
370          * after initiation of functions
371          */
372         extendingValidatorMessages();
373     }
375     $.datepicker.initialized = false;
377     $(document).on('click', 'span.open_gis_editor', function (event) {
378         event.preventDefault();
380         var $span = $(this);
381         // Current value
382         var value = $span.parent('td').children('input[type=\'text\']').val();
383         // Field name
384         var field = $span.parents('tr').children('td:first').find('input[type=\'hidden\']').val();
385         // Column type
386         var type = $span.parents('tr').find('span.column_type').text();
387         // Names of input field and null checkbox
388         var input_name = $span.parent('td').children('input[type=\'text\']').attr('name');
390         openGISEditor();
391         if (!gisEditorLoaded) {
392             loadJSAndGISEditor(value, field, type, input_name);
393         } else {
394             loadGISEditor(value, field, type, input_name);
395         }
396     });
398     /**
399      * Forced validation check of fields
400      */
401     $(document).on('click','input[name^=\'insert_ignore_\']', function (event) {
402         $('#insertForm').valid();
403     });
405     /**
406      * Uncheck the null checkbox as geometry data is placed on the input field
407      */
408     $(document).on('click', 'input[name=\'gis_data[save]\']', function (event) {
409         var input_name = $('form#gis_data_editor_form').find('input[name=\'input_name\']').val();
410         var $null_checkbox = $('input[name=\'' + input_name + '\']').parents('tr').find('.checkbox_null');
411         $null_checkbox.prop('checked', false);
412     });
414     /**
415      * Handles all current checkboxes for Null; this only takes care of the
416      * checkboxes on currently displayed rows as the rows generated by
417      * "Continue insertion" are handled in the "Continue insertion" code
418      *
419      */
420     $(document).on('click', 'input.checkbox_null', function () {
421         nullify(
422             // use hidden fields populated by tbl_change.php
423             $(this).siblings('.nullify_code').val(),
424             $(this).closest('tr').find('input:hidden').first().val(),
425             $(this).siblings('.hashed_field').val(),
426             $(this).siblings('.multi_edit').val()
427         );
428     });
430     /**
431      * Reset the auto_increment column to 0 when selecting any of the
432      * insert options in submit_type-dropdown. Only perform the reset
433      * when we are in edit-mode, and not in insert-mode(no previous value
434      * available).
435      */
436     $('select[name="submit_type"]').on('change', function () {
437         var thisElemSubmitTypeVal = $(this).val();
438         var $table = $('table.insertRowTable');
439         var auto_increment_column = $table.find('input[name^="auto_increment"]');
440         auto_increment_column.each(function () {
441             var $thisElemAIField = $(this);
442             var thisElemName = $thisElemAIField.attr('name');
444             var prev_value_field = $table.find('input[name="' + thisElemName.replace('auto_increment', 'fields_prev') + '"]');
445             var value_field = $table.find('input[name="' + thisElemName.replace('auto_increment', 'fields') + '"]');
446             var previous_value = $(prev_value_field).val();
447             if (previous_value !== undefined) {
448                 if (thisElemSubmitTypeVal === 'insert'
449                     || thisElemSubmitTypeVal === 'insertignore'
450                     || thisElemSubmitTypeVal === 'showinsert'
451                 ) {
452                     $(value_field).val(0);
453                 } else {
454                     $(value_field).val(previous_value);
455                 }
456             }
457         });
458     });
460     /**
461      * Handle ENTER key when press on Continue insert with field
462      */
463     $('#insert_rows').keypress(function (e) {
464         var key = e.which;
465         if (key === 13) {
466             addNewContinueInsertionFiels(e);
467         }
468     });
470     /**
471      * Continue Insertion form
472      */
473     $(document).on('change', '#insert_rows', addNewContinueInsertionFiels);
476 function addNewContinueInsertionFiels (event) {
477     event.preventDefault();
478     /**
479      * @var columnCount   Number of number of columns table has.
480      */
481     var columnCount = $('table.insertRowTable:first').find('tr').has('input[name*=\'fields_name\']').length;
482     /**
483      * @var curr_rows   Number of current insert rows already on page
484      */
485     var curr_rows = $('table.insertRowTable').length;
486     /**
487      * @var target_rows Number of rows the user wants
488      */
489     var target_rows = $('#insert_rows').val();
491     // remove all datepickers
492     $('input.datefield, input.datetimefield').each(function () {
493         $(this).datepicker('destroy');
494     });
496     if (curr_rows < target_rows) {
497         var tempIncrementIndex = function () {
498             var $this_element = $(this);
499             /**
500              * Extract the index from the name attribute for all input/select fields and increment it
501              * name is of format funcs[multi_edit][10][<long random string of alphanum chars>]
502              */
504             /**
505              * @var this_name   String containing name of the input/select elements
506              */
507             var this_name = $this_element.attr('name');
508             /** split {@link this_name} at [10], so we have the parts that can be concatenated later */
509             var name_parts = this_name.split(/\[\d+\]/);
510             /** extract the [10] from  {@link name_parts} */
511             var old_row_index_string = this_name.match(/\[\d+\]/)[0];
512             /** extract 10 - had to split into two steps to accomodate double digits */
513             var old_row_index = parseInt(old_row_index_string.match(/\d+/)[0], 10);
515             /** calculate next index i.e. 11 */
516             new_row_index = old_row_index + 1;
517             /** generate the new name i.e. funcs[multi_edit][11][foobarbaz] */
518             var new_name = name_parts[0] + '[' + new_row_index + ']' + name_parts[1];
520             var hashed_field = name_parts[1].match(/\[(.+)\]/)[1];
521             $this_element.attr('name', new_name);
523             /** If element is select[name*='funcs'], update id */
524             if ($this_element.is('select[name*=\'funcs\']')) {
525                 var this_id = $this_element.attr('id');
526                 var id_parts = this_id.split(/\_/);
527                 var old_id_index = id_parts[1];
528                 var prevSelectedValue = $('#field_' + old_id_index + '_1').val();
529                 var new_id_index = parseInt(old_id_index) + columnCount;
530                 var new_id = 'field_' + new_id_index + '_1';
531                 $this_element.attr('id', new_id);
532                 $this_element.find('option').filter(function () {
533                     return $(this).text() === prevSelectedValue;
534                 }).attr('selected','selected');
536                 // If salt field is there then update its id.
537                 var nextSaltInput = $this_element.parent().next('td').next('td').find('input[name*=\'salt\']');
538                 if (nextSaltInput.length !== 0) {
539                     nextSaltInput.attr('id', 'salt_' + new_id);
540                 }
541             }
543             // handle input text fields and textareas
544             if ($this_element.is('.textfield') || $this_element.is('.char') || $this_element.is('textarea')) {
545                 // do not remove the 'value' attribute for ENUM columns
546                 // special handling for radio fields after updating ids to unique - see below
547                 if ($this_element.closest('tr').find('span.column_type').html() !== 'enum') {
548                     $this_element.val($this_element.closest('tr').find('span.default_value').html());
549                 }
550                 $this_element
551                     .off('change')
552                     // Remove onchange attribute that was placed
553                     // by tbl_change.php; it refers to the wrong row index
554                     .attr('onchange', null)
555                     // Keep these values to be used when the element
556                     // will change
557                     .data('hashed_field', hashed_field)
558                     .data('new_row_index', new_row_index)
559                     .on('change', function () {
560                         var $changed_element = $(this);
561                         verificationsAfterFieldChange(
562                             $changed_element.data('hashed_field'),
563                             $changed_element.data('new_row_index'),
564                             $changed_element.closest('tr').find('span.column_type').html()
565                         );
566                     });
567             }
569             if ($this_element.is('.checkbox_null')) {
570                 $this_element
571                 // this event was bound earlier by jQuery but
572                 // to the original row, not the cloned one, so unbind()
573                     .off('click')
574                     // Keep these values to be used when the element
575                     // will be clicked
576                     .data('hashed_field', hashed_field)
577                     .data('new_row_index', new_row_index)
578                     .on('click', function () {
579                         var $changed_element = $(this);
580                         nullify(
581                             $changed_element.siblings('.nullify_code').val(),
582                             $this_element.closest('tr').find('input:hidden').first().val(),
583                             $changed_element.data('hashed_field'),
584                             '[multi_edit][' + $changed_element.data('new_row_index') + ']'
585                         );
586                     });
587             }
588         };
590         var tempReplaceAnchor = function () {
591             var $anchor = $(this);
592             var new_value = 'rownumber=' + new_row_index;
593             // needs improvement in case something else inside
594             // the href contains this pattern
595             var new_href = $anchor.attr('href').replace(/rownumber=\d+/, new_value);
596             $anchor.attr('href', new_href);
597         };
599         while (curr_rows < target_rows) {
600             /**
601              * @var $last_row    Object referring to the last row
602              */
603             var $last_row = $('#insertForm').find('.insertRowTable:last');
605             // need to access this at more than one level
606             // (also needs improvement because it should be calculated
607             //  just once per cloned row, not once per column)
608             var new_row_index = 0;
610             // Clone the insert tables
611             $last_row
612                 .clone(true, true)
613                 .insertBefore('#actions_panel')
614                 .find('input[name*=multi_edit],select[name*=multi_edit],textarea[name*=multi_edit]')
615                 .each(tempIncrementIndex)
616                 .end()
617                 .find('.foreign_values_anchor')
618                 .each(tempReplaceAnchor);
620             // Insert/Clone the ignore checkboxes
621             if (curr_rows === 1) {
622                 $('<input id="insert_ignore_1" type="checkbox" name="insert_ignore_1" checked="checked" />')
623                     .insertBefore('table.insertRowTable:last')
624                     .after('<label for="insert_ignore_1">' + PMA_messages.strIgnore + '</label>');
625             } else {
626                 /**
627                  * @var $last_checkbox   Object reference to the last checkbox in #insertForm
628                  */
629                 var $last_checkbox = $('#insertForm').children('input:checkbox:last');
631                 /** name of {@link $last_checkbox} */
632                 var last_checkbox_name = $last_checkbox.attr('name');
633                 /** index of {@link $last_checkbox} */
634                 var last_checkbox_index = parseInt(last_checkbox_name.match(/\d+/), 10);
635                 /** name of new {@link $last_checkbox} */
636                 var new_name = last_checkbox_name.replace(/\d+/, last_checkbox_index + 1);
638                 $('<br/><div class="clearfloat"></div>')
639                     .insertBefore('table.insertRowTable:last');
641                 $last_checkbox
642                     .clone()
643                     .attr({ 'id': new_name, 'name': new_name })
644                     .prop('checked', true)
645                     .insertBefore('table.insertRowTable:last');
647                 $('label[for^=insert_ignore]:last')
648                     .clone()
649                     .attr('for', new_name)
650                     .insertBefore('table.insertRowTable:last');
652                 $('<br/>')
653                     .insertBefore('table.insertRowTable:last');
654             }
655             curr_rows++;
656         }
657         // recompute tabindex for text fields and other controls at footer;
658         // IMO it's not really important to handle the tabindex for
659         // function and Null
660         var tabindex = 0;
661         $('.textfield, .char, textarea')
662             .each(function () {
663                 tabindex++;
664                 $(this).attr('tabindex', tabindex);
665                 // update the IDs of textfields to ensure that they are unique
666                 $(this).attr('id', 'field_' + tabindex + '_3');
668                 // special handling for radio fields after updating ids to unique
669                 if ($(this).closest('tr').find('span.column_type').html() === 'enum') {
670                     if ($(this).val() === $(this).closest('tr').find('span.default_value').html()) {
671                         $(this).prop('checked', true);
672                     } else {
673                         $(this).prop('checked', false);
674                     }
675                 }
676             });
677         $('.control_at_footer')
678             .each(function () {
679                 tabindex++;
680                 $(this).attr('tabindex', tabindex);
681             });
682     } else if (curr_rows > target_rows) {
683         /**
684          * Displays alert if data loss possible on decrease
685          * of rows.
686          */
687         var checkLock = jQuery.isEmptyObject(AJAX.lockedTargets);
688         if (checkLock || confirm(PMA_messages.strConfirmRowChange) === true) {
689             while (curr_rows > target_rows) {
690                 $('input[id^=insert_ignore]:last')
691                     .nextUntil('fieldset')
692                     .addBack()
693                     .remove();
694                 curr_rows--;
695             }
696         } else {
697             document.getElementById('insert_rows').value = curr_rows;
698         }
699     }
700     // Add all the required datepickers back
701     addDateTimePicker();
704 function changeValueFieldType (elem, searchIndex) {
705     var fieldsValue = $('select#fieldID_' + searchIndex);
706     if (0 === fieldsValue.size()) {
707         return;
708     }
710     var type = $(elem).val();
711     if ('IN (...)' === type ||
712         'NOT IN (...)' === type ||
713         'BETWEEN' === type ||
714         'NOT BETWEEN' === type
715     ) {
716         $('#fieldID_' + searchIndex).attr('multiple', '');
717     } else {
718         $('#fieldID_' + searchIndex).removeAttr('multiple');
719     }