1 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 * JavaScript functionality for Routines, Triggers and Events.
8 * @var RTE Contains all the JavaScript functionality
9 * for Routines, Triggers and Events
13 * Construct for the object that provides the
14 * functionality for Routines, Triggers and Events
16 object: function (type) {
17 $.extend(this, RTE.COMMON);
18 this.editorType = type;
22 $.extend(this, RTE.ROUTINE);
25 // nothing extra yet for triggers
28 $.extend(this, RTE.EVENT);
35 * @var string param_template Template for a row in the routine editor
41 * @var RTE.COMMON a JavaScript namespace containing the functionality
42 * for Routines, Triggers and Events
44 * This namespace is extended by the functionality required
45 * to handle a specific item (a routine, trigger or event)
46 * in the relevant javascript files in this folder
50 * @var $ajaxDialog Query object containing the reference to the
51 * dialog that contains the editor
55 * @var syntaxHiglighter Reference to the codemirror editor
57 syntaxHiglighter: null,
59 * @var buttonOptions Object containing options for
60 * the jQueryUI dialog buttons
64 * @var editorType Type of the editor
68 * Validate editor form fields.
70 validate: function () {
72 * @var $elm a jQuery object containing the reference
73 * to an element that is being validated
76 // Common validation. At the very least the name
77 // and the definition must be provided for an item
78 $elm = $('table.rte_table').last().find('input[name=item_name]');
79 if ($elm.val() === '') {
81 alert(PMA_messages.strFormEmpty);
84 $elm = $('table.rte_table').find('textarea[name=item_definition]');
85 if ($elm.val() === '') {
86 if (this.syntaxHiglighter !== null) {
87 this.syntaxHiglighter.focus();
89 $('textarea[name=item_definition]').last().focus();
91 alert(PMA_messages.strFormEmpty);
94 // The validation has so far passed, so now
95 // we can validate item-specific fields.
96 return this.validateCustom();
99 * Validate custom editor form fields.
100 * This function can be overridden by
101 * other files in this folder
103 validateCustom: function () {
105 }, // end validateCustom()
107 * Execute some code after the ajax
108 * dialog for the editor is shown.
109 * This function can be overridden by
110 * other files in this folder
112 postDialogShow: function () {
113 // Nothing by default
114 }, // end postDialogShow()
116 exportDialog: function ($this) {
117 var $msg = PMA_ajaxShowMessage();
118 if ($this.hasClass('mult_submit')) {
121 title: PMA_messages.strExport,
125 // export anchors of all selected rows
126 var export_anchors = $('input.checkall:checked').parents('tr').find('.export_anchor');
127 var count = export_anchors.length;
130 // No routine is exportable (due to privilege issues)
132 PMA_ajaxShowMessage(PMA_messages.NoExportable);
135 export_anchors.each(function () {
136 $.get($(this).attr('href'), { 'ajax_request': true }, function (data) {
138 if (data.success === true) {
139 combined.message += '\n' + data.message + '\n';
140 if (returnCount === count) {
141 showExport(combined);
144 // complain even if one export is failing
145 combined.success = false;
146 combined.error += '\n' + data.error + '\n';
147 if (returnCount === count) {
148 showExport(combined);
154 $.get($this.attr('href'), { 'ajax_request': true }, showExport);
156 PMA_ajaxRemoveMessage($msg);
158 function showExport (data) {
159 if (data.success === true) {
160 PMA_ajaxRemoveMessage($msg);
162 * @var button_options Object containing options
163 * for jQueryUI dialog buttons
165 var button_options = {};
166 button_options[PMA_messages.strClose] = function () {
167 $(this).dialog('close').remove();
170 * Display the dialog to the user
172 data.message = '<textarea cols="40" rows="15" class="all100">' + data.message + '</textarea>';
173 var $ajaxDialog = $('<div>' + data.message + '</div>').dialog({
175 buttons: button_options,
178 // Attach syntax highlighted editor to export dialog
180 * @var $elm jQuery object containing the reference
181 * to the Export textarea.
183 var $elm = $ajaxDialog.find('textarea');
184 PMA_getSQLEditor($elm);
186 PMA_ajaxShowMessage(data.error, false);
188 } // end showExport()
189 }, // end exportDialog()
190 editorDialog: function (is_new, $this) {
193 * @var $edit_row jQuery object containing the reference to
194 * the row of the the item being edited
195 * from the list of items
197 var $edit_row = null;
198 if ($this.hasClass('edit_anchor')) {
199 // Remeber the row of the item being edited for later,
200 // so that if the edit is successful, we can replace the
201 // row with info about the modified item.
202 $edit_row = $this.parents('tr');
205 * @var $msg jQuery object containing the reference to
206 * the AJAX message shown to the user
208 var $msg = PMA_ajaxShowMessage();
209 $.get($this.attr('href'), { 'ajax_request': true }, function (data) {
210 if (data.success === true) {
211 // We have successfully fetched the editor form
212 PMA_ajaxRemoveMessage($msg);
213 // Now define the function that is called when
214 // the user presses the "Go" button
215 that.buttonOptions[PMA_messages.strGo] = function () {
216 // Move the data from the codemirror editor back to the
217 // textarea, where it can be used in the form submission.
218 if (typeof CodeMirror !== 'undefined') {
219 that.syntaxHiglighter.save();
221 // Validate editor and submit request, if passed.
222 if (that.validate()) {
224 * @var data Form data to be sent in the AJAX request
226 var data = $('form.rte_form').last().serialize();
227 $msg = PMA_ajaxShowMessage(
228 PMA_messages.strProcessingRequest
230 var url = $('form.rte_form').last().attr('action');
231 $.post(url, data, function (data) {
232 if (data.success === true) {
233 // Item created successfully
234 PMA_ajaxRemoveMessage($msg);
235 PMA_slidingMessage(data.message);
236 that.$ajaxDialog.dialog('close');
237 // If we are in 'edit' mode, we must
238 // remove the reference to the old row.
239 if (mode === 'edit' && $edit_row !== null) {
242 // Sometimes, like when moving a trigger from
243 // a table to another one, the new row should
244 // not be inserted into the list. In this case
245 // "data.insert" will be set to false.
247 // Insert the new row at the correct
248 // location in the list of items
250 * @var text Contains the name of an item from
251 * the list that is used in comparisons
252 * to find the correct location where
253 * to insert a new row.
257 * @var inserted Whether a new item has been
258 * inserted in the list or not
260 var inserted = false;
261 $('table.data').find('tr').each(function () {
269 if (text !== '' && text > data.name) {
270 $(this).before(data.new_row);
276 // If we didn't manage to insert the row yet,
277 // it must belong at the end of the list,
278 // so we insert it there.
279 $('table.data').append(data.new_row);
281 // Fade-in the new row
284 .removeClass('ajaxInsert');
285 } else if ($('table.data').find('tr').has('td').length === 0) {
286 // If we are not supposed to insert the new row,
287 // we will now check if the table is empty and
288 // needs to be hidden. This will be the case if
289 // we were editing the only item in the list,
290 // which we removed and will not be inserting
291 // something else in its place.
292 $('table.data').hide('slow', function () {
293 $('#nothing2display').show('slow');
296 // Now we have inserted the row at the correct
297 // position, but surely at least some row classes
298 // are wrong now. So we will itirate throught
299 // all rows and assign correct classes to them
301 * @var ct Count of processed rows
305 * @var rowclass Class to be attached to the row
306 * that is being processed
309 $('table.data').find('tr').has('td').each(function () {
310 rowclass = (ct % 2 === 0) ? 'odd' : 'even';
311 $(this).removeClass().addClass(rowclass);
314 // If this is the first item being added, remove
315 // the "No items" message and show the list.
316 if ($('table.data').find('tr').has('td').length > 0 &&
317 $('#nothing2display').is(':visible')
319 $('#nothing2display').hide('slow', function () {
320 $('table.data').show('slow');
323 PMA_reloadNavigation();
325 PMA_ajaxShowMessage(data.error, false);
328 } // end "if (that.validate())"
329 }; // end of function that handles the submission of the Editor
330 that.buttonOptions[PMA_messages.strClose] = function () {
331 $(this).dialog('close');
334 * Display the dialog to the user
336 that.$ajaxDialog = $('<div id="rteDialog">' + data.message + '</div>').dialog({
339 maxHeight: $(window).height(),
340 buttons: that.buttonOptions,
344 if ($('#rteDialog').parents('.ui-dialog').height() > $(window).height()) {
345 $('#rteDialog').dialog('option', 'height', $(window).height());
347 $(this).find('input[name=item_name]').focus();
348 $(this).find('input.datefield').each(function () {
349 PMA_addDatepicker($(this).css('width', '95%'), 'date');
351 $(this).find('input.datetimefield').each(function () {
352 PMA_addDatepicker($(this).css('width', '95%'), 'datetime');
354 $.datepicker.initialized = false;
361 * @var mode Used to remeber whether the editor is in
362 * "Edit" or "Add" mode
365 if ($('input[name=editor_process_edit]').length > 0) {
368 // Attach syntax highlighted editor to the definition
370 * @var elm jQuery object containing the reference to
371 * the Definition textarea.
373 var $elm = $('textarea[name=item_definition]').last();
374 var linterOptions = {};
375 linterOptions[that.editorType + '_editor'] = true;
376 that.syntaxHiglighter = PMA_getSQLEditor($elm, {}, null, linterOptions);
378 // Execute item-specific code
379 that.postDialogShow(data);
381 PMA_ajaxShowMessage(data.error, false);
386 dropDialog: function ($this) {
388 * @var $curr_row Object containing reference to the current row
390 var $curr_row = $this.parents('tr');
392 * @var question String containing the question to be asked for confirmation
394 var question = $('<div/>').text(
395 $curr_row.children('td').children('.drop_sql').html()
397 // We ask for confirmation first here, before submitting the ajax request
398 $this.PMA_confirm(question, $this.attr('href'), function (url) {
400 * @var msg jQuery object containing the reference to
401 * the AJAX message shown to the user
403 var $msg = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
404 var params = getJSConfirmCommonParam(this, $this.getPostData());
405 $.post(url, params, function (data) {
406 if (data.success === true) {
408 * @var $table Object containing reference
409 * to the main list of elements
411 var $table = $curr_row.parent();
412 // Check how many rows will be left after we remove
413 // the one that the user has requested us to remove
414 if ($table.find('tr').length === 3) {
415 // If there are two rows left, it means that they are
416 // the header of the table and the rows that we are
417 // about to remove, so after the removal there will be
418 // nothing to show in the table, so we hide it.
419 $table.hide('slow', function () {
420 $(this).find('tr.even, tr.odd').remove();
421 $('.withSelected').remove();
422 $('#nothing2display').show('slow');
425 $curr_row.hide('slow', function () {
427 // Now we have removed the row from the list, but maybe
428 // some row classes are wrong now. So we will itirate
429 // throught all rows and assign correct classes to them.
431 * @var ct Count of processed rows
435 * @var rowclass Class to be attached to the row
436 * that is being processed
439 $table.find('tr').has('td').each(function () {
440 rowclass = (ct % 2 === 1) ? 'odd' : 'even';
441 $(this).removeClass().addClass(rowclass);
446 // Get rid of the "Loading" message
447 PMA_ajaxRemoveMessage($msg);
448 // Show the query that we just executed
449 PMA_slidingMessage(data.sql_query);
450 PMA_reloadNavigation();
452 PMA_ajaxShowMessage(data.error, false);
455 }); // end $.PMA_confirm()
458 dropMultipleDialog: function ($this) {
459 // We ask for confirmation here
460 $this.PMA_confirm(PMA_messages.strDropRTEitems, '', function (url) {
462 * @var msg jQuery object containing the reference to
463 * the AJAX message shown to the user
465 var $msg = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
467 // drop anchors of all selected rows
468 var drop_anchors = $('input.checkall:checked').parents('tr').find('.drop_anchor');
470 var count = drop_anchors.length;
473 drop_anchors.each(function () {
474 var $anchor = $(this);
476 * @var $curr_row Object containing reference to the current row
478 var $curr_row = $anchor.parents('tr');
479 var params = getJSConfirmCommonParam(this, $anchor.getPostData());
480 $.post($anchor.attr('href'), params, function (data) {
482 if (data.success === true) {
484 * @var $table Object containing reference
485 * to the main list of elements
487 var $table = $curr_row.parent();
488 // Check how many rows will be left after we remove
489 // the one that the user has requested us to remove
490 if ($table.find('tr').length === 3) {
491 // If there are two rows left, it means that they are
492 // the header of the table and the rows that we are
493 // about to remove, so after the removal there will be
494 // nothing to show in the table, so we hide it.
495 $table.hide('slow', function () {
496 $(this).find('tr.even, tr.odd').remove();
497 $('.withSelected').remove();
498 $('#nothing2display').show('slow');
501 $curr_row.hide('fast', function () {
503 // Now we have removed the row from the list, but maybe
504 // some row classes are wrong now. So we will itirate
505 // throught all rows and assign correct classes to them.
507 * @var ct Count of processed rows
511 * @var rowclass Class to be attached to the row
512 * that is being processed
515 $table.find('tr').has('td').each(function () {
516 rowclass = (ct % 2 === 1) ? 'odd' : 'even';
517 $(this).removeClass().addClass(rowclass);
522 if (returnCount === count) {
524 // Get rid of the "Loading" message
525 PMA_ajaxRemoveMessage($msg);
526 $('#rteListForm_checkall').prop({ checked: false, indeterminate: false });
528 PMA_reloadNavigation();
531 PMA_ajaxShowMessage(data.error, false);
533 if (returnCount === count) {
534 PMA_reloadNavigation();
538 }); // end drop_anchors.each()
539 }); // end $.PMA_confirm()
541 }; // end RTE namespace
544 * @var RTE.EVENT JavaScript functionality for events
547 validateCustom: function () {
549 * @var elm a jQuery object containing the reference
550 * to an element that is being validated
553 if (this.$ajaxDialog.find('select[name=item_type]').find(':selected').val() === 'RECURRING') {
554 // The interval field must not be empty for recurring events
555 $elm = this.$ajaxDialog.find('input[name=item_interval_value]');
556 if ($elm.val() === '') {
558 alert(PMA_messages.strFormEmpty);
562 // The execute_at field must not be empty for "once off" events
563 $elm = this.$ajaxDialog.find('input[name=item_execute_at]');
564 if ($elm.val() === '') {
566 alert(PMA_messages.strFormEmpty);
575 * @var RTE.ROUTINE JavaScript functionality for routines
579 * Overriding the postDialogShow() function defined in common.js
581 * @param data JSON-encoded data from the ajax request
583 postDialogShow: function (data) {
584 // Cache the template for a parameter table row
585 RTE.param_template = data.param_template;
587 // Make adjustments in the dialog to make it AJAX compatible
588 $('td.routine_param_remove').show();
589 $('input[name=routine_removeparameter]').remove();
590 $('input[name=routine_addparameter]').css('width', '100%');
591 // Enable/disable the 'options' dropdowns for parameters as necessary
592 $('table.routine_params_table').last().find('th[colspan=2]').attr('colspan', '1');
593 $('table.routine_params_table').last().find('tr').has('td').each(function () {
594 that.setOptionsForParameter(
595 $(this).find('select[name^=item_param_type]'),
596 $(this).find('input[name^=item_param_length]'),
597 $(this).find('select[name^=item_param_opts_text]'),
598 $(this).find('select[name^=item_param_opts_num]')
601 // Enable/disable the 'options' dropdowns for
602 // function return value as necessary
603 this.setOptionsForParameter(
604 $('table.rte_table').last().find('select[name=item_returntype]'),
605 $('table.rte_table').last().find('input[name=item_returnlength]'),
606 $('table.rte_table').last().find('select[name=item_returnopts_text]'),
607 $('table.rte_table').last().find('select[name=item_returnopts_num]')
609 // Allow changing parameter order
610 $('.routine_params_table tbody').sortable({
611 containment: '.routine_params_table tbody',
612 handle: '.dragHandle',
613 stop: function (event, ui) {
614 that.reindexParameters();
619 * Reindexes the parameters after dropping a parameter or reordering parameters
621 reindexParameters: function () {
623 * @var index Counter used for reindexing the input
624 * fields in the routine parameters table
627 $('table.routine_params_table tbody').find('tr').each(function () {
628 $(this).find(':input').each(function () {
630 * @var inputname The value of the name attribute of
631 * the input field being reindexed
633 var inputname = $(this).attr('name');
634 if (inputname.substr(0, 14) === 'item_param_dir') {
635 $(this).attr('name', inputname.substr(0, 14) + '[' + index + ']');
636 } else if (inputname.substr(0, 15) === 'item_param_name') {
637 $(this).attr('name', inputname.substr(0, 15) + '[' + index + ']');
638 } else if (inputname.substr(0, 15) === 'item_param_type') {
639 $(this).attr('name', inputname.substr(0, 15) + '[' + index + ']');
640 } else if (inputname.substr(0, 17) === 'item_param_length') {
641 $(this).attr('name', inputname.substr(0, 17) + '[' + index + ']');
642 $(this).attr('id', 'item_param_length_' + index);
643 } else if (inputname.substr(0, 20) === 'item_param_opts_text') {
644 $(this).attr('name', inputname.substr(0, 20) + '[' + index + ']');
645 } else if (inputname.substr(0, 19) === 'item_param_opts_num') {
646 $(this).attr('name', inputname.substr(0, 19) + '[' + index + ']');
653 * Overriding the validateCustom() function defined in common.js
655 validateCustom: function () {
657 * @var isSuccess Stores the outcome of the validation
659 var isSuccess = true;
661 * @var inputname The value of the "name" attribute for
662 * the field that is being processed
665 this.$ajaxDialog.find('table.routine_params_table').last().find('tr').each(function () {
666 // Every parameter of a routine must have
667 // a non-empty direction, name and type
669 $(this).find(':input').each(function () {
670 inputname = $(this).attr('name');
671 if (inputname.substr(0, 14) === 'item_param_dir' ||
672 inputname.substr(0, 15) === 'item_param_name' ||
673 inputname.substr(0, 15) === 'item_param_type') {
674 if ($(this).val() === '') {
686 alert(PMA_messages.strFormEmpty);
689 this.$ajaxDialog.find('table.routine_params_table').last().find('tr').each(function () {
690 // SET, ENUM, VARCHAR and VARBINARY fields must have length/values
691 var $inputtyp = $(this).find('select[name^=item_param_type]');
692 var $inputlen = $(this).find('input[name^=item_param_length]');
693 if ($inputtyp.length && $inputlen.length) {
694 if (($inputtyp.val() === 'ENUM' || $inputtyp.val() === 'SET' || $inputtyp.val().substr(0, 3) === 'VAR') &&
695 $inputlen.val() === ''
704 alert(PMA_messages.strFormEmpty);
707 if (this.$ajaxDialog.find('select[name=item_type]').find(':selected').val() === 'FUNCTION') {
708 // The length/values of return variable for functions must
709 // be set, if the type is SET, ENUM, VARCHAR or VARBINARY.
710 var $returntyp = this.$ajaxDialog.find('select[name=item_returntype]');
711 var $returnlen = this.$ajaxDialog.find('input[name=item_returnlength]');
712 if (($returntyp.val() === 'ENUM' || $returntyp.val() === 'SET' || $returntyp.val().substr(0, 3) === 'VAR') &&
713 $returnlen.val() === ''
716 alert(PMA_messages.strFormEmpty);
720 if ($('select[name=item_type]').find(':selected').val() === 'FUNCTION') {
721 // A function must contain a RETURN statement in its definition
722 if (this.$ajaxDialog.find('table.rte_table').find('textarea[name=item_definition]').val().toUpperCase().indexOf('RETURN') < 0) {
723 this.syntaxHiglighter.focus();
724 alert(PMA_messages.MissingReturn);
731 * Enable/disable the "options" dropdown and "length" input for
732 * parameters and the return variable in the routine editor
735 * @param type a jQuery object containing the reference
736 * to the "Type" dropdown box
737 * @param len a jQuery object containing the reference
738 * to the "Length" input box
739 * @param text a jQuery object containing the reference
740 * to the dropdown box with options for
741 * parameters of text type
742 * @param num a jQuery object containing the reference
743 * to the dropdown box with options for
744 * parameters of numeric type
746 setOptionsForParameter: function ($type, $len, $text, $num) {
748 * @var no_opts a jQuery object containing the reference
749 * to an element to be displayed when no
750 * options are available
752 var $no_opts = $text.parent().parent().find('.no_opts');
754 * @var no_len a jQuery object containing the reference
755 * to an element to be displayed when no
756 * "length/values" field is available
758 var $no_len = $len.parent().parent().find('.no_len');
760 // Process for parameter options
761 switch ($type.val()) {
771 $text.parent().hide();
772 $num.parent().show();
783 $text.parent().show();
784 $num.parent().hide();
788 $text.parent().hide();
789 $num.parent().hide();
793 // Process for parameter length
794 switch ($type.val()) {
804 $text.closest('tr').find('a:first').hide();
805 $len.parent().hide();
809 if ($type.val() === 'ENUM' || $type.val() === 'SET') {
810 $text.closest('tr').find('a:first').show();
812 $text.closest('tr').find('a:first').hide();
814 $len.parent().show();
819 executeDialog: function ($this) {
822 * @var msg jQuery object containing the reference to
823 * the AJAX message shown to the user
825 var $msg = PMA_ajaxShowMessage();
826 var params = getJSConfirmCommonParam($this[0], $this.getPostData());
827 $.post($this.attr('href'), params, function (data) {
828 if (data.success === true) {
829 PMA_ajaxRemoveMessage($msg);
830 // If 'data.dialog' is true we show a dialog with a form
831 // to get the input parameters for routine, otherwise
832 // we just show the results of the query
834 // Define the function that is called when
835 // the user presses the "Go" button
836 that.buttonOptions[PMA_messages.strGo] = function () {
838 * @var data Form data to be sent in the AJAX request
840 var data = $('form.rte_form').last().serialize();
841 $msg = PMA_ajaxShowMessage(
842 PMA_messages.strProcessingRequest
844 $.post('db_routines.php', data, function (data) {
845 if (data.success === true) {
846 // Routine executed successfully
847 PMA_ajaxRemoveMessage($msg);
848 PMA_slidingMessage(data.message);
849 $ajaxDialog.dialog('close');
851 PMA_ajaxShowMessage(data.error, false);
855 that.buttonOptions[PMA_messages.strClose] = function () {
856 $(this).dialog('close');
859 * Display the dialog to the user
861 var $ajaxDialog = $('<div>' + data.message + '</div>').dialog({
863 buttons: that.buttonOptions,
870 $ajaxDialog.find('input[name^=params]').first().focus();
872 * Attach the datepickers to the relevant form fields
874 $ajaxDialog.find('input.datefield, input.datetimefield').each(function () {
875 PMA_addDatepicker($(this).css('width', '95%'));
878 * Define the function if the user presses enter
880 $('form.rte_form').on('keyup', function (event) {
881 event.preventDefault();
882 if (event.keyCode === 13) {
884 * @var data Form data to be sent in the AJAX request
886 var data = $(this).serialize();
887 $msg = PMA_ajaxShowMessage(
888 PMA_messages.strProcessingRequest
890 var url = $(this).attr('action');
891 $.post(url, data, function (data) {
892 if (data.success === true) {
893 // Routine executed successfully
894 PMA_ajaxRemoveMessage($msg);
895 PMA_slidingMessage(data.message);
896 $('form.rte_form').off('keyup');
897 $ajaxDialog.remove();
899 PMA_ajaxShowMessage(data.error, false);
905 // Routine executed successfully
906 PMA_slidingMessage(data.message);
909 PMA_ajaxShowMessage(data.error, false);
916 * Attach Ajax event handlers for the Routines, Triggers and Events editor
920 * Attach Ajax event handlers for the Add/Edit functionality.
922 $(document).on('click', 'a.ajax.add_anchor, a.ajax.edit_anchor', function (event) {
923 event.preventDefault();
924 var type = $(this).attr('href').substr(0, $(this).attr('href').indexOf('?'));
925 if (type.indexOf('routine') !== -1) {
927 } else if (type.indexOf('trigger') !== -1) {
929 } else if (type.indexOf('event') !== -1) {
934 var dialog = new RTE.object(type);
935 dialog.editorDialog($(this).hasClass('add_anchor'), $(this));
936 }); // end $(document).on()
939 * Attach Ajax event handlers for the Execute routine functionality
941 $(document).on('click', 'a.ajax.exec_anchor', function (event) {
942 event.preventDefault();
943 var dialog = new RTE.object('routine');
944 dialog.executeDialog($(this));
945 }); // end $(document).on()
948 * Attach Ajax event handlers for Export of Routines, Triggers and Events
950 $(document).on('click', 'a.ajax.export_anchor', function (event) {
951 event.preventDefault();
952 var dialog = new RTE.object();
953 dialog.exportDialog($(this));
954 }); // end $(document).on()
956 $(document).on('click', '#rteListForm.ajax .mult_submit[value="export"]', function (event) {
957 event.preventDefault();
958 var dialog = new RTE.object();
959 dialog.exportDialog($(this));
960 }); // end $(document).on()
963 * Attach Ajax event handlers for Drop functionality
964 * of Routines, Triggers and Events.
966 $(document).on('click', 'a.ajax.drop_anchor', function (event) {
967 event.preventDefault();
968 var dialog = new RTE.object();
969 dialog.dropDialog($(this));
970 }); // end $(document).on()
972 $(document).on('click', '#rteListForm.ajax .mult_submit[value="drop"]', function (event) {
973 event.preventDefault();
974 var dialog = new RTE.object();
975 dialog.dropMultipleDialog($(this));
976 }); // end $(document).on()
979 * Attach Ajax event handlers for the "Change event/routine type"
980 * functionality in the events editor, so that the correct
981 * rows are shown in the editor when changing the event type
983 $(document).on('change', 'select[name=item_type]', function () {
986 .find('tr.recurring_event_row, tr.onetime_event_row, tr.routine_return_row, .routine_direction_cell')
988 }); // end $(document).on()
991 * Attach Ajax event handlers for the "Change parameter type"
992 * functionality in the routines editor, so that the correct
993 * option/length fields, if any, are shown when changing
996 $(document).on('change', 'select[name^=item_param_type]', function () {
998 * @var row jQuery object containing the reference to
999 * a row in the routine parameters table
1001 var $row = $(this).parents('tr').first();
1002 var rte = new RTE.object('routine');
1003 rte.setOptionsForParameter(
1004 $row.find('select[name^=item_param_type]'),
1005 $row.find('input[name^=item_param_length]'),
1006 $row.find('select[name^=item_param_opts_text]'),
1007 $row.find('select[name^=item_param_opts_num]')
1009 }); // end $(document).on()
1012 * Attach Ajax event handlers for the "Change the type of return
1013 * variable of function" functionality, so that the correct fields,
1014 * if any, are shown when changing the function return type type
1016 $(document).on('change', 'select[name=item_returntype]', function () {
1017 var rte = new RTE.object('routine');
1018 var $table = $(this).closest('table.rte_table');
1019 rte.setOptionsForParameter(
1020 $table.find('select[name=item_returntype]'),
1021 $table.find('input[name=item_returnlength]'),
1022 $table.find('select[name=item_returnopts_text]'),
1023 $table.find('select[name=item_returnopts_num]')
1025 }); // end $(document).on()
1028 * Attach Ajax event handlers for the "Add parameter to routine" functionality
1030 $(document).on('click', 'input[name=routine_addparameter]', function (event) {
1031 event.preventDefault();
1033 * @var routine_params_table jQuery object containing the reference
1034 * to the routine parameters table
1036 var $routine_params_table = $(this).closest('div.ui-dialog').find('.routine_params_table');
1038 * @var new_param_row A string containing the HTML code for the
1039 * new row for the routine parameters table
1041 var new_param_row = RTE.param_template.replace(/%s/g, $routine_params_table.find('tr').length - 1);
1042 // Append the new row to the parameters table
1043 $routine_params_table.append(new_param_row);
1044 // Make sure that the row is correctly shown according to the type of routine
1045 if ($(this).closest('div.ui-dialog').find('table.rte_table select[name=item_type]').val() === 'FUNCTION') {
1046 $('tr.routine_return_row').show();
1047 $('td.routine_direction_cell').hide();
1050 * @var newrow jQuery object containing the reference to the newly
1051 * inserted row in the routine parameters table
1053 var $newrow = $(this).closest('div.ui-dialog').find('table.routine_params_table').find('tr').has('td').last();
1054 // Enable/disable the 'options' dropdowns for parameters as necessary
1055 var rte = new RTE.object('routine');
1056 rte.setOptionsForParameter(
1057 $newrow.find('select[name^=item_param_type]'),
1058 $newrow.find('input[name^=item_param_length]'),
1059 $newrow.find('select[name^=item_param_opts_text]'),
1060 $newrow.find('select[name^=item_param_opts_num]')
1062 }); // end $(document).on()
1065 * Attach Ajax event handlers for the
1066 * "Remove parameter from routine" functionality
1068 $(document).on('click', 'a.routine_param_remove_anchor', function (event) {
1069 event.preventDefault();
1070 $(this).parent().parent().remove();
1071 // After removing a parameter, the indices of the name attributes in
1072 // the input fields lose the correct order and need to be reordered.
1073 RTE.ROUTINE.reindexParameters();
1074 }); // end $(document).on()