1 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 * general function, usually for data manipulation pages
8 * @var $table_clone reference to the action links on the tbl_structure page
10 var $table_clone = false;
13 * @var sql_box_locked lock for the sqlbox textarea in the querybox/querywindow
15 var sql_box_locked = false;
18 * @var array holds elements which content should only selected once
20 var only_once_elements = [];
23 * @var int ajax_message_count Number of AJAX messages shown since page load
25 var ajax_message_count = 0;
28 * @var codemirror_editor object containing CodeMirror editor of the query editor in SQL tab
30 var codemirror_editor = false;
33 * @var codemirror_editor object containing CodeMirror editor of the inline query editor
35 var codemirror_inline_editor = false;
38 * @var chart_activeTimeouts object active timeouts that refresh the charts. When disabling a realtime chart, this can be used to stop the continuous ajax requests
40 var chart_activeTimeouts = {};
43 * Make sure that ajax requests will not be cached
44 * by appending a random variable to their parameters
46 $.ajaxPrefilter(function (options, originalOptions, jqXHR) {
47 var nocache = new Date().getTime() + "" + Math.floor(Math.random() * 1000000);
48 if (typeof options.data == "string") {
49 options.data += "&_nocache=" + nocache;
50 } else if (typeof options.data == "object") {
51 options.data = $.extend(originalOptions.data, {'_nocache' : nocache});
56 * Add a hidden field to the form to indicate that this will be an
57 * Ajax request (only if this hidden field does not exist)
59 * @param object the form
61 function PMA_prepareForAjaxRequest($form)
63 if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
64 $form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
69 * Generate a new password and copy it to the password input areas
71 * @param object the form that holds the password fields
73 * @return boolean always true
75 function suggestPassword(passwd_form)
77 // restrict the password to just letters and numbers to avoid problems:
78 // "editors and viewers regard the password as multiple words and
79 // things like double click no longer work"
80 var pwchars = "abcdefhjmnpqrstuvwxyz23456789ABCDEFGHJKLMNPQRSTUVWYXZ";
81 var passwordlength = 16; // do we want that to be dynamic? no, keep it simple :)
82 var passwd = passwd_form.generated_pw;
85 for (var i = 0; i < passwordlength; i++) {
86 passwd.value += pwchars.charAt(Math.floor(Math.random() * pwchars.length));
88 passwd_form.text_pma_pw.value = passwd.value;
89 passwd_form.text_pma_pw2.value = passwd.value;
94 * Version string to integer conversion.
96 function parseVersionString(str)
98 if (typeof(str) != 'string') { return false; }
100 // Parse possible alpha/beta/rc/
101 var state = str.split('-');
102 if (state.length >= 2) {
103 if (state[1].substr(0, 2) == 'rc') {
104 add = - 20 - parseInt(state[1].substr(2), 10);
105 } else if (state[1].substr(0, 4) == 'beta') {
106 add = - 40 - parseInt(state[1].substr(4), 10);
107 } else if (state[1].substr(0, 5) == 'alpha') {
108 add = - 60 - parseInt(state[1].substr(5), 10);
109 } else if (state[1].substr(0, 3) == 'dev') {
110 /* We don't handle dev, it's git snapshot */
115 var x = str.split('.');
116 // Use 0 for non existing parts
117 var maj = parseInt(x[0], 10) || 0;
118 var min = parseInt(x[1], 10) || 0;
119 var pat = parseInt(x[2], 10) || 0;
120 var hotfix = parseInt(x[3], 10) || 0;
121 return maj * 100000000 + min * 1000000 + pat * 10000 + hotfix * 100 + add;
125 * Indicates current available version on main page.
127 function PMA_current_version(data)
129 if (data && data.version && data.date) {
130 var current = parseVersionString(pmaversion);
131 var latest = parseVersionString(data.version);
132 var version_information_message = PMA_messages.strLatestAvailable + ' ' + escapeHtml(data.version);
133 if (latest > current) {
134 var message = $.sprintf(
135 PMA_messages.strNewerVersion,
136 escapeHtml(data.version),
137 escapeHtml(data.date)
139 var htmlClass = 'notice';
140 if (Math.floor(latest / 10000) === Math.floor(current / 10000)) {
141 /* Security update */
144 $('#maincontainer').after('<div class="' + htmlClass + '">' + message + '</div>');
146 if (latest === current) {
147 version_information_message = ' (' + PMA_messages.strUpToDate + ')';
149 $('#li_pma_version').append(version_information_message);
154 * Loads Git revision data from ajax for index.php
156 function PMA_display_git_revision()
158 $('#is_git_revision').remove();
162 "server": PMA_commonParams.get('server'),
163 "token": PMA_commonParams.get('token'),
164 "git_revision": true,
168 if (data.success === true) {
169 $(data.message).insertAfter('#li_pma_version');
176 * for libraries/display_change_password.lib.php
177 * libraries/user_password.php
181 function displayPasswordGenerateButton()
183 $('#tr_element_before_generate_password').parent().append('<tr class="vmiddle"><td>' + PMA_messages.strGeneratePassword + '</td><td><input type="button" class="button" id="button_generate_password" value="' + PMA_messages.strGenerate + '" onclick="suggestPassword(this.form)" /><input type="text" name="generated_pw" id="generated_pw" /></td></tr>');
184 $('#div_element_before_generate_password').parent().append('<div class="item"><label for="button_generate_password">' + PMA_messages.strGeneratePassword + ':</label><span class="options"><input type="button" class="button" id="button_generate_password" value="' + PMA_messages.strGenerate + '" onclick="suggestPassword(this.form)" /></span><input type="text" name="generated_pw" id="generated_pw" /></div>');
188 * Adds a date/time picker to an element
190 * @param object $this_element a jQuery object pointing to the element
192 function PMA_addDatepicker($this_element, options)
194 var showTimeOption = false;
195 if ($this_element.is('.datetimefield')) {
196 showTimeOption = true;
199 var defaultOptions = {
201 buttonImage: themeCalendarImage, // defined in js/messages.php
202 buttonImageOnly: true,
208 showTimepicker: showTimeOption,
209 showButtonPanel: false,
210 dateFormat: 'yy-mm-dd', // yy means year with four digits
211 timeFormat: 'HH:mm:ss.lc',
212 altFieldTimeOnly: false,
214 beforeShow: function (input, inst) {
215 // Remember that we came from the datepicker; this is used
216 // in tbl_change.js by verificationsAfterFieldChange()
217 $this_element.data('comes_from', 'datepicker');
219 // Fix wrong timepicker z-index, doesn't work without timeout
220 setTimeout(function () {
221 $('#ui-timepicker-div').css('z-index', $('#ui-datepicker-div').css('z-index'));
224 onClose: function (dateText, dp_inst) {
225 // The value is no more from the date picker
226 $this_element.data('comes_from', '');
229 if (showTimeOption || (typeof(options) != 'undefined' && options.showTimepicker)) {
230 $this_element.datetimepicker($.extend(defaultOptions, options));
232 $this_element.datepicker($.extend(defaultOptions, options));
237 * selects the content of a given object, f.e. a textarea
239 * @param object element element of which the content will be selected
240 * @param var lock variable which holds the lock for this element
241 * or true, if no lock exists
242 * @param boolean only_once if true this is only done once
243 * f.e. only on first focus
245 function selectContent(element, lock, only_once)
247 if (only_once && only_once_elements[element.name]) {
251 only_once_elements[element.name] = true;
261 * Displays a confirmation box before submitting a "DROP/DELETE/ALTER" query.
262 * This function is called while clicking links
264 * @param object the link
265 * @param object the sql query to submit
267 * @return boolean whether to run the query or not
269 function confirmLink(theLink, theSqlQuery)
271 // Confirmation is not required in the configuration file
272 // or browser is Opera (crappy js implementation)
273 if (PMA_messages.strDoYouReally === '' || typeof(window.opera) != 'undefined') {
277 var is_confirmed = confirm($.sprintf(PMA_messages.strDoYouReally, theSqlQuery));
279 if ($(theLink).hasClass('formLinkSubmit')) {
280 var name = 'is_js_confirmed';
281 if ($(theLink).attr('href').indexOf('usesubform') != -1) {
282 name = 'subform[' + $(theLink).attr('href').substr('#').match(/usesubform\[(\d+)\]/i)[1] + '][is_js_confirmed]';
285 $(theLink).parents('form').append('<input type="hidden" name="' + name + '" value="1" />');
286 } else if (typeof(theLink.href) != 'undefined') {
287 theLink.href += '&is_js_confirmed=1';
288 } else if (typeof(theLink.form) != 'undefined') {
289 theLink.form.action += '?is_js_confirmed=1';
294 } // end of the 'confirmLink()' function
297 * Displays an error message if a "DROP DATABASE" statement is submitted
298 * while it isn't allowed, else confirms a "DROP/DELETE/ALTER" query before
299 * sumitting it if required.
300 * This function is called by the 'checkSqlQuery()' js function.
302 * @param object the form
303 * @param object the sql query textarea
305 * @return boolean whether to run the query or not
307 * @see checkSqlQuery()
309 function confirmQuery(theForm1, sqlQuery1)
311 // Confirmation is not required in the configuration file
312 if (PMA_messages.strDoYouReally === '') {
316 // "DROP DATABASE" statement isn't allowed
317 if (PMA_messages.strNoDropDatabases !== '') {
318 var drop_re = new RegExp('(^|;)\\s*DROP\\s+(IF EXISTS\\s+)?DATABASE\\s', 'i');
319 if (drop_re.test(sqlQuery1.value)) {
320 alert(PMA_messages.strNoDropDatabases);
327 // Confirms a "DROP/DELETE/ALTER/TRUNCATE" statement
329 // TODO: find a way (if possible) to use the parser-analyser
330 // for this kind of verification
331 // For now, I just added a ^ to check for the statement at
332 // beginning of expression
334 var do_confirm_re_0 = new RegExp('^\\s*DROP\\s+(IF EXISTS\\s+)?(TABLE|DATABASE|PROCEDURE)\\s', 'i');
335 var do_confirm_re_1 = new RegExp('^\\s*ALTER\\s+TABLE\\s+((`[^`]+`)|([A-Za-z0-9_$]+))\\s+DROP\\s', 'i');
336 var do_confirm_re_2 = new RegExp('^\\s*DELETE\\s+FROM\\s', 'i');
337 var do_confirm_re_3 = new RegExp('^\\s*TRUNCATE\\s', 'i');
339 if (do_confirm_re_0.test(sqlQuery1.value) ||
340 do_confirm_re_1.test(sqlQuery1.value) ||
341 do_confirm_re_2.test(sqlQuery1.value) ||
342 do_confirm_re_3.test(sqlQuery1.value)) {
344 if (sqlQuery1.value.length > 100) {
345 message = sqlQuery1.value.substr(0, 100) + '\n ...';
347 message = sqlQuery1.value;
349 var is_confirmed = confirm($.sprintf(PMA_messages.strDoYouReally, message));
350 // statement is confirmed -> update the
351 // "is_js_confirmed" form field so the confirm test won't be
352 // run on the server side and allows to submit the form
354 theForm1.elements['is_js_confirmed'].value = 1;
357 // statement is rejected -> do not submit the form
362 } // end if (handle confirm box result)
363 } // end if (display confirm box)
366 } // end of the 'confirmQuery()' function
369 * Displays an error message if the user submitted the sql query form with no
370 * sql query, else checks for "DROP/DELETE/ALTER" statements
372 * @param object the form
374 * @return boolean always false
376 * @see confirmQuery()
378 function checkSqlQuery(theForm)
381 // First check if codemirror is active.
382 if (codemirror_editor) {
383 theForm.elements['sql_query'].value = codemirror_editor.getValue();
386 var sqlQuery = theForm.elements['sql_query'];
390 var space_re = new RegExp('\\s+');
391 if (typeof(theForm.elements['sql_file']) != 'undefined' &&
392 theForm.elements['sql_file'].value.replace(space_re, '') !== '') {
395 if (typeof(theForm.elements['sql_localfile']) != 'undefined' &&
396 theForm.elements['sql_localfile'].value.replace(space_re, '') !== '') {
399 if (isEmpty && typeof(theForm.elements['id_bookmark']) != 'undefined' &&
400 (theForm.elements['id_bookmark'].value !== null || theForm.elements['id_bookmark'].value !== '') &&
401 theForm.elements['id_bookmark'].selectedIndex !== 0) {
404 // Checks for "DROP/DELETE/ALTER" statements
405 if (sqlQuery.value.replace(space_re, '') !== '') {
406 if (confirmQuery(theForm, sqlQuery)) {
417 alert(PMA_messages.strFormEmpty);
423 } // end of the 'checkSqlQuery()' function
426 * Check if a form's element is empty.
427 * An element containing only spaces is also considered empty
429 * @param object the form
430 * @param string the name of the form field to put the focus on
432 * @return boolean whether the form field is empty or not
434 function emptyCheckTheField(theForm, theFieldName)
436 var theField = theForm.elements[theFieldName];
437 var space_re = new RegExp('\\s+');
438 return (theField.value.replace(space_re, '') === '') ? 1 : 0;
439 } // end of the 'emptyCheckTheField()' function
443 * Check whether a form field is empty or not
445 * @param object the form
446 * @param string the name of the form field to put the focus on
448 * @return boolean whether the form field is empty or not
450 function emptyFormElements(theForm, theFieldName)
452 var theField = theForm.elements[theFieldName];
453 var isEmpty = emptyCheckTheField(theForm, theFieldName);
457 } // end of the 'emptyFormElements()' function
461 * Ensures a value submitted in a form is numeric and is in a range
463 * @param object the form
464 * @param string the name of the form field to check
465 * @param integer the minimum authorized value
466 * @param integer the maximum authorized value
468 * @return boolean whether a valid number has been submitted or not
470 function checkFormElementInRange(theForm, theFieldName, message, min, max)
472 var theField = theForm.elements[theFieldName];
473 var val = parseInt(theField.value, 10);
475 if (typeof(min) == 'undefined') {
478 if (typeof(max) == 'undefined') {
479 max = Number.MAX_VALUE;
485 alert(PMA_messages.strEnterValidNumber);
489 // It's a number but it is not between min and max
490 else if (val < min || val > max) {
492 alert($.sprintf(message, val));
496 // It's a valid number
498 theField.value = val;
502 } // end of the 'checkFormElementInRange()' function
505 function checkTableEditForm(theForm, fieldsCnt)
507 // TODO: avoid sending a message if user just wants to add a line
508 // on the form but has not completed at least one field name
510 var atLeastOneField = 0;
511 var i, elm, elm2, elm3, val, id;
513 for (i = 0; i < fieldsCnt; i++) {
514 id = "#field_" + i + "_2";
517 if (val == 'VARCHAR' || val == 'CHAR' || val == 'BIT' || val == 'VARBINARY' || val == 'BINARY') {
518 elm2 = $("#field_" + i + "_3");
519 val = parseInt(elm2.val(), 10);
520 elm3 = $("#field_" + i + "_1");
521 if (isNaN(val) && elm3.val() !== "") {
523 alert(PMA_messages.strEnterValidLength);
529 if (atLeastOneField === 0) {
530 id = "field_" + i + "_1";
531 if (!emptyCheckTheField(theForm, id)) {
536 if (atLeastOneField === 0) {
537 var theField = theForm.elements["field_0_1"];
538 alert(PMA_messages.strFormEmpty);
543 // at least this section is under jQuery
544 if ($("input.textfield[name='table']").val() === "") {
545 alert(PMA_messages.strFormEmpty);
546 $("input.textfield[name='table']").focus();
552 } // enf of the 'checkTableEditForm()' function
555 * Unbind all event handlers before tearing down a page
557 AJAX.registerTeardown('functions.js', function () {
558 $('input:checkbox.checkall').die('click');
560 AJAX.registerOnload('functions.js', function () {
562 * Row marking in horizontal mode (use "live" so that it works also for
563 * next pages reached via AJAX); a tr may have the class noclick to remove
567 $('input:checkbox.checkall').live('click', function (e) {
568 var $tr = $(this).closest('tr');
570 // make the table unselectable (to prevent default highlighting when shift+click)
571 //$tr.parents('table').noSelect();
573 if (!e.shiftKey || last_clicked_row == -1) {
576 // XXX: FF fires two click events for <label> (label and checkbox), so we need to handle this differently
577 var $checkbox = $tr.find(':checkbox');
578 if ($checkbox.length) {
579 // checkbox in a row, add or remove class depending on checkbox state
580 var checked = $checkbox.prop('checked');
581 if (!$(e.target).is(':checkbox, label')) {
583 $checkbox.prop('checked', checked).trigger('change');
586 $tr.addClass('marked');
588 $tr.removeClass('marked');
590 last_click_checked = checked;
592 // normal data table, just toggle class
593 $tr.toggleClass('marked');
594 last_click_checked = false;
597 // remember the last clicked row
598 last_clicked_row = last_click_checked ? $('tr.odd:not(.noclick), tr.even:not(.noclick)').index($tr) : -1;
599 last_shift_clicked_row = -1;
601 // handle the shift click
602 PMA_clearSelection();
605 // clear last shift click result
606 if (last_shift_clicked_row >= 0) {
607 if (last_shift_clicked_row >= last_clicked_row) {
608 start = last_clicked_row;
609 end = last_shift_clicked_row;
611 start = last_shift_clicked_row;
612 end = last_clicked_row;
614 $tr.parent().find('tr.odd:not(.noclick), tr.even:not(.noclick)')
615 .slice(start, end + 1)
616 .removeClass('marked')
618 .prop('checked', false)
622 // handle new shift click
623 var curr_row = $('tr.odd:not(.noclick), tr.even:not(.noclick)').index($tr);
624 if (curr_row >= last_clicked_row) {
625 start = last_clicked_row;
629 end = last_clicked_row;
631 $tr.parent().find('tr.odd:not(.noclick), tr.even:not(.noclick)')
632 .slice(start, end + 1)
635 .prop('checked', true)
638 // remember the last shift clicked row
639 last_shift_clicked_row = curr_row;
646 * Add attribute to text boxes for iOS devices (based on bugID: 3508912)
648 if (navigator.userAgent.match(/(iphone|ipod|ipad)/i)) {
649 $('input[type=text]').attr('autocapitalize', 'off').attr('autocorrect', 'off');
654 * True if last click is to check a row.
656 var last_click_checked = false;
659 * Zero-based index of last clicked row.
660 * Used to handle the shift + click event in the code above.
662 var last_clicked_row = -1;
665 * Zero-based index of last shift clicked row.
667 var last_shift_clicked_row = -1;
670 * Row highlighting in horizontal mode (use "live"
671 * so that it works also for pages reached via AJAX)
673 /*AJAX.registerOnload('functions.js', function () {
674 $('tr.odd, tr.even').live('hover',function (event) {
676 $tr.toggleClass('hover',event.type=='mouseover');
677 $tr.children().toggleClass('hover',event.type=='mouseover');
682 * This array is used to remember mark status of rows in browse mode
687 * marks all rows and selects its first checkbox inside the given element
688 * the given element is usaly a table or a div containing the table or tables
690 * @param container DOM element
692 function markAllRows(container_id)
695 $("#" + container_id).find("input:checkbox:enabled").prop('checked', true)
697 .parents("tr").addClass("marked");
702 * marks all rows and selects its first checkbox inside the given element
703 * the given element is usaly a table or a div containing the table or tables
705 * @param container DOM element
707 function unMarkAllRows(container_id)
710 $("#" + container_id).find("input:checkbox:enabled").prop('checked', false)
712 .parents("tr").removeClass("marked");
717 * Checks/unchecks all checkbox in given conainer (f.e. a form, fieldset or div)
719 * @param string container_id the container id
720 * @param boolean state new value for checkbox (true or false)
721 * @return boolean always true
723 function setCheckboxes(container_id, state)
726 $("#" + container_id).find("input:checkbox").prop('checked', state);
728 } // end of the 'setCheckboxes()' function
731 * Checks/unchecks all options of a <select> element
733 * @param string the form name
734 * @param string the element name
735 * @param boolean whether to check or to uncheck options
737 * @return boolean always true
739 function setSelectOptions(the_form, the_select, do_check)
741 $("form[name='" + the_form + "'] select[name='" + the_select + "']").find("option").prop('selected', do_check);
743 } // end of the 'setSelectOptions()' function
746 * Sets current value for query box.
748 function setQuery(query)
750 if (codemirror_editor) {
751 codemirror_editor.setValue(query);
752 codemirror_editor.focus();
754 document.sqlform.sql_query.value = query;
755 document.sqlform.sql_query.focus();
761 * Create quick sql statements.
764 function insertQuery(queryType)
766 if (queryType == "clear") {
772 var myListBox = document.sqlform.dummy;
773 var table = document.sqlform.table.value;
775 if (myListBox.options.length > 0) {
776 sql_box_locked = true;
781 for (var i = 0; i < myListBox.options.length; i++) {
788 chaineAj += myListBox.options[i].value;
789 valDis += "[value-" + NbSelect + "]";
790 editDis += myListBox.options[i].value + "=[value-" + NbSelect + "]";
792 if (queryType == "selectall") {
793 query = "SELECT * FROM `" + table + "` WHERE 1";
794 } else if (queryType == "select") {
795 query = "SELECT " + chaineAj + " FROM `" + table + "` WHERE 1";
796 } else if (queryType == "insert") {
797 query = "INSERT INTO `" + table + "`(" + chaineAj + ") VALUES (" + valDis + ")";
798 } else if (queryType == "update") {
799 query = "UPDATE `" + table + "` SET " + editDis + " WHERE 1";
800 } else if (queryType == "delete") {
801 query = "DELETE FROM `" + table + "` WHERE 1";
804 sql_box_locked = false;
810 * Inserts multiple fields.
813 function insertValueQuery()
815 var myQuery = document.sqlform.sql_query;
816 var myListBox = document.sqlform.dummy;
818 if (myListBox.options.length > 0) {
819 sql_box_locked = true;
822 for (var i = 0; i < myListBox.options.length; i++) {
823 if (myListBox.options[i].selected) {
828 chaineAj += myListBox.options[i].value;
832 /* CodeMirror support */
833 if (codemirror_editor) {
834 codemirror_editor.replaceSelection(chaineAj);
836 } else if (document.selection) {
838 var sel = document.selection.createRange();
840 document.sqlform.insert.focus();
842 //MOZILLA/NETSCAPE support
843 else if (document.sqlform.sql_query.selectionStart || document.sqlform.sql_query.selectionStart == "0") {
844 var startPos = document.sqlform.sql_query.selectionStart;
845 var endPos = document.sqlform.sql_query.selectionEnd;
846 var chaineSql = document.sqlform.sql_query.value;
848 myQuery.value = chaineSql.substring(0, startPos) + chaineAj + chaineSql.substring(endPos, chaineSql.length);
850 myQuery.value += chaineAj;
852 sql_box_locked = false;
857 * Add a date/time picker to each element that needs it
858 * (only when jquery-ui-timepicker-addon.js is loaded)
860 function addDateTimePicker() {
861 if ($.timepicker !== undefined) {
862 $('input.datefield, input.datetimefield').each(function () {
863 PMA_addDatepicker($(this));
869 * Refresh/resize the WYSIWYG scratchboard
871 function refreshLayout()
873 var $elm = $('#pdflayout');
874 var orientation = $('#orientation_opt').val();
876 if ($('#paper_opt').length == 1) {
877 paper = $('#paper_opt').val();
881 if (orientation == 'P') {
885 $elm.css('width', pdfPaperSize(paper, posa) + 'px');
886 $elm.css('height', pdfPaperSize(paper, posb) + 'px');
890 * Initializes positions of elements.
892 function TableDragInit() {
893 $('.pdflayout_table').each(function () {
895 var number = $this.data('number');
896 var x = $('#c_table_' + number + '_x').val();
897 var y = $('#c_table_' + number + '_y').val();
898 $this.css('left', x + 'px');
899 $this.css('top', y + 'px');
900 /* Make elements draggable */
902 containment: "parent",
903 drag: function (evt, ui) {
904 var number = $this.data('number');
905 $('#c_table_' + number + '_x').val(parseInt(ui.position.left, 10));
906 $('#c_table_' + number + '_y').val(parseInt(ui.position.top, 10));
913 * Resets drag and drop positions.
915 function resetDrag() {
916 $('.pdflayout_table').each(function () {
918 var x = $this.data('x');
919 var y = $this.data('y');
920 $this.css('left', x + 'px');
921 $this.css('top', y + 'px');
926 * User schema handlers.
929 /* Move in scratchboard on manual change */
930 $('.position-change').live('change', function () {
932 var $elm = $('#table_' + $this.data('number'));
933 $elm.css($this.data('axis'), $this.val() + 'px');
935 /* Refresh on paper size/orientation change */
936 $('.paper-change').live('change', function () {
937 var $elm = $('#pdflayout');
938 if ($elm.css('visibility') == 'visible') {
943 /* Show/hide the WYSIWYG scratchboard */
944 $('#toggle-dragdrop').live('click', function () {
945 var $elm = $('#pdflayout');
946 if ($elm.css('visibility') == 'hidden') {
949 $elm.css('visibility', 'visible');
950 $elm.css('display', 'block');
951 $('#showwysiwyg').val('1');
953 $elm.css('visibility', 'hidden');
954 $elm.css('display', 'none');
955 $('#showwysiwyg').val('0');
958 /* Reset scratchboard */
959 $('#reset-dragdrop').live('click', function () {
965 * Returns paper sizes for a given format
967 function pdfPaperSize(format, axis)
969 switch (format.toUpperCase()) {
1319 * Unbind all event handlers before tearing down a page
1321 AJAX.registerTeardown('functions.js', function () {
1322 $("a.inline_edit_sql").die('click');
1323 $("input#sql_query_edit_save").die('click');
1324 $("input#sql_query_edit_discard").die('click');
1325 $('input.sqlbutton').unbind('click');
1326 $("#export_type").unbind('change');
1327 $('#sqlquery').unbind('keydown');
1328 $('#sql_query_edit').unbind('keydown');
1330 if (codemirror_inline_editor) {
1331 // Copy the sql query to the text area to preserve it.
1332 $('#sql_query_edit').text(codemirror_inline_editor.getValue());
1333 $(codemirror_inline_editor.getWrapperElement()).unbind('keydown');
1334 codemirror_inline_editor.toTextArea();
1335 codemirror_inline_editor = false;
1337 if (codemirror_editor) {
1338 $(codemirror_editor.getWrapperElement()).unbind('keydown');
1343 * Jquery Coding for inline editing SQL_QUERY
1345 AJAX.registerOnload('functions.js', function () {
1346 // If we are coming back to the page by clicking forward button
1347 // of the browser, bind the code mirror to inline query editor.
1348 bindCodeMirrorToInlineEditor();
1349 $("a.inline_edit_sql").live('click', function () {
1350 if ($('#sql_query_edit').length) {
1351 // An inline query editor is already open,
1352 // we don't want another copy of it
1356 var $form = $(this).prev('form');
1357 var sql_query = $form.find("input[name='sql_query']").val();
1358 var $inner_sql = $(this).parent().prev().find('.inner_sql');
1359 var $sql_highlight = $(this).parent().prev().find('.sql-highlight');
1360 var old_text = $inner_sql.html();
1362 var new_content = "<textarea name=\"sql_query_edit\" id=\"sql_query_edit\">" + sql_query + "</textarea>\n";
1363 new_content += "<input type=\"submit\" id=\"sql_query_edit_save\" class=\"button btnSave\" value=\"" + PMA_messages.strGo + "\"/>\n";
1364 new_content += "<input type=\"button\" id=\"sql_query_edit_discard\" class=\"button btnDiscard\" value=\"" + PMA_messages.strCancel + "\"/>\n";
1365 var $editor_area = $('div#inline_editor');
1366 if ($editor_area.length === 0) {
1367 $editor_area = $('<div id="inline_editor_outer"></div>');
1368 $editor_area.insertBefore($inner_sql);
1370 $editor_area.html(new_content);
1372 $sql_highlight.hide();
1374 bindCodeMirrorToInlineEditor();
1378 $("input#sql_query_edit_save").live('click', function () {
1380 if (codemirror_inline_editor) {
1381 sql_query = codemirror_inline_editor.getValue();
1383 sql_query = $(this).prev().val();
1386 var $form = $("a.inline_edit_sql").prev('form');
1387 var $fake_form = $('<form>', {action: 'import.php', method: 'post'})
1388 .append($form.find("input[name=server], input[name=db], input[name=table], input[name=token]").clone())
1389 .append($('<input/>', {type: 'hidden', name: 'show_query', value: 1}))
1390 .append($('<input/>', {type: 'hidden', name: 'sql_query', value: sql_query}));
1391 $fake_form.appendTo($('body')).submit();
1394 $("input#sql_query_edit_discard").live('click', function () {
1395 $('div#inline_editor_outer')
1396 .siblings('.sql-highlight').show();
1397 $('div#inline_editor_outer').remove();
1400 $('input.sqlbutton').click(function (evt) {
1401 insertQuery(evt.target.id);
1405 $("#export_type").change(function () {
1406 if ($("#export_type").val() == 'svg') {
1407 $("#show_grid_opt").prop("disabled", true);
1408 $("#orientation_opt").prop("disabled", true);
1409 $("#with_doc").prop("disabled", true);
1410 $("#show_table_dim_opt").removeProp("disabled");
1411 $("#all_tables_same_width").removeProp("disabled");
1412 $("#paper_opt").removeProp("disabled");
1413 $("#show_color_opt").removeProp("disabled");
1414 //$(this).css("background-color","yellow");
1415 } else if ($("#export_type").val() == 'dia') {
1416 $("#show_grid_opt").prop("disabled", true);
1417 $("#with_doc").prop("disabled", true);
1418 $("#show_table_dim_opt").prop("disabled", true);
1419 $("#all_tables_same_width").prop("disabled", true);
1420 $("#paper_opt").removeProp("disabled");
1421 $("#show_color_opt").removeProp("disabled");
1422 $("#orientation_opt").removeProp("disabled");
1423 } else if ($("#export_type").val() == 'eps') {
1424 $("#show_grid_opt").prop("disabled", true);
1425 $("#orientation_opt").removeProp("disabled");
1426 $("#with_doc").prop("disabled", true);
1427 $("#show_table_dim_opt").prop("disabled", true);
1428 $("#all_tables_same_width").prop("disabled", true);
1429 $("#paper_opt").prop("disabled", true);
1430 $("#show_color_opt").prop("disabled", true);
1431 } else if ($("#export_type").val() == 'pdf') {
1432 $("#show_grid_opt").removeProp("disabled");
1433 $("#orientation_opt").removeProp("disabled");
1434 $("#with_doc").removeProp("disabled");
1435 $("#show_table_dim_opt").removeProp("disabled");
1436 $("#all_tables_same_width").removeProp("disabled");
1437 $("#paper_opt").removeProp("disabled");
1438 $("#show_color_opt").removeProp("disabled");
1444 if ($('#input_username')) {
1445 if ($('#input_username').val() === '') {
1446 $('#input_username').focus();
1448 $('#input_password').focus();
1454 * Binds the CodeMirror to the text area used to inline edit a query.
1456 function bindCodeMirrorToInlineEditor() {
1457 var $inline_editor = $('#sql_query_edit');
1458 if ($inline_editor.length > 0) {
1459 if (typeof CodeMirror !== 'undefined') {
1460 var height = $('#sql_query_edit').css('height');
1461 codemirror_inline_editor = CodeMirror.fromTextArea($inline_editor[0], {
1463 matchBrackets: true,
1465 mode: "text/x-mysql",
1468 codemirror_inline_editor.getScrollerElement().style.height = height;
1469 codemirror_inline_editor.refresh();
1470 codemirror_inline_editor.focus();
1471 $(codemirror_inline_editor.getWrapperElement()).bind(
1473 catchKeypressesFromSqlTextboxes
1476 $inline_editor.focus().bind(
1478 catchKeypressesFromSqlTextboxes
1484 function catchKeypressesFromSqlTextboxes(event) {
1485 // ctrl-enter is 10 in chrome and ie, but 13 in ff
1486 if (event.ctrlKey && (event.keyCode == 13 || event.keyCode == 10)) {
1487 if ($('#sql_query_edit').length > 0) {
1488 $("#sql_query_edit_save").trigger('click');
1489 } else if ($('#sqlquery').length > 0) {
1490 $("#button_submit_query").trigger('click');
1496 * Adds doc link to single highlighted SQL element
1498 function PMA_doc_add($elm, params)
1500 var url = $.sprintf(
1504 if (params.length > 1) {
1505 url += '#' + params[1];
1507 var content = $elm.text();
1509 $elm.append('<a target="mysql_doc" class="cm-sql-doc" href="' + url + '">' + content + '</a>');
1513 * Generates doc links for keywords inside highlighted SQL
1515 function PMA_doc_keyword(idx, elm)
1518 /* Skip already processed ones */
1519 if ($elm.find('a').length > 0) {
1522 var keyword = $elm.text().toUpperCase();
1523 var $next = $elm.next('.cm-keyword');
1525 var next_keyword = $next.text().toUpperCase();
1526 var full = keyword + ' ' + next_keyword;
1528 var $next2 = $next.next('.cm-keyword');
1530 var next2_keyword = $next2.text().toUpperCase();
1531 var full2 = full + ' ' + next2_keyword;
1532 if (full2 in mysql_doc_keyword) {
1533 PMA_doc_add($elm, mysql_doc_keyword[full2]);
1534 PMA_doc_add($next, mysql_doc_keyword[full2]);
1535 PMA_doc_add($next2, mysql_doc_keyword[full2]);
1539 if (full in mysql_doc_keyword) {
1540 PMA_doc_add($elm, mysql_doc_keyword[full]);
1541 PMA_doc_add($next, mysql_doc_keyword[full]);
1545 if (keyword in mysql_doc_keyword) {
1546 PMA_doc_add($elm, mysql_doc_keyword[keyword]);
1551 * Generates doc links for builtins inside highlighted SQL
1553 function PMA_doc_builtin(idx, elm)
1556 var builtin = $elm.text().toUpperCase();
1557 if (builtin in mysql_doc_builtin) {
1558 PMA_doc_add($elm, mysql_doc_builtin[builtin]);
1563 * Higlights SQL using CodeMirror.
1565 function PMA_highlightSQL(base)
1567 var $elm = base.find('code.sql');
1568 $elm.each(function () {
1570 var $pre = $sql.find('pre');
1571 /* We only care about visible elements to avoid double processing */
1572 if ($pre.is(":visible")) {
1573 var $highlight = $('<div class="sql-highlight cm-s-default"></div>');
1574 $sql.append($highlight);
1575 if (typeof CodeMirror != 'undefined') {
1576 CodeMirror.runMode($sql.text(), 'text/x-mysql', $highlight[0]);
1578 $highlight.find('.cm-keyword').each(PMA_doc_keyword);
1579 $highlight.find('.cm-builtin').each(PMA_doc_builtin);
1586 * Show a message on the top of the page for an Ajax request
1590 * 1) var $msg = PMA_ajaxShowMessage();
1591 * This will show a message that reads "Loading...". Such a message will not
1592 * disappear automatically and cannot be dismissed by the user. To remove this
1593 * message either the PMA_ajaxRemoveMessage($msg) function must be called or
1594 * another message must be show with PMA_ajaxShowMessage() function.
1596 * 2) var $msg = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
1597 * This is a special case. The behaviour is same as above,
1598 * just with a different message
1600 * 3) var $msg = PMA_ajaxShowMessage('The operation was successful');
1601 * This will show a message that will disappear automatically and it can also
1602 * be dismissed by the user.
1604 * 4) var $msg = PMA_ajaxShowMessage('Some error', false);
1605 * This will show a message that will not disappear automatically, but it
1606 * can be dismissed by the user after he has finished reading it.
1608 * @param string message string containing the message to be shown.
1609 * optional, defaults to 'Loading...'
1610 * @param mixed timeout number of milliseconds for the message to be visible
1611 * optional, defaults to 5000. If set to 'false', the
1612 * notification will never disappear
1613 * @return jQuery object jQuery Element that holds the message div
1614 * this object can be passed to PMA_ajaxRemoveMessage()
1615 * to remove the notification
1617 function PMA_ajaxShowMessage(message, timeout)
1620 * @var self_closing Whether the notification will automatically disappear
1622 var self_closing = true;
1624 * @var dismissable Whether the user will be able to remove
1625 * the notification by clicking on it
1627 var dismissable = true;
1628 // Handle the case when a empty data.message is passed.
1629 // We don't want the empty message
1630 if (message === '') {
1632 } else if (! message) {
1633 // If the message is undefined, show the default
1634 message = PMA_messages.strLoading;
1635 dismissable = false;
1636 self_closing = false;
1637 } else if (message == PMA_messages.strProcessingRequest) {
1638 // This is another case where the message should not disappear
1639 dismissable = false;
1640 self_closing = false;
1642 // Figure out whether (or after how long) to remove the notification
1643 if (timeout === undefined) {
1645 } else if (timeout === false) {
1646 self_closing = false;
1648 // Create a parent element for the AJAX messages, if necessary
1649 if ($('#loading_parent').length === 0) {
1650 $('<div id="loading_parent"></div>')
1653 // Update message count to create distinct message elements every time
1654 ajax_message_count++;
1655 // Remove all old messages, if any
1656 $("span.ajax_notification[id^=ajax_message_num]").remove();
1658 * @var $retval a jQuery object containing the reference
1659 * to the created AJAX message
1662 '<span class="ajax_notification" id="ajax_message_num_' +
1663 ajax_message_count +
1667 .appendTo("#loading_parent")
1670 // If the notification is self-closing we should create a callback to remove it
1674 .fadeOut('medium', function () {
1675 if ($(this).is('.dismissable')) {
1676 $(this).tooltip('destroy');
1678 // Remove the notification
1682 // If the notification is dismissable we need to add the relevant class to it
1683 // and add a tooltip so that the users know that it can be removed
1685 $retval.addClass('dismissable').css('cursor', 'pointer');
1687 * Add a tooltip to the notification to let the user know that (s)he
1688 * can dismiss the ajax notification by clicking on it.
1693 PMA_messages.strDismiss
1696 PMA_highlightSQL($retval);
1702 * Removes the message shown for an Ajax operation when it's completed
1704 * @param jQuery object jQuery Element that holds the notification
1708 function PMA_ajaxRemoveMessage($this_msgbox)
1710 if ($this_msgbox !== undefined && $this_msgbox instanceof jQuery) {
1714 if ($this_msgbox.is('.dismissable')) {
1715 if ($.isFunction($this_msgbox.tooltip)) {
1716 $this_msgbox.tooltip('destroy');
1719 $this_msgbox.remove();
1724 // This event only need to be fired once after the initial page load
1727 * Allows the user to dismiss a notification
1728 * created with PMA_ajaxShowMessage()
1730 $('span.ajax_notification.dismissable').live('click', function () {
1731 PMA_ajaxRemoveMessage($(this));
1734 * The below two functions hide the "Dismiss notification" tooltip when a user
1735 * is hovering a link or button that is inside an ajax message
1737 $('span.ajax_notification a, span.ajax_notification button, span.ajax_notification input')
1738 .live('mouseover', function () {
1739 $(this).parents('span.ajax_notification').tooltip('disable');
1741 .live('mouseout', function () {
1742 $(this).parents('span.ajax_notification').tooltip('enable');
1747 * Hides/shows the "Open in ENUM/SET editor" message, depending on the data type of the column currently selected
1749 function PMA_showNoticeForEnum(selectElement)
1751 var enum_notice_id = selectElement.attr("id").split("_")[1];
1752 enum_notice_id += "_" + (parseInt(selectElement.attr("id").split("_")[2], 10) + 1);
1753 var selectedType = selectElement.val();
1754 if (selectedType == "ENUM" || selectedType == "SET") {
1755 $("p#enum_notice_" + enum_notice_id).show();
1757 $("p#enum_notice_" + enum_notice_id).hide();
1762 * Creates a Profiling Chart with jqplot. Used in sql.js
1763 * and in server_status_monitor.js
1765 function PMA_createProfilingChartJqplot(target, data)
1767 return $.jqplot(target, [data],
1770 renderer: $.jqplot.PieRenderer,
1772 showDataLabels: true
1777 tooltipLocation: 'se',
1779 tooltipAxes: 'pieref',
1780 useAxesFormatters: false,
1781 formatString: '%s, %.9Ps'
1787 // from http://tango.freedesktop.org/Tango_Icon_Theme_Guidelines#Color_Palette
1813 * Formats a profiling duration nicely (in us and ms time).
1814 * Used in server_status_monitor.js
1816 * @param integer Number to be formatted, should be in the range of microsecond to second
1817 * @param integer Accuracy, how many numbers right to the comma should be
1818 * @return string The formatted number
1820 function PMA_prettyProfilingNum(num, acc)
1825 acc = Math.pow(10, acc);
1826 if (num * 1000 < 0.1) {
1827 num = Math.round(acc * (num * 1000 * 1000)) / acc + 'µ';
1828 } else if (num < 0.1) {
1829 num = Math.round(acc * (num * 1000)) / acc + 'm';
1831 num = Math.round(acc * num) / acc;
1839 * Formats a SQL Query nicely with newlines and indentation. Depends on Codemirror and MySQL Mode!
1841 * @param string Query to be formatted
1842 * @return string The formatted query
1844 function PMA_SQLPrettyPrint(string)
1846 if (typeof CodeMirror == 'undefined') {
1850 var mode = CodeMirror.getMode({}, "text/x-mysql");
1851 var stream = new CodeMirror.StringStream(string);
1852 var state = mode.startState();
1853 var token, tokens = [];
1855 var tabs = function (cnt) {
1857 for (var i = 0; i < 4 * cnt; i++) {
1863 // "root-level" statements
1865 'select': ['select', 'from', 'on', 'where', 'having', 'limit', 'order by', 'group by'],
1866 'update': ['update', 'set', 'where'],
1867 'insert into': ['insert into', 'values']
1869 // don't put spaces before these tokens
1870 var spaceExceptionsBefore = {';': true, ',': true, '.': true, '(': true};
1871 // don't put spaces after these tokens
1872 var spaceExceptionsAfter = {'.': true};
1874 // Populate tokens array
1876 while (! stream.eol()) {
1877 stream.start = stream.pos;
1878 token = mode.token(stream, state);
1879 if (token !== null) {
1880 tokens.push([token, stream.current().toLowerCase()]);
1884 var currentStatement = tokens[0][1];
1886 if (! statements[currentStatement]) {
1889 // Holds all currently opened code blocks (statement, function or generic)
1890 var blockStack = [];
1891 // Holds the type of block from last iteration (the current is in blockStack[0])
1893 // If a new code block is found, newBlock contains its type for one iteration and vice versa for endBlock
1894 var newBlock, endBlock;
1895 // How much to indent in the current line
1896 var indentLevel = 0;
1897 // Holds the "root-level" statements
1898 var statementPart, lastStatementPart = statements[currentStatement][0];
1900 blockStack.unshift('statement');
1902 // Iterate through every token and format accordingly
1903 for (var i = 0; i < tokens.length; i++) {
1904 previousBlock = blockStack[0];
1906 // New block => push to stack
1907 if (tokens[i][1] == '(') {
1908 if (i < tokens.length - 1 && tokens[i + 1][0] == 'statement-verb') {
1909 blockStack.unshift(newBlock = 'statement');
1910 } else if (i > 0 && tokens[i - 1][0] == 'builtin') {
1911 blockStack.unshift(newBlock = 'function');
1913 blockStack.unshift(newBlock = 'generic');
1919 // Block end => pop from stack
1920 if (tokens[i][1] == ')') {
1921 endBlock = blockStack[0];
1927 // A subquery is starting
1928 if (i > 0 && newBlock == 'statement') {
1930 output += "\n" + tabs(indentLevel) + tokens[i][1] + ' ' + tokens[i + 1][1].toUpperCase() + "\n" + tabs(indentLevel + 1);
1931 currentStatement = tokens[i + 1][1];
1936 // A subquery is ending
1937 if (endBlock == 'statement' && indentLevel > 0) {
1938 output += "\n" + tabs(indentLevel);
1942 // One less indentation for statement parts (from, where, order by, etc.) and a newline
1943 statementPart = statements[currentStatement].indexOf(tokens[i][1]);
1944 if (statementPart != -1) {
1948 output += tabs(indentLevel) + tokens[i][1].toUpperCase();
1949 output += "\n" + tabs(indentLevel + 1);
1950 lastStatementPart = tokens[i][1];
1952 // Normal indentatin and spaces for everything else
1954 if (! spaceExceptionsBefore[tokens[i][1]] &&
1955 ! (i > 0 && spaceExceptionsAfter[tokens[i - 1][1]]) &&
1956 output.charAt(output.length - 1) != ' ') {
1959 if (tokens[i][0] == 'keyword') {
1960 output += tokens[i][1].toUpperCase();
1962 output += tokens[i][1];
1966 // split columns in select and 'update set' clauses, but only inside statements blocks
1967 if ((lastStatementPart == 'select' || lastStatementPart == 'where' || lastStatementPart == 'set') &&
1968 tokens[i][1] == ',' && blockStack[0] == 'statement') {
1970 output += "\n" + tabs(indentLevel + 1);
1973 // split conditions in where clauses, but only inside statements blocks
1974 if (lastStatementPart == 'where' &&
1975 (tokens[i][1] == 'and' || tokens[i][1] == 'or' || tokens[i][1] == 'xor')) {
1977 if (blockStack[0] == 'statement') {
1978 output += "\n" + tabs(indentLevel + 1);
1980 // Todo: Also split and or blocks in newlines & identation++
1981 //if (blockStack[0] == 'generic')
1989 * jQuery function that uses jQueryUI's dialogs to confirm with user. Does not
1990 * return a jQuery object yet and hence cannot be chained
1992 * @param string question
1993 * @param string url URL to be passed to the callbackFn to make
1995 * @param function callbackFn callback to execute after user clicks on OK
1998 jQuery.fn.PMA_confirm = function (question, url, callbackFn) {
1999 var confirmState = PMA_commonParams.get('confirm');
2000 // when the Confirm directive is set to false in config.inc.php
2001 // and not changed in user prefs, confirmState is ""
2002 // when it's unticked in user prefs, confirmState is 1
2003 if (confirmState === "" || confirmState === "1") {
2004 // user does not want to confirm
2005 if ($.isFunction(callbackFn)) {
2006 callbackFn.call(this, url);
2010 if (PMA_messages.strDoYouReally === '') {
2015 * @var button_options Object that stores the options passed to jQueryUI
2018 var button_options = {};
2019 button_options[PMA_messages.strOK] = function () {
2020 $(this).dialog("close");
2022 if ($.isFunction(callbackFn)) {
2023 callbackFn.call(this, url);
2026 button_options[PMA_messages.strCancel] = function () {
2027 $(this).dialog("close");
2030 $('<div/>', {'id': 'confirm_dialog'})
2033 buttons: button_options,
2034 close: function () {
2042 * jQuery function to sort a table's body after a new row has been appended to it.
2043 * Also fixes the even/odd classes of the table rows at the end.
2045 * @param string text_selector string to select the sortKey's text
2047 * @return jQuery Object for chaining purposes
2049 jQuery.fn.PMA_sort_table = function (text_selector) {
2050 return this.each(function () {
2053 * @var table_body Object referring to the table's <tbody> element
2055 var table_body = $(this);
2057 * @var rows Object referring to the collection of rows in {@link table_body}
2059 var rows = $(this).find('tr').get();
2061 //get the text of the field that we will sort by
2062 $.each(rows, function (index, row) {
2063 row.sortKey = $.trim($(row).find(text_selector).text().toLowerCase());
2066 //get the sorted order
2067 rows.sort(function (a, b) {
2068 if (a.sortKey < b.sortKey) {
2071 if (a.sortKey > b.sortKey) {
2077 //pull out each row from the table and then append it according to it's order
2078 $.each(rows, function (index, row) {
2079 $(table_body).append(row);
2083 //Re-check the classes of each row
2084 $(this).find('tr:odd')
2085 .removeClass('even').addClass('odd')
2088 .removeClass('odd').addClass('even');
2093 * Unbind all event handlers before tearing down a page
2095 AJAX.registerTeardown('functions.js', function () {
2096 $("#create_table_form_minimal.ajax").die('submit');
2097 $("form.create_table_form.ajax").die('submit');
2098 $("form.create_table_form.ajax input[name=submit_num_fields]").die('click');
2099 $("form.create_table_form.ajax input").die('keyup');
2103 * jQuery coding for 'Create Table'. Used on db_operations.php,
2104 * db_structure.php and db_tracking.php (i.e., wherever
2105 * libraries/display_create_table.lib.php is used)
2107 * Attach Ajax Event handlers for Create Table
2109 AJAX.registerOnload('functions.js', function () {
2111 * Attach event handler for submission of create table form (save)
2113 $("form.create_table_form.ajax").live('submit', function (event) {
2114 event.preventDefault();
2117 * @var the_form object referring to the create table form
2119 var $form = $(this);
2122 * First validate the form; if there is a problem, avoid submitting it
2124 * checkTableEditForm() needs a pure element and not a jQuery object,
2125 * this is why we pass $form[0] as a parameter (the jQuery object
2126 * is actually an array of DOM elements)
2129 if (checkTableEditForm($form[0], $form.find('input[name=orig_num_fields]').val())) {
2130 PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
2131 PMA_prepareForAjaxRequest($form);
2132 //User wants to submit the form
2133 $.post($form.attr('action'), $form.serialize() + "&do_save_data=1", function (data) {
2134 if (data.success === true) {
2135 $('#properties_message')
2136 .removeClass('error')
2138 PMA_ajaxShowMessage(data.message);
2139 // Only if the create table dialog (distinct panel) exists
2140 if ($("#create_table_dialog").length > 0) {
2141 $("#create_table_dialog").dialog("close").remove();
2143 $('#tableslistcontainer').before(data.formatted_sql);
2146 * @var tables_table Object referring to the <tbody> element that holds the list of tables
2148 var tables_table = $("#tablesForm").find("tbody").not("#tbl_summary_row");
2149 // this is the first table created in this db
2150 if (tables_table.length === 0) {
2151 PMA_commonActions.refreshMain(
2152 PMA_commonParams.get('opendb_url')
2156 * @var curr_last_row Object referring to the last <tr> element in {@link tables_table}
2158 var curr_last_row = $(tables_table).find('tr:last');
2160 * @var curr_last_row_index_string String containing the index of {@link curr_last_row}
2162 var curr_last_row_index_string = $(curr_last_row).find('input:checkbox').attr('id').match(/\d+/)[0];
2164 * @var curr_last_row_index Index of {@link curr_last_row}
2166 var curr_last_row_index = parseFloat(curr_last_row_index_string);
2168 * @var new_last_row_index Index of the new row to be appended to {@link tables_table}
2170 var new_last_row_index = curr_last_row_index + 1;
2172 * @var new_last_row_id String containing the id of the row to be appended to {@link tables_table}
2174 var new_last_row_id = 'checkbox_tbl_' + new_last_row_index;
2176 data.new_table_string = data.new_table_string.replace(/checkbox_tbl_/, new_last_row_id);
2178 $(data.new_table_string)
2179 .appendTo(tables_table);
2182 $(tables_table).PMA_sort_table('th');
2184 // Adjust summary row
2188 //Refresh navigation as a new table has been added
2189 PMA_reloadNavigation();
2191 PMA_ajaxShowMessage(
2192 '<div class="error">' + data.error + '</div>',
2197 } // end if (checkTableEditForm() )
2198 }); // end create table form (save)
2201 * Attach event handler for create table form (add fields)
2203 $("form.create_table_form.ajax input[name=submit_num_fields]").live('click', function (event) {
2204 event.preventDefault();
2206 * @var the_form object referring to the create table form
2208 var $form = $(this).closest('form');
2210 var $msgbox = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
2211 PMA_prepareForAjaxRequest($form);
2213 //User wants to add more fields to the table
2214 $.post($form.attr('action'), $form.serialize() + "&submit_num_fields=1", function (data) {
2216 $("#page_content").html(data.message);
2217 PMA_highlightSQL($('#page_content'));
2218 PMA_verifyColumnsProperties();
2219 PMA_ajaxRemoveMessage($msgbox);
2221 PMA_ajaxShowMessage(data.error);
2224 }); // end create table form (add fields)
2226 $("form.create_table_form.ajax input").live('keydown', function (event) {
2227 if (event.keyCode == 13) {
2228 event.preventDefault();
2229 event.stopImmediatePropagation();
2232 .append('<input type="hidden" name="do_save_data" value="1" />')
2240 * Unbind all event handlers before tearing down a page
2242 AJAX.registerTeardown('functions.js', function () {
2243 $("#copyTable.ajax").die('submit');
2244 $("#moveTableForm").die('submit');
2245 $("#tableOptionsForm").die('submit');
2246 $("#tbl_maintenance li a.maintain_action.ajax").die('click');
2249 * jQuery coding for 'Table operations'. Used on tbl_operations.php
2250 * Attach Ajax Event handlers for Table operations
2252 AJAX.registerOnload('functions.js', function () {
2254 *Ajax action for submitting the "Copy table"
2256 $("#copyTable.ajax").live('submit', function (event) {
2257 event.preventDefault();
2258 var $form = $(this);
2259 PMA_prepareForAjaxRequest($form);
2260 $.post($form.attr('action'), $form.serialize() + "&submit_copy=Go", function (data) {
2261 if (data.success === true) {
2262 if ($form.find("input[name='switch_to_new']").prop('checked')) {
2263 PMA_commonParams.set(
2267 PMA_commonParams.set(
2269 $form.find("input[name='new_name']").val()
2271 PMA_commonActions.refreshMain(false, function () {
2272 PMA_ajaxShowMessage(data.message);
2275 PMA_ajaxShowMessage(data.message);
2277 // Refresh navigation when the table is copied
2278 PMA_reloadNavigation();
2280 PMA_ajaxShowMessage(data.error, false);
2283 });//end of copyTable ajax submit
2286 *Ajax action for submitting the "Move table"
2288 $("#moveTableForm").live('submit', function (event) {
2289 event.preventDefault();
2290 var $form = $(this);
2291 var db = $form.find('select[name=target_db]').val();
2292 var tbl = $form.find('input[name=new_name]').val();
2293 PMA_prepareForAjaxRequest($form);
2294 $.post($form.attr('action'), $form.serialize() + "&submit_move=1", function (data) {
2295 if (data.success === true) {
2296 PMA_commonParams.set('db', db);
2297 PMA_commonParams.set('table', tbl);
2298 PMA_commonActions.refreshMain(false, function () {
2299 PMA_ajaxShowMessage(data.message);
2301 // Refresh navigation when the table is copied
2302 PMA_reloadNavigation();
2304 PMA_ajaxShowMessage(data.error, false);
2310 * Ajax action for submitting the "Table options"
2312 $("#tableOptionsForm").live('submit', function (event) {
2313 event.preventDefault();
2314 event.stopPropagation();
2315 var $form = $(this);
2316 var $tblNameField = $form.find('input[name=new_name]');
2317 if ($tblNameField.val() !== $tblNameField[0].defaultValue) {
2318 // reload page and navigation if the table has been renamed
2319 PMA_prepareForAjaxRequest($form);
2320 var tbl = $tblNameField.val();
2321 $.post($form.attr('action'), $form.serialize(), function (data) {
2322 if (data.success === true) {
2323 PMA_commonParams.set('table', tbl);
2324 PMA_commonActions.refreshMain(false, function () {
2325 $('#page_content').html(data.message);
2326 PMA_highlightSQL($('#page_content'));
2329 PMA_ajaxShowMessage(data.error, false);
2333 $form.removeClass('ajax').submit().addClass('ajax');
2338 *Ajax events for actions in the "Table maintenance"
2340 $("#tbl_maintenance li a.maintain_action.ajax").live('click', function (event) {
2341 event.preventDefault();
2342 if ($("#sqlqueryresults").length !== 0) {
2343 $("#sqlqueryresults").remove();
2345 if ($("#result_query").length !== 0) {
2346 $("#result_query").remove();
2348 //variables which stores the common attributes
2349 $.post($(this).attr('href'), { ajax_request: 1 }, function (data) {
2350 function scrollToTop() {
2351 $('html, body').animate({ scrollTop: 0 });
2353 if (data.success === true && data.sql_query !== undefined) {
2354 PMA_ajaxShowMessage(data.message);
2355 $("<div id='sqlqueryresults' class='ajax'></div>").prependTo("#page_content");
2356 $("#sqlqueryresults").html(data.sql_query);
2357 PMA_highlightSQL($('#page_content'));
2359 } else if (data.success === true) {
2360 var $temp_div = $("<div id='temp_div'></div>");
2361 $temp_div.html(data.message);
2362 var $success = $temp_div.find("#result_query .success");
2363 PMA_ajaxShowMessage($success);
2364 $("<div id='sqlqueryresults' class='ajax'></div>").prependTo("#page_content");
2365 $("#sqlqueryresults").html(data.message);
2366 PMA_highlightSQL($('#page_content'));
2368 $("#sqlqueryresults").children("fieldset,br").remove();
2371 var $temp_div = $("<div id='temp_div'></div>");
2372 $temp_div.html(data.error);
2373 var $error = $temp_div.find("code").addClass("error");
2374 PMA_ajaxShowMessage($error, false);
2377 });//end of table maintanance ajax click
2378 }); //end $(document).ready for 'Table operations'
2381 * Unbind all event handlers before tearing down a page
2383 AJAX.registerTeardown('functions.js', function () {
2384 $("#drop_db_anchor.ajax").die('click');
2387 * Attach Ajax event handlers for Drop Database. Moved here from db_structure.js
2388 * as it was also required on db_create.php
2390 AJAX.registerOnload('functions.js', function () {
2391 $("#drop_db_anchor.ajax").live('click', function (event) {
2392 event.preventDefault();
2394 * @var question String containing the question to be asked for confirmation
2396 var question = PMA_messages.strDropDatabaseStrongWarning + ' ';
2397 question += $.sprintf(
2398 PMA_messages.strDoYouReally,
2399 'DROP DATABASE ' + escapeHtml(PMA_commonParams.get('db'))
2401 $(this).PMA_confirm(question, $(this).attr('href'), function (url) {
2402 PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
2403 $.get(url, {'is_js_confirmed': '1', 'ajax_request': true}, function (data) {
2405 //Database deleted successfully, refresh both the frames
2406 PMA_reloadNavigation();
2407 PMA_commonParams.set('db', '');
2408 PMA_commonActions.refreshMain(
2409 'server_databases.php',
2411 PMA_ajaxShowMessage(data.message);
2415 PMA_ajaxShowMessage(data.error, false);
2420 }); // end of $() for Drop Database
2423 * Validates the password field in a form
2425 * @see PMA_messages.strPasswordEmpty
2426 * @see PMA_messages.strPasswordNotSame
2427 * @param object $the_form The form to be validated
2430 function PMA_checkPassword($the_form)
2432 // Did the user select 'no password'?
2433 if ($the_form.find('#nopass_1').is(':checked')) {
2436 var $pred = $the_form.find('#select_pred_password');
2437 if ($pred.length && ($pred.val() == 'none' || $pred.val() == 'keep')) {
2442 var $password = $the_form.find('input[name=pma_pw]');
2443 var $password_repeat = $the_form.find('input[name=pma_pw2]');
2444 var alert_msg = false;
2446 if ($password.val() === '') {
2447 alert_msg = PMA_messages.strPasswordEmpty;
2448 } else if ($password.val() != $password_repeat.val()) {
2449 alert_msg = PMA_messages.strPasswordNotSame;
2455 $password_repeat.val('');
2463 * Unbind all event handlers before tearing down a page
2465 AJAX.registerTeardown('functions.js', function () {
2466 $('#change_password_anchor.ajax').die('click');
2469 * Attach Ajax event handlers for 'Change Password' on index.php
2471 AJAX.registerOnload('functions.js', function () {
2474 * Attach Ajax event handler on the change password anchor
2476 $('#change_password_anchor.ajax').live('click', function (event) {
2477 event.preventDefault();
2479 var $msgbox = PMA_ajaxShowMessage();
2482 * @var button_options Object containing options to be passed to jQueryUI's dialog
2484 var button_options = {};
2485 button_options[PMA_messages.strGo] = function () {
2487 event.preventDefault();
2490 * @var $the_form Object referring to the change password form
2492 var $the_form = $("#change_password_form");
2494 if (! PMA_checkPassword($the_form)) {
2499 * @var this_value String containing the value of the submit button.
2500 * Need to append this for the change password form on Server Privileges
2503 var this_value = $(this).val();
2505 var $msgbox = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
2506 $the_form.append('<input type="hidden" name="ajax_request" value="true" />');
2508 $.post($the_form.attr('action'), $the_form.serialize() + '&change_pw=' + this_value, function (data) {
2509 if (data.success === true) {
2510 $("#page_content").prepend(data.message);
2511 PMA_highlightSQL($('#page_content'));
2512 $("#change_password_dialog").hide().remove();
2513 $("#edit_user_dialog").dialog("close").remove();
2514 PMA_ajaxRemoveMessage($msgbox);
2517 PMA_ajaxShowMessage(data.error, false);
2522 button_options[PMA_messages.strCancel] = function () {
2523 $(this).dialog('close');
2525 $.get($(this).attr('href'), {'ajax_request': true}, function (data) {
2527 $('<div id="change_password_dialog"></div>')
2529 title: PMA_messages.strChangePassword,
2531 close: function (ev, ui) {
2534 buttons : button_options,
2537 .append(data.message);
2538 // for this dialog, we remove the fieldset wrapping due to double headings
2539 $("fieldset#fieldset_change_password")
2540 .find("legend").remove().end()
2541 .find("table.noclick").unwrap().addClass("some-margin")
2542 .find("input#text_pma_pw").focus();
2543 displayPasswordGenerateButton();
2544 $('#fieldset_change_password_footer').hide();
2545 PMA_ajaxRemoveMessage($msgbox);
2546 $('#change_password_form').bind('submit', function (e) {
2549 .closest('.ui-dialog')
2550 .find('.ui-dialog-buttonpane .ui-button')
2555 PMA_ajaxShowMessage(data.error, false);
2558 }); // end handler for change password anchor
2559 }); // end $() for Change Password
2562 * Unbind all event handlers before tearing down a page
2564 AJAX.registerTeardown('functions.js', function () {
2565 $("select.column_type").die('change');
2566 $("select.default_type").die('change');
2567 $('input.allow_null').die('change');
2570 * Toggle the hiding/showing of the "Open in ENUM/SET editor" message when
2571 * the page loads and when the selected data type changes
2573 AJAX.registerOnload('functions.js', function () {
2574 // is called here for normal page loads and also when opening
2575 // the Create table dialog
2576 PMA_verifyColumnsProperties();
2578 // needs live() to work also in the Create Table dialog
2579 $("select.column_type").live('change', function () {
2580 PMA_showNoticeForEnum($(this));
2582 $("select.default_type").live('change', function () {
2583 PMA_hideShowDefaultValue($(this));
2585 $('input.allow_null').live('change', function () {
2586 PMA_validateDefaultValue($(this));
2590 function PMA_verifyColumnsProperties()
2592 $("select.column_type").each(function () {
2593 PMA_showNoticeForEnum($(this));
2595 $("select.default_type").each(function () {
2596 PMA_hideShowDefaultValue($(this));
2601 * Hides/shows the default value input field, depending on the default type
2602 * Ticks the NULL checkbox if NULL is chosen as default value.
2604 function PMA_hideShowDefaultValue($default_type)
2606 if ($default_type.val() == 'USER_DEFINED') {
2607 $default_type.siblings('.default_value').show().focus();
2609 $default_type.siblings('.default_value').hide();
2610 if ($default_type.val() == 'NULL') {
2611 var $null_checkbox = $default_type.closest('tr').find('.allow_null');
2612 $null_checkbox.prop('checked', true);
2618 * If the column does not allow NULL values, makes sure that default is not NULL
2620 function PMA_validateDefaultValue($null_checkbox)
2622 if (! $null_checkbox.prop('checked')) {
2623 var $default = $null_checkbox.closest('tr').find('.default_type');
2624 if ($default.val() == 'NULL') {
2625 $default.val('NONE');
2632 * Unbind all event handlers before tearing down a page
2634 AJAX.registerTeardown('functions.js', function () {
2635 $("a.open_enum_editor").die('click');
2636 $("input.add_value").die('click');
2637 $("#enum_editor td.drop").die('click');
2640 * @var $enum_editor_dialog An object that points to the jQuery
2641 * dialog of the ENUM/SET editor
2643 var $enum_editor_dialog = null;
2645 * Opens the ENUM/SET editor and controls its functions
2647 AJAX.registerOnload('functions.js', function () {
2648 $("a.open_enum_editor").live('click', function () {
2649 // Get the name of the column that is being edited
2650 var colname = $(this).closest('tr').find('input:first').val();
2653 // And use it to make up a title for the page
2654 if (colname.length < 1) {
2655 title = PMA_messages.enum_newColumnVals;
2657 title = PMA_messages.enum_columnVals.replace(
2659 '"' + decodeURIComponent(colname) + '"'
2662 // Get the values as a string
2663 var inputstring = $(this)
2667 // Escape html entities
2668 inputstring = $('<div/>')
2671 // Parse the values, escaping quotes and
2672 // slashes on the fly, into an array
2674 var in_string = false;
2675 var curr, next, buffer = '';
2676 for (i = 0; i < inputstring.length; i++) {
2677 curr = inputstring.charAt(i);
2678 next = i == inputstring.length ? '' : inputstring.charAt(i + 1);
2679 if (! in_string && curr == "'") {
2681 } else if (in_string && curr == "\\" && next == "\\") {
2684 } else if (in_string && next == "'" && (curr == "'" || curr == "\\")) {
2687 } else if (in_string && curr == "'") {
2689 values.push(buffer);
2691 } else if (in_string) {
2695 if (buffer.length > 0) {
2696 // The leftovers in the buffer are the last value (if any)
2697 values.push(buffer);
2700 // If there are no values, maybe the user is about to make a
2701 // new list so we add a few for him/her to get started with.
2702 if (values.length === 0) {
2703 values.push('', '', '', '');
2705 // Add the parsed values to the editor
2706 var drop_icon = PMA_getImage('b_drop.png');
2707 for (i = 0; i < values.length; i++) {
2708 fields += "<tr><td>" +
2709 "<input type='text' value='" + values[i] + "'/>" +
2710 "</td><td class='drop'>" +
2715 * @var dialog HTML code for the ENUM/SET dialog
2717 var dialog = "<div id='enum_editor'>" +
2719 "<legend>" + title + "</legend>" +
2720 "<p>" + PMA_getImage('s_notice.png') +
2721 PMA_messages.enum_hint + "</p>" +
2722 "<table class='values'>" + fields + "</table>" +
2723 "</fieldset><fieldset class='tblFooters'>" +
2724 "<table class='add'><tr><td>" +
2725 "<div class='slider'></div>" +
2727 "<form><div><input type='submit' class='add_value' value='" +
2728 $.sprintf(PMA_messages.enum_addValue, 1) +
2729 "'/></div></form>" +
2730 "</td></tr></table>" +
2731 "<input type='hidden' value='" + // So we know which column's data is being edited
2732 $(this).closest('td').find("input").attr("id") +
2737 * @var Defines functions to be called when the buttons in
2738 * the buttonOptions jQuery dialog bar are pressed
2740 var buttonOptions = {};
2741 buttonOptions[PMA_messages.strGo] = function () {
2742 // When the submit button is clicked,
2743 // put the data back into the original form
2744 var value_array = [];
2745 $(this).find(".values input").each(function (index, elm) {
2746 var val = elm.value.replace(/\\/g, '\\\\').replace(/'/g, "''");
2747 value_array.push("'" + val + "'");
2749 // get the Length/Values text field where this value belongs
2750 var values_id = $(this).find("input[type='hidden']").val();
2751 $("input#" + values_id).val(value_array.join(","));
2752 $(this).dialog("close");
2754 buttonOptions[PMA_messages.strClose] = function () {
2755 $(this).dialog("close");
2758 var width = parseInt(
2759 (parseInt($('html').css('font-size'), 10) / 13) * 340,
2765 $enum_editor_dialog = $(dialog).dialog({
2768 title: PMA_messages.enum_editor,
2769 buttons: buttonOptions,
2771 // Focus the "Go" button after opening the dialog
2772 $(this).closest('.ui-dialog').find('.ui-dialog-buttonpane button:first').focus();
2774 close: function () {
2778 // slider for choosing how many fields to add
2779 $enum_editor_dialog.find(".slider").slider({
2785 slide: function (event, ui) {
2786 $(this).closest('table').find('input[type=submit]').val(
2787 $.sprintf(PMA_messages.enum_addValue, ui.value)
2791 // Focus the slider, otherwise it looks nearly transparent
2792 $('a.ui-slider-handle').addClass('ui-state-focus');
2796 // When "add a new value" is clicked, append an empty text field
2797 $("input.add_value").live('click', function (e) {
2799 var num_new_rows = $enum_editor_dialog.find("div.slider").slider('value');
2800 while (num_new_rows--) {
2801 $enum_editor_dialog.find('.values')
2803 "<tr style='display: none;'><td>" +
2804 "<input type='text' />" +
2805 "</td><td class='drop'>" +
2806 PMA_getImage('b_drop.png') +
2814 // Removes the specified row from the enum editor
2815 $("#enum_editor td.drop").live('click', function () {
2816 $(this).closest('tr').hide('fast', function () {
2823 * Ensures indexes names are valid according to their type and, for a primary
2824 * key, lock index name to 'PRIMARY'
2825 * @param string form_id Variable which parses the form name as
2827 * @return boolean false if there is no index form, true else
2829 function checkIndexName(form_id)
2831 if ($("#" + form_id).length === 0) {
2835 // Gets the elements pointers
2836 var $the_idx_name = $("#input_index_name");
2837 var $the_idx_type = $("#select_index_type");
2839 // Index is a primary key
2840 if ($the_idx_type.find("option:selected").val() == 'PRIMARY') {
2841 $the_idx_name.val('PRIMARY');
2842 $the_idx_name.prop("disabled", true);
2847 if ($the_idx_name.val() == 'PRIMARY') {
2848 $the_idx_name.val("");
2850 $the_idx_name.prop("disabled", false);
2854 } // end of the 'checkIndexName()' function
2856 AJAX.registerTeardown('functions.js', function () {
2857 $('#index_frm input[type=submit]').die('click');
2859 AJAX.registerOnload('functions.js', function () {
2861 * Handler for adding more columns to an index in the editor
2863 $('#index_frm input[type=submit]').live('click', function (event) {
2864 event.preventDefault();
2865 var rows_to_add = $(this)
2866 .closest('fieldset')
2869 while (rows_to_add--) {
2870 var $newrow = $('#index_columns')
2871 .find('tbody > tr:first')
2874 $('#index_columns').find('tbody')
2876 $newrow.find(':input').each(function () {
2879 // focus index size input on column picked
2880 $newrow.find('select').change(function () {
2881 if ($(this).find("option:selected").val() === '') {
2884 $(this).closest("tr").find("input").focus();
2890 function indexEditorDialog(url, title, callback_success, callback_failure)
2892 /*Remove the hidden dialogs if there are*/
2893 if ($('#edit_index_dialog').length !== 0) {
2894 $('#edit_index_dialog').remove();
2896 var $div = $('<div id="edit_index_dialog"></div>');
2899 * @var button_options Object that stores the options
2900 * passed to jQueryUI dialog
2902 var button_options = {};
2903 button_options[PMA_messages.strGo] = function () {
2905 * @var the_form object referring to the export form
2907 var $form = $("#index_frm");
2908 var $msgbox = PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
2909 PMA_prepareForAjaxRequest($form);
2910 //User wants to submit the form
2911 $.post($form.attr('action'), $form.serialize() + "&do_save_data=1", function (data) {
2912 if ($("#sqlqueryresults").length !== 0) {
2913 $("#sqlqueryresults").remove();
2915 if (data.success === true) {
2916 PMA_ajaxShowMessage(data.message);
2917 if ($('#result_query').length) {
2918 $('#result_query').remove();
2920 if (data.sql_query) {
2921 $('<div id="result_query"></div>')
2922 .html(data.sql_query)
2923 .prependTo('#page_content');
2924 PMA_highlightSQL($('#page_content'));
2926 $("#result_query .notice").remove();
2927 $("#result_query").prepend(data.message);
2928 /*Reload the field form*/
2929 $("#table_index").remove();
2930 var $temp_div = $("<div id='temp_div'><div>").append(data.index_table);
2931 $temp_div.find("#table_index").insertAfter("#index_header");
2932 if ($("#edit_index_dialog").length > 0) {
2933 $("#edit_index_dialog").dialog("close");
2935 $('div.no_indexes_defined').hide();
2936 if (callback_success) {
2939 PMA_reloadNavigation();
2941 var $temp_div = $("<div id='temp_div'><div>").append(data.error);
2943 if ($temp_div.find(".error code").length !== 0) {
2944 $error = $temp_div.find(".error code").addClass("error");
2948 if (callback_failure) {
2951 PMA_ajaxShowMessage($error, false);
2955 button_options[PMA_messages.strCancel] = function () {
2956 $(this).dialog('close');
2958 var $msgbox = PMA_ajaxShowMessage();
2959 $.get("tbl_indexes.php", url, function (data) {
2960 if (data.success === false) {
2961 //in the case of an error, show the error message returned.
2962 PMA_ajaxShowMessage(data.error, false);
2964 PMA_ajaxRemoveMessage($msgbox);
2965 // Show dialog if the request was successful
2967 .append(data.message)
2971 open: PMA_verifyColumnsProperties,
2973 buttons: button_options,
2974 close: function () {
2979 checkIndexName("index_frm");
2980 PMA_showHints($div);
2981 // Add a slider for selecting how many columns to add to the index
2982 $div.find('.slider').slider({
2987 slide: function (event, ui) {
2988 $(this).closest('fieldset').find('input[type=submit]').val(
2989 $.sprintf(PMA_messages.strAddToIndex, ui.value)
2993 // focus index size input on column picked
2994 $div.find('table#index_columns select').change(function () {
2995 if ($(this).find("option:selected").val() === '') {
2998 $(this).closest("tr").find("input").focus();
3000 // Focus the slider, otherwise it looks nearly transparent
3001 $('a.ui-slider-handle').addClass('ui-state-focus');
3002 // set focus on index name input, if empty
3003 var input = $div.find('input#input_index_name');
3004 input.val() || input.focus();
3010 * Function to display tooltips that were
3011 * generated on the PHP side by PMA_Util::showHint()
3013 * @param object $div a div jquery object which specifies the
3014 * domain for searching for tooltips. If we
3015 * omit this parameter the function searches
3018 function PMA_showHints($div)
3020 if ($div === undefined || ! $div instanceof jQuery || $div.length === 0) {
3023 $div.find('.pma_hint').each(function () {
3025 $(this).children('img'),
3027 $(this).children('span').html()
3032 AJAX.registerOnload('functions.js', function () {
3036 function PMA_mainMenuResizerCallback() {
3037 // 5 px margin for jumping menu in Chrome
3038 return $(document.body).width() - 5;
3040 // This must be fired only once after the inital page load
3042 // Initialise the menu resize plugin
3043 $('#topmenu').menuResizer(PMA_mainMenuResizerCallback);
3044 // register resize event
3045 $(window).resize(function () {
3046 $('#topmenu').menuResizer('resize');
3051 * Get the row number from the classlist (for example, row_1)
3053 function PMA_getRowNumber(classlist)
3055 return parseInt(classlist.split(/\s+row_/)[1], 10);
3059 * Changes status of slider
3061 function PMA_set_status_label($element)
3064 if ($element.css('display') == 'none') {
3069 $element.closest('.slide-wrapper').prev().find('span').text(text);
3073 * var toggleButton This is a function that creates a toggle
3074 * sliding button given a jQuery reference
3075 * to the correct DOM element
3077 var toggleButton = function ($obj) {
3078 // In rtl mode the toggle switch is flipped horizontally
3079 // so we need to take that into account
3081 if ($('span.text_direction', $obj).text() == 'ltr') {
3087 * var h Height of the button, used to scale the
3088 * background image and position the layers
3090 var h = $obj.height();
3091 $('img', $obj).height(h);
3092 $('table', $obj).css('bottom', h - 1);
3094 * var on Width of the "ON" part of the toggle switch
3095 * var off Width of the "OFF" part of the toggle switch
3097 var on = $('td.toggleOn', $obj).width();
3098 var off = $('td.toggleOff', $obj).width();
3099 // Make the "ON" and "OFF" parts of the switch the same size
3100 // + 2 pixels to avoid overflowed
3101 $('td.toggleOn > div', $obj).width(Math.max(on, off) + 2);
3102 $('td.toggleOff > div', $obj).width(Math.max(on, off) + 2);
3104 * var w Width of the central part of the switch
3106 var w = parseInt(($('img', $obj).height() / 16) * 22, 10);
3107 // Resize the central part of the switch on the top
3108 // layer to match the background
3109 $('table td:nth-child(2) > div', $obj).width(w);
3111 * var imgw Width of the background image
3112 * var tblw Width of the foreground layer
3113 * var offset By how many pixels to move the background
3114 * image, so that it matches the top layer
3116 var imgw = $('img', $obj).width();
3117 var tblw = $('table', $obj).width();
3118 var offset = parseInt(((imgw - tblw) / 2), 10);
3119 // Move the background to match the layout of the top layer
3120 $obj.find('img').css(right, offset);
3122 * var offw Outer width of the "ON" part of the toggle switch
3123 * var btnw Outer width of the central part of the switch
3125 var offw = $('td.toggleOff', $obj).outerWidth();
3126 var btnw = $('table td:nth-child(2)', $obj).outerWidth();
3127 // Resize the main div so that exactly one side of
3128 // the switch plus the central part fit into it.
3129 $obj.width(offw + btnw + 2);
3131 * var move How many pixels to move the
3132 * switch by when toggling
3134 var move = $('td.toggleOff', $obj).outerWidth();
3135 // If the switch is initialized to the
3136 // OFF state we need to move it now.
3137 if ($('div.container', $obj).hasClass('off')) {
3138 if (right == 'right') {
3139 $('div.container', $obj).animate({'left': '-=' + move + 'px'}, 0);
3141 $('div.container', $obj).animate({'left': '+=' + move + 'px'}, 0);
3144 // Attach an 'onclick' event to the switch
3145 $('div.container', $obj).click(function () {
3146 if ($(this).hasClass('isActive')) {
3149 $(this).addClass('isActive');
3151 var $msg = PMA_ajaxShowMessage();
3152 var $container = $(this);
3153 var callback = $('span.callback', this).text();
3154 var operator, url, removeClass, addClass;
3155 // Perform the actual toggle
3156 if ($(this).hasClass('on')) {
3157 if (right == 'right') {
3162 url = $(this).find('td.toggleOff > span').text();
3166 if (right == 'right') {
3171 url = $(this).find('td.toggleOn > span').text();
3172 removeClass = 'off';
3175 $.post(url, {'ajax_request': true}, function (data) {
3176 if (data.success === true) {
3177 PMA_ajaxRemoveMessage($msg);
3179 .removeClass(removeClass)
3181 .animate({'left': operator + move + 'px'}, function () {
3182 $container.removeClass('isActive');
3186 PMA_ajaxShowMessage(data.error, false);
3187 $container.removeClass('isActive');
3194 * Unbind all event handlers before tearing down a page
3196 AJAX.registerTeardown('functions.js', function () {
3197 $('div.container').unbind('click');
3200 * Initialise all toggle buttons
3202 AJAX.registerOnload('functions.js', function () {
3203 $('div.toggleAjax').each(function () {
3204 var $button = $(this).show();
3205 $button.find('img').each(function () {
3206 if (this.complete) {
3207 toggleButton($button);
3209 $(this).load(function () {
3210 toggleButton($button);
3218 * Unbind all event handlers before tearing down a page
3220 AJAX.registerTeardown('functions.js', function () {
3221 $('.vpointer').die('hover');
3222 $('.vmarker').die('click');
3223 $('#pageselector').die('change');
3224 $('a.formLinkSubmit').die('click');
3225 $('#update_recent_tables').unbind('ready');
3230 AJAX.registerOnload('functions.js', function () {
3231 $('.vpointer').live('hover',
3234 var $this_td = $(this);
3235 var row_num = PMA_getRowNumber($this_td.attr('class'));
3236 // for all td of the same vertical row, toggle hover
3237 $('.vpointer').filter('.row_' + row_num).toggleClass('hover');
3245 $('.vmarker').live('click', function (e) {
3246 // do not trigger when clicked on anchor
3247 if ($(e.target).is('a, img, a *')) {
3251 var $this_td = $(this);
3252 var row_num = PMA_getRowNumber($this_td.attr('class'));
3254 // XXX: FF fires two click events for <label> (label and checkbox), so we need to handle this differently
3255 var $checkbox = $('.vmarker').filter('.row_' + row_num + ':first').find(':checkbox');
3256 if ($checkbox.length) {
3257 // checkbox in a row, add or remove class depending on checkbox state
3258 var checked = $checkbox.prop('checked');
3259 if (!$(e.target).is(':checkbox, label')) {
3261 $checkbox.prop('checked', checked);
3263 // for all td of the same vertical row, toggle the marked class
3265 $('.vmarker').filter('.row_' + row_num).addClass('marked');
3267 $('.vmarker').filter('.row_' + row_num).removeClass('marked');
3270 // normaln data table, just toggle class
3271 $('.vmarker').filter('.row_' + row_num).toggleClass('marked');
3276 * Autosubmit page selector
3278 $('select.pageselector').live('change', function (event) {
3279 event.stopPropagation();
3280 // Check where to load the new content
3281 if ($(this).closest("#pma_navigation").length === 0) {
3282 // For the main page we don't need to do anything,
3283 $(this).closest("form").submit();
3285 // but for the navigation we need to manually replace the content
3286 PMA_navigationTreePagination($(this));
3291 * Load version information asynchronously.
3293 if ($('li.jsversioncheck').length > 0) {
3294 $.getJSON('version_check.php', {}, PMA_current_version);
3297 if ($('#is_git_revision').length > 0) {
3298 setTimeout(PMA_display_git_revision, 10);
3307 * Enables the text generated by PMA_Util::linkOrButton() to be clickable
3309 $('a.formLinkSubmit').live('click', function (e) {
3311 if ($(this).attr('href').indexOf('=') != -1) {
3312 var data = $(this).attr('href').substr($(this).attr('href').indexOf('#') + 1).split('=', 2);
3313 $(this).parents('form').append('<input type="hidden" name="' + data[0] + '" value="' + data[1] + '"/>');
3315 $(this).parents('form').submit();
3319 if ($('#update_recent_tables').length) {
3321 $('#update_recent_tables').attr('href'),
3323 if (data.success === true) {
3324 $('#recentTable').html(data.options);
3334 * Initializes slider effect.
3336 function PMA_init_slider()
3338 $('div.pma_auto_slider').each(function () {
3339 var $this = $(this);
3340 if ($this.data('slider_init_done')) {
3343 var $wrapper = $('<div>', {'class': 'slide-wrapper'});
3344 $wrapper.toggle($this.is(':visible'));
3345 $('<a>', {href: '#' + this.id, "class": 'ajax'})
3347 .prepend($('<span>'))
3348 .insertBefore($this)
3349 .click(function () {
3350 var $wrapper = $this.closest('.slide-wrapper');
3351 var visible = $this.is(':visible');
3355 $this[visible ? 'hide' : 'show']('blind', function () {
3356 $wrapper.toggle(!visible);
3357 PMA_set_status_label($this);
3361 $this.wrap($wrapper);
3362 PMA_set_status_label($this);
3363 $this.data('slider_init_done', 1);
3368 * Initializes slider effect.
3370 AJAX.registerOnload('functions.js', function () {
3375 * Restores sliders to the state they were in before initialisation.
3377 AJAX.registerTeardown('functions.js', function () {
3378 $('div.pma_auto_slider').each(function () {
3379 var $this = $(this);
3381 $this.parent().replaceWith($this);
3382 $this.parent().children('a').remove();
3387 * Creates a message inside an object with a sliding effect
3389 * @param msg A string containing the text to display
3390 * @param $obj a jQuery object containing the reference
3391 * to the element where to put the message
3392 * This is optional, if no element is
3393 * provided, one will be created below the
3394 * navigation links at the top of the page
3396 * @return bool True on success, false on failure
3398 function PMA_slidingMessage(msg, $obj)
3400 if (msg === undefined || msg.length === 0) {
3401 // Don't show an empty message
3404 if ($obj === undefined || ! $obj instanceof jQuery || $obj.length === 0) {
3405 // If the second argument was not supplied,
3406 // we might have to create a new DOM node.
3407 if ($('#PMA_slidingMessage').length === 0) {
3408 $('#page_content').prepend(
3409 '<span id="PMA_slidingMessage" ' +
3410 'style="display: inline-block;"></span>'
3413 $obj = $('#PMA_slidingMessage');
3415 if ($obj.has('div').length > 0) {
3416 // If there already is a message inside the
3417 // target object, we must get rid of it
3421 .fadeOut(function () {
3426 .append('<div style="display: none;">' + msg + '</div>')
3428 height: $obj.find('div').first().height()
3435 // Object does not already have a message
3436 // inside it, so we simply slide it down
3439 .html('<div style="display: none;">' + msg + '</div>')
3451 // Set the height of the parent
3452 // to the height of the child
3463 } // end PMA_slidingMessage()
3466 * Unbind all event handlers before tearing down a page
3468 AJAX.registerTeardown('functions.js', function () {
3469 $("#drop_tbl_anchor.ajax").die('click');
3470 $("#drop_view_anchor.ajax").die('click');
3471 $("#truncate_tbl_anchor.ajax").die('click');
3474 * Attach Ajax event handlers for Drop Table.
3476 AJAX.registerOnload('functions.js', function () {
3477 $("#drop_tbl_anchor.ajax").live('click', function (event) {
3478 event.preventDefault();
3480 * @var question String containing the question to be asked for confirmation
3482 var question = PMA_messages.strDropTableStrongWarning + ' ';
3483 question += $.sprintf(
3484 PMA_messages.strDoYouReally,
3485 'DROP TABLE ' + PMA_commonParams.get('table')
3488 $(this).PMA_confirm(question, $(this).attr('href'), function (url) {
3490 var $msgbox = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
3491 $.get(url, {'is_js_confirmed': '1', 'ajax_request': true}, function (data) {
3492 if (data.success === true) {
3493 PMA_ajaxRemoveMessage($msgbox);
3494 // Table deleted successfully, refresh both the frames
3495 PMA_reloadNavigation();
3496 PMA_commonParams.set('table', '');
3497 PMA_commonActions.refreshMain(
3498 PMA_commonParams.get('opendb_url'),
3500 PMA_ajaxShowMessage(data.message);
3504 PMA_ajaxShowMessage(data.error, false);
3507 }); // end $.PMA_confirm()
3508 }); //end of Drop Table Ajax action
3510 $("#drop_view_anchor.ajax").live('click', function (event) {
3511 event.preventDefault();
3513 * @var question String containing the question to be asked for confirmation
3515 var question = PMA_messages.strDropTableStrongWarning + ' ';
3516 question += $.sprintf(
3517 PMA_messages.strDoYouReally,
3518 'DROP VIEW ' + PMA_commonParams.get('table')
3521 $(this).PMA_confirm(question, $(this).attr('href'), function (url) {
3523 var $msgbox = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
3524 $.get(url, {'is_js_confirmed': '1', 'ajax_request': true}, function (data) {
3525 if (data.success === true) {
3526 PMA_ajaxRemoveMessage($msgbox);
3527 // Table deleted successfully, refresh both the frames
3528 PMA_reloadNavigation();
3529 PMA_commonParams.set('table', '');
3530 PMA_commonActions.refreshMain(
3531 PMA_commonParams.get('opendb_url'),
3533 PMA_ajaxShowMessage(data.message);
3537 PMA_ajaxShowMessage(data.error, false);
3540 }); // end $.PMA_confirm()
3541 }); //end of Drop View Ajax action
3543 $("#truncate_tbl_anchor.ajax").live('click', function (event) {
3544 event.preventDefault();
3546 * @var question String containing the question to be asked for confirmation
3548 var question = PMA_messages.strTruncateTableStrongWarning + ' ';
3549 question += $.sprintf(
3550 PMA_messages.strDoYouReally,
3551 'TRUNCATE ' + PMA_commonParams.get('table')
3553 $(this).PMA_confirm(question, $(this).attr('href'), function (url) {
3554 PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
3555 $.get(url, {'is_js_confirmed': '1', 'ajax_request': true}, function (data) {
3556 if ($("#sqlqueryresults").length !== 0) {
3557 $("#sqlqueryresults").remove();
3559 if ($("#result_query").length !== 0) {
3560 $("#result_query").remove();
3562 if (data.success === true) {
3563 PMA_ajaxShowMessage(data.message);
3564 $("<div id='sqlqueryresults'></div>").prependTo("#page_content");
3565 $("#sqlqueryresults").html(data.sql_query);
3566 PMA_highlightSQL($('#page_content'));
3568 PMA_ajaxShowMessage(data.error, false);
3571 }); // end $.PMA_confirm()
3572 }); //end of Truncate Table Ajax action
3573 }); // end of $() for Truncate Table
3576 * Attach CodeMirror2 editor to SQL edit area.
3578 AJAX.registerOnload('functions.js', function () {
3579 var $elm = $('#sqlquery');
3580 if ($elm.length > 0) {
3581 if (typeof CodeMirror != 'undefined') {
3583 codemirror_editor = CodeMirror.fromTextArea($elm[0], {
3585 matchBrackets: true,
3587 mode: "text/x-mysql",
3590 codemirror_editor.focus();
3591 $(codemirror_editor.getWrapperElement()).bind(
3593 catchKeypressesFromSqlTextboxes
3596 // without codemirror
3597 $elm.focus().bind('keydown', catchKeypressesFromSqlTextboxes);
3600 PMA_highlightSQL($('body'));
3602 AJAX.registerTeardown('functions.js', function () {
3603 if (codemirror_editor) {
3604 $('#sqlquery').text(codemirror_editor.getValue());
3605 codemirror_editor.toTextArea();
3606 codemirror_editor = false;
3611 * jQuery plugin to cancel selection in HTML code.
3614 $.fn.noSelect = function (p) { //no select plugin by Paulo P.Marinas
3615 var prevent = (p === null) ? true : p;
3617 return this.each(function () {
3618 if ($.browser.msie || $.browser.safari) {
3619 $(this).bind('selectstart', function () {
3622 } else if ($.browser.mozilla) {
3623 $(this).css('MozUserSelect', 'none');
3624 $('body').trigger('focus');
3625 } else if ($.browser.opera) {
3626 $(this).bind('mousedown', function () {
3630 $(this).attr('unselectable', 'on');
3634 return this.each(function () {
3635 if ($.browser.msie || $.browser.safari) {
3636 $(this).unbind('selectstart');
3637 } else if ($.browser.mozilla) {
3638 $(this).css('MozUserSelect', 'inherit');
3639 } else if ($.browser.opera) {
3640 $(this).unbind('mousedown');
3642 $(this).removeAttr('unselectable');
3650 * jQuery plugin to correctly filter input fields by value, needed
3651 * because some nasty values may break selector syntax
3654 $.fn.filterByValue = function (value) {
3655 return this.filter(function () {
3656 return $(this).val() === value;
3662 * Create a jQuery UI tooltip
3664 * @param $elements jQuery object representing the elements
3665 * @param item the item
3666 * (see http://api.jqueryui.com/tooltip/#option-items)
3667 * @param myContent content of the tooltip
3668 * @param additionalOptions to override the default options
3671 function PMA_tooltip($elements, item, myContent, additionalOptions)
3673 if ($('#no_hint').length > 0) {
3677 var defaultOptions = {
3680 tooltipClass: "tooltip",
3686 $elements.tooltip($.extend(true, defaultOptions, additionalOptions));
3690 * Return value of a cell in a table.
3692 function PMA_getCellValue(td) {
3694 if ($td.is('.null')) {
3696 } else if (! $td.is('.to_be_saved') && $td.data('original_data')) {
3697 return $td.data('original_data');
3704 * Unbind all event handlers before tearing down a page
3706 AJAX.registerTeardown('functions.js', function () {
3707 $('a.themeselect').die('click');
3708 $('.autosubmit').die('change');
3709 $('a.take_theme').unbind('click');
3712 AJAX.registerOnload('functions.js', function () {
3716 $('a.themeselect').live('click', function (e) {
3720 'left=10,top=20,width=510,height=350,scrollbars=yes,status=yes,resizable=yes'
3726 * Automatic form submission on change.
3728 $('.autosubmit').live('change', function (e) {
3729 $(this).closest('form').submit();
3735 $('a.take_theme').click(function (e) {
3736 var what = this.name;
3737 if (window.opener && window.opener.document.forms['setTheme'].elements['set_theme']) {
3738 window.opener.document.forms['setTheme'].elements['set_theme'].value = what;
3739 window.opener.document.forms['setTheme'].submit();
3748 * Clear text selection
3750 function PMA_clearSelection() {
3751 if (document.selection && document.selection.empty) {
3752 document.selection.empty();
3753 } else if (window.getSelection) {
3754 var sel = window.getSelection();
3758 if (sel.removeAllRanges) {
3759 sel.removeAllRanges();
3767 function escapeHtml(unsafe) {
3769 .replace(/&/g, "&")
3770 .replace(/</g, "<")
3771 .replace(/>/g, ">")
3772 .replace(/"/g, """)
3773 .replace(/'/g, "'");
3779 function printPage()
3781 // Do print the page
3782 if (typeof(window.print) != 'undefined') {
3788 * Unbind all event handlers before tearing down a page
3790 AJAX.registerTeardown('functions.js', function () {
3791 $('input#print').unbind('click');
3792 $('a.create_view.ajax').die('click');
3793 $('#createViewDialog').find('input, select').die('keydown');
3796 AJAX.registerOnload('functions.js', function () {
3797 $('input#print').click(printPage);
3799 * Ajaxification for the "Create View" action
3801 $('a.create_view.ajax').live('click', function (e) {
3803 PMA_createViewDialog($(this));
3806 * Attach Ajax event handlers for input fields in the editor
3807 * and used to submit the Ajax request when the ENTER key is pressed.
3809 $('#createViewDialog').find('input, select').live('keydown', function (e) {
3810 if (e.which === 13) { // 13 is the ENTER key
3812 $(this).closest('.ui-dialog').find('.ui-button:first').click();
3816 var $elm = $('textarea[name="view[as]"]');
3817 if ($elm.length > 0) {
3818 if (typeof CodeMirror != 'undefined') {
3819 syntaxHighlighter = CodeMirror.fromTextArea(
3823 matchBrackets: true,
3825 mode: "text/x-mysql",
3833 function PMA_createViewDialog($this)
3835 var $msg = PMA_ajaxShowMessage();
3836 var syntaxHighlighter = null;
3837 $.get($this.attr('href') + '&ajax_request=1&ajax_dialog=1', function (data) {
3838 if (data.success === true) {
3839 PMA_ajaxRemoveMessage($msg);
3840 var buttonOptions = {};
3841 buttonOptions[PMA_messages.strGo] = function () {
3842 if (typeof CodeMirror !== 'undefined') {
3843 syntaxHighlighter.save();
3845 $msg = PMA_ajaxShowMessage();
3846 $.get('view_create.php', $('#createViewDialog').find('form').serialize(), function (data) {
3847 PMA_ajaxRemoveMessage($msg);
3848 if (data.success === true) {
3849 $('#createViewDialog').dialog("close");
3850 $('#result_query').html(data.message);
3851 PMA_reloadNavigation();
3853 PMA_ajaxShowMessage(data.error, false);
3857 buttonOptions[PMA_messages.strClose] = function () {
3858 $(this).dialog("close");
3860 var $dialog = $('<div/>').attr('id', 'createViewDialog').append(data.message).dialog({
3864 buttons: buttonOptions,
3865 title: PMA_messages.strCreateView,
3866 close: function () {
3870 // Attach syntax highlited editor
3871 if (typeof CodeMirror !== 'undefined') {
3872 var $elm = $dialog.find('textarea');
3873 var opts = {lineNumbers: true, matchBrackets: true, indentUnit: 4, mode: "text/x-mysql", lineWrapping: true};
3874 syntaxHighlighter = CodeMirror.fromTextArea($elm[0], opts);
3876 $('input:visible[type=text]', $dialog).first().focus();
3878 PMA_ajaxShowMessage(data.error);
3884 * Makes the breadcrumbs and the menu bar float at the top of the viewport
3887 if ($("#floating_menubar").length && $('#PMA_disable_floating_menubar').length === 0) {
3888 var left = $('html').attr('dir') == 'ltr' ? 'left' : 'right';
3889 $("#floating_menubar")
3890 .css('margin-' + left, $('#pma_navigation').width() + $('#pma_navigation_resizer').width())
3893 'position': 'fixed',
3898 .append($('#serverinfo'))
3899 .append($('#topmenucontainer'));
3900 // Allow the DOM to render, then adjust the padding on the body
3901 setTimeout(function () {
3904 $('#floating_menubar').outerHeight(true)
3906 $('#topmenu').menuResizer('resize');
3912 * Scrolls the page to the top if clicking the serverinfo bar
3915 $(document).delegate("#serverinfo, #goto_pagetop", "click", function (event) {
3916 event.preventDefault();
3917 $('html, body').animate({scrollTop: 0}, 'fast');
3921 var checkboxes_sel = "input.checkall:checkbox:enabled";
3923 * Watches checkboxes in a form to set the checkall box accordingly
3925 var checkboxes_changed = function () {
3926 var $form = $(this.form);
3927 // total number of checkboxes in current form
3928 var total_boxes = $form.find(checkboxes_sel).length;
3929 // number of checkboxes checked in current form
3930 var checked_boxes = $form.find(checkboxes_sel + ":checked").length;
3931 var $checkall = $form.find("input.checkall_box");
3932 if (total_boxes == checked_boxes) {
3933 $checkall.prop({checked: true, indeterminate: false});
3935 else if (checked_boxes > 0) {
3936 $checkall.prop({checked: true, indeterminate: true});
3939 $checkall.prop({checked: false, indeterminate: false});
3942 $(checkboxes_sel).live("change", checkboxes_changed);
3944 $("input.checkall_box").live("change", function () {
3945 var is_checked = $(this).is(":checked");
3946 $(this.form).find(checkboxes_sel).prop("checked", is_checked)
3947 .parents("tr").toggleClass("marked", is_checked);
3951 * Toggles row colors of a set of 'tr' elements starting from a given element
3953 * @param $start Starting element
3955 function toggleRowColors($start)
3957 for (var $curr_row = $start; $curr_row.length > 0; $curr_row = $curr_row.next()) {
3958 if ($curr_row.hasClass('odd')) {
3959 $curr_row.removeClass('odd').addClass('even');
3960 } else if ($curr_row.hasClass('even')) {
3961 $curr_row.removeClass('even').addClass('odd');
3967 * Formats a byte number to human-readable form
3969 * @param bytes the bytes to format
3970 * @param optional subdecimals the number of digits after the point
3971 * @param optional pointchar the char to use as decimal point
3973 function formatBytes(bytes, subdecimals, pointchar) {
3980 var units = ['B', 'KiB', 'MiB', 'GiB'];
3981 for (var i = 0; bytes > 1024 && i < units.length; i++) {
3984 var factor = Math.pow(10, subdecimals);
3985 bytes = Math.round(bytes * factor) / factor;
3986 bytes = bytes.toString().split('.').join(pointchar);
3987 return bytes + ' ' + units[i];
3990 AJAX.registerOnload('functions.js', function () {
3992 * Opens pma more themes link in themes browser, in new window instead of popup
3993 * This way, we don't break HTML validity
3995 $("a._blank").prop("target", "_blank");
3997 * Reveal the login form to users with JS enabled
3998 * and focus the appropriate input field
4000 var $loginform = $('#loginform');
4001 if ($loginform.length) {
4002 $loginform.find('.js-show').show();
4003 if ($('#input_username').val()) {
4004 $('#input_password').focus();
4006 $('#input_username').focus();
4012 * When user gets an ajax session expiry message, we show a login link
4014 $('a.login-link').live('click', function (e) {
4016 window.location.reload(true);
4020 * Dynamically adjust the width of the boxes
4021 * on the table and db operations pages
4024 function DynamicBoxes() {
4025 var $boxContainer = $('#boxContainer');
4026 if ($boxContainer.length) {
4027 var minWidth = $boxContainer.data('box-width');
4028 var viewport = $(window).width() - $('#pma_navigation').width();
4029 var slots = Math.floor(viewport / minWidth);
4030 $boxContainer.children()
4032 if (viewport < minWidth) {
4033 $(this).width(minWidth);
4035 $(this).css('width', ((1 / slots) * 100) + "%");
4038 .removeClass('clearfloat')
4039 .filter(':nth-child(' + slots + 'n+1)')
4040 .addClass('clearfloat');
4043 AJAX.registerOnload('functions.js', function () {
4047 $(window).resize(DynamicBoxes);
4052 * Formats timestamp for display
4054 function PMA_formatDateTime(date, seconds) {
4055 var result = $.datepicker.formatDate('yy-mm-dd', date);
4056 var timefmt = 'HH:mm';
4058 timefmt = 'HH:mm:ss';
4060 return result + ' ' + $.datepicker.formatTime(
4062 hour: date.getHours(),
4063 minute: date.getMinutes(),
4064 second: date.getSeconds()