diff --git a/js/db_routines.js b/js/db_routines.js index 5aa889e1d5..df6260a852 100644 --- a/js/db_routines.js +++ b/js/db_routines.js @@ -27,6 +27,98 @@ $(document).ready(function() { * @var button_options Object containing options for jQueryUI dialog buttons */ var button_options = {}; + button_options[PMA_messages['strGo']] = function() { + // Validate editor fields + var inputname = ''; + var errored_out = false; + $('.rte_table').last().find(':input[name=routine_name], :input[name=routine_definition]').each(function() { + if ($(this).val() == '') { + alert(PMA_messages['strFormEmpty']); + $(this).focus(); + errored_out = true; + return false; + } + }); + if (! errored_out) { + $('.routine_params_table').last().find('tr').each(function() { + if (! errored_out) { + $(this).find(':input').each(function() { + inputname = $(this).attr('name'); + if (inputname.substr(0, 17) == 'routine_param_dir' || + inputname.substr(0, 18) == 'routine_param_name' || + inputname.substr(0, 18) == 'routine_param_type') { + if ($(this).val() == '') { + alert(PMA_messages['strFormEmpty']); + $(this).focus(); + errored_out = true; + return false; + } + } + }); + } + }); + } + if (! errored_out) { + // SET and ENUM fields must have some values (a.k.a. length) + $('.routine_params_table').last().find('tr').each(function() { + var $inputtyp = $(this).find(':input[name^=routine_param_type]'); + var $inputlen = $(this).find(':input[name^=routine_param_length]'); + if ($inputtyp.length && $inputlen.length) { + if (($inputtyp.val() == 'ENUM' || $inputtyp.val() == 'SET') && $inputlen.val() == '') { + alert(PMA_messages['strFormEmpty']); + $inputlen.focus(); + errored_out = true; + return false; + } + } + }); + } + // Validation finished, submit request + if (! errored_out) { + var data = $('.rte_form').last().serialize() + "&routine_process_"+mode+"routine=1&ajax_request=true"; + var $msg = PMA_ajaxShowMessage(PMA_messages['strLoading']); + $.post('db_routines.php', data, function (data) { + if(data.success == true) { + // Routine created successfully + PMA_ajaxShowMessage(data.message); + $('#js_query_display').html('
' + data.sql_query + '
'); + $ajaxDialog.dialog('close'); + // If we are in 'edit' mode, we must remove the reference to the old row. + if (mode == 'edit') { + $edit_row.remove(); + } + // Insert the new row at the correct location in the list of routines + var text = ''; + var inserted = false; + $('table.data').find('tr').each(function() { + text = $(this).children('td').eq(0).find('strong').text().toUpperCase(); + if (text != '' && text > data.name) { + $(this).before(data.new_row); + inserted = true; + return false; + } + }); + if (! inserted) { + $('table.data').append(data.new_row); + } + // Now we have inserted the row at the correct position, but surely + // at least some row classes are wrong now. So we will itirate + // throught all rows and assign correct classes to them. + var ct = 0; + $('table.data').find('tr').each(function() { + if ($(this).has('th').length) { + return true; + } + rowclass = (ct % 2 == 0) ? 'even' : 'odd'; + $(this).removeClass().addClass(rowclass); + ct++; + }); + } else { + PMA_ajaxShowMessage(data.error); + } + }); + } + } button_options[PMA_messages['strClose']] = function() { $(this).dialog("close"); } @@ -43,7 +135,16 @@ $(document).ready(function() { $(this).remove(); } }); + // Is this edit mode or add mode? + var mode = 'add'; + if ($('input[name=routine_process_editroutine]').length > 0) { + mode = 'edit'; + } + // No need for 2 submit buttons + $('fieldset.routineEditorSubmit').remove(); + // Cache the template for a parameter table row param_template = data.param_template; + // Make adjustments in the dialog to make it AJAX compatible var is_procedure = ''; var is_function = ''; if (data.type == 'PROCEDURE') { @@ -103,103 +204,4 @@ $(document).ready(function() { event.preventDefault(); $('.routine_return_row, .routine_direction_cell').toggle(); }); // end $.live() - - $('input[name=routine_process_addroutine], input[name=routine_process_editroutine]').live('click', function(event) { - event.preventDefault(); - // Is this edit mode or add mode? - var mode = 'add'; - if ($(this).attr('name') == 'routine_process_editroutine') { - mode = 'edit'; - } - // Validate editor fields - var inputname = ''; - var errored_out = false; - $('.rte_table').last().find(':input[name=routine_name], :input[name=routine_definition]').each(function() { - if ($(this).val() == '') { - alert(PMA_messages['strFormEmpty']); - $(this).focus(); - errored_out = true; - return false; - } - }); - if (! errored_out) { - $('.routine_params_table').last().find('tr').each(function() { - if (! errored_out) { - $(this).find(':input').each(function() { - inputname = $(this).attr('name'); - if (inputname.substr(0, 17) == 'routine_param_dir' || - inputname.substr(0, 18) == 'routine_param_name' || - inputname.substr(0, 18) == 'routine_param_type') { - if ($(this).val() == '') { - alert(PMA_messages['strFormEmpty']); - $(this).focus(); - errored_out = true; - return false; - } - } - }); - } - }); - } - if (! errored_out) { - // SET and ENUM fields must have some values (a.k.a. length) - $('.routine_params_table').last().find('tr').each(function() { - var $inputtyp = $(this).find(':input[name^=routine_param_type]'); - var $inputlen = $(this).find(':input[name^=routine_param_length]'); - if ($inputtyp.length && $inputlen.length) { - if (($inputtyp.val() == 'ENUM' || $inputtyp.val() == 'SET') && $inputlen.val() == '') { - alert(PMA_messages['strFormEmpty']); - $inputlen.focus(); - errored_out = true; - return false; - } - } - }); - } - // Validation finished, submit request - if (! errored_out) { - var data = $('.rte_form').last().serialize() + "&routine_process_"+mode+"routine=1&ajax_request=true"; - var $msg = PMA_ajaxShowMessage(PMA_messages['strLoading']); - $.post('db_routines.php', data, function (data) { - if(data.success == true) { - // Routine created successfully - PMA_ajaxShowMessage(data.message); - $('#js_query_display').html('
' + data.sql_query + '
'); - $ajaxDialog.dialog('close'); - // If we are in 'edit' mode, we must remove the reference to the old row. - if (mode == 'edit') { - $edit_row.remove(); - } - // Insert the new row at the correct location in the list of routines - var text = ''; - var inserted = false; - $('table.data').find('tr').each(function() { - text = $(this).children('td').eq(0).find('strong').text().toUpperCase(); - if (text != '' && text > data.name) { - $(this).before(data.new_row); - inserted = true; - return false; - } - }); - if (! inserted) { - $('table.data').append(data.new_row); - } - // Now we have inserted the row at the correct position, but surely - // at least some row classes are wrong now. So we will itirate - // throught all rows and assign correct classes to them. - var ct = 0; - $('table.data').find('tr').each(function() { - if ($(this).has('th').length) { - return true; - } - rowclass = (ct % 2 == 0) ? 'even' : 'odd'; - $(this).removeClass().addClass(rowclass); - ct++; - }); - } else { - PMA_ajaxShowMessage(data.error); - } - }); - } - }); // end $.live() }); // end of $(document).ready() for Export of Routines, Triggers and Events. diff --git a/libraries/db_routines.inc.php b/libraries/db_routines.inc.php index 625d736590..6245ea6376 100644 --- a/libraries/db_routines.inc.php +++ b/libraries/db_routines.inc.php @@ -680,7 +680,7 @@ function displayRoutineEditor($mode, $operation, $routine, $errors) { $retval .= "\n"; $retval .= "\n"; $retval .= "\n"; - $retval .= "
\n"; + $retval .= "
\n"; $retval .= " \n"; $retval .= "
\n";