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);
36 * @var {string} paramTemplate Template for a row in the routine editor
42 * @var RTE.COMMON a JavaScript namespace containing the functionality
43 * for Routines, Triggers and Events
45 * This namespace is extended by the functionality required
46 * to handle a specific item (a routine, trigger or event)
47 * in the relevant javascript files in this folder
51 * @var $ajaxDialog Query object containing the reference to the
52 * dialog that contains the editor
56 * @var syntaxHiglighter Reference to the codemirror editor
58 syntaxHiglighter: null,
60 * @var buttonOptions Object containing options for
61 * the jQueryUI dialog buttons
65 * @var editorType Type of the editor
69 * Validate editor form fields.
71 validate: function () {
73 * @var $elm a jQuery object containing the reference
74 * to an element that is being validated
77 // Common validation. At the very least the name
78 // and the definition must be provided for an item
79 $elm = $('table.rte_table').last().find('input[name=item_name]');
80 if ($elm.val() === '') {
81 $elm.trigger('focus');
82 alert(Messages.strFormEmpty);
85 $elm = $('table.rte_table').find('textarea[name=item_definition]');
86 if ($elm.val() === '') {
87 if (this.syntaxHiglighter !== null) {
88 this.syntaxHiglighter.focus();
90 $('textarea[name=item_definition]').last().trigger('focus');
92 alert(Messages.strFormEmpty);
95 // The validation has so far passed, so now
96 // we can validate item-specific fields.
97 return this.validateCustom();
100 * Validate custom editor form fields.
101 * This function can be overridden by
102 * other files in this folder
104 validateCustom: function () {
106 }, // end validateCustom()
108 * Execute some code after the ajax
109 * dialog for the editor is shown.
110 * This function can be overridden by
111 * other files in this folder
113 postDialogShow: function () {
114 // Nothing by default
115 }, // end postDialogShow()
117 exportDialog: function ($this) {
118 var $msg = Functions.ajaxShowMessage();
119 if ($this.hasClass('mult_submit')) {
122 title: Messages.strExport,
126 // export anchors of all selected rows
127 var exportAnchors = $('input.checkall:checked').parents('tr').find('.export_anchor');
128 var count = exportAnchors.length;
131 // No routine is exportable (due to privilege issues)
133 Functions.ajaxShowMessage(Messages.NoExportable);
136 exportAnchors.each(function () {
137 $.get($(this).attr('href'), { 'ajax_request': true }, function (data) {
139 if (data.success === true) {
140 combined.message += '\n' + data.message + '\n';
141 if (returnCount === count) {
142 showExport(combined);
145 // complain even if one export is failing
146 combined.success = false;
147 combined.error += '\n' + data.error + '\n';
148 if (returnCount === count) {
149 showExport(combined);
155 $.get($this.attr('href'), { 'ajax_request': true }, showExport);
157 Functions.ajaxRemoveMessage($msg);
159 function showExport (data) {
160 if (data.success === true) {
161 Functions.ajaxRemoveMessage($msg);
163 * @var button_options Object containing options
164 * for jQueryUI dialog buttons
166 var buttonOptions = {};
167 buttonOptions[Messages.strClose] = function () {
168 $(this).dialog('close').remove();
171 * Display the dialog to the user
173 data.message = '<textarea cols="40" rows="15" class="all100">' + data.message + '</textarea>';
174 var $ajaxDialog = $('<div>' + data.message + '</div>').dialog({
176 buttons: buttonOptions,
179 // Attach syntax highlighted editor to export dialog
181 * @var $elm jQuery object containing the reference
182 * to the Export textarea.
184 var $elm = $ajaxDialog.find('textarea');
185 Functions.getSqlEditor($elm);
187 Functions.ajaxShowMessage(data.error, false);
189 } // end showExport()
190 }, // end exportDialog()
191 editorDialog: function (isNew, $this) {
194 * @var $edit_row jQuery object containing the reference to
195 * the row of the the item being edited
196 * from the list of items
199 if ($this.hasClass('edit_anchor')) {
200 // Remeber the row of the item being edited for later,
201 // so that if the edit is successful, we can replace the
202 // row with info about the modified item.
203 $editRow = $this.parents('tr');
206 * @var $msg jQuery object containing the reference to
207 * the AJAX message shown to the user
209 var $msg = Functions.ajaxShowMessage();
210 $.get($this.attr('href'), { 'ajax_request': true }, function (data) {
211 if (data.success === true) {
212 // We have successfully fetched the editor form
213 Functions.ajaxRemoveMessage($msg);
214 // Now define the function that is called when
215 // the user presses the "Go" button
216 that.buttonOptions[Messages.strGo] = function () {
217 // Move the data from the codemirror editor back to the
218 // textarea, where it can be used in the form submission.
219 if (typeof CodeMirror !== 'undefined') {
220 that.syntaxHiglighter.save();
222 // Validate editor and submit request, if passed.
223 if (that.validate()) {
225 * @var data Form data to be sent in the AJAX request
227 var data = $('form.rte_form').last().serialize();
228 $msg = Functions.ajaxShowMessage(
229 Messages.strProcessingRequest
231 var url = $('form.rte_form').last().attr('action');
232 $.post(url, data, function (data) {
233 if (data.success === true) {
234 // Item created successfully
235 Functions.ajaxRemoveMessage($msg);
236 Functions.slidingMessage(data.message);
237 that.$ajaxDialog.dialog('close');
238 // If we are in 'edit' mode, we must
239 // remove the reference to the old row.
240 if (mode === 'edit' && $editRow !== null) {
243 // Sometimes, like when moving a trigger from
244 // a table to another one, the new row should
245 // not be inserted into the list. In this case
246 // "data.insert" will be set to false.
248 // Insert the new row at the correct
249 // location in the list of items
251 * @var text Contains the name of an item from
252 * the list that is used in comparisons
253 * to find the correct location where
254 * to insert a new row.
258 * @var inserted Whether a new item has been
259 * inserted in the list or not
261 var inserted = false;
262 $('table.data').find('tr').each(function () {
270 if (text !== '' && text > data.name) {
271 $(this).before(data.new_row);
277 // If we didn't manage to insert the row yet,
278 // it must belong at the end of the list,
279 // so we insert it there.
280 $('table.data').append(data.new_row);
282 // Fade-in the new row
285 .removeClass('ajaxInsert');
286 } else if ($('table.data').find('tr').has('td').length === 0) {
287 // If we are not supposed to insert the new row,
288 // we will now check if the table is empty and
289 // needs to be hidden. This will be the case if
290 // we were editing the only item in the list,
291 // which we removed and will not be inserting
292 // something else in its place.
293 $('table.data').hide('slow', function () {
294 $('#nothing2display').show('slow');
297 // Now we have inserted the row at the correct
298 // position, but surely at least some row classes
299 // are wrong now. So we will itirate throught
300 // all rows and assign correct classes to them
302 * @var ct Count of processed rows
306 * @var rowclass Class to be attached to the row
307 * that is being processed
310 $('table.data').find('tr').has('td').each(function () {
311 rowclass = (ct % 2 === 0) ? 'odd' : 'even';
312 $(this).removeClass().addClass(rowclass);
315 // If this is the first item being added, remove
316 // the "No items" message and show the list.
317 if ($('table.data').find('tr').has('td').length > 0 &&
318 $('#nothing2display').is(':visible')
320 $('#nothing2display').hide('slow', function () {
321 $('table.data').show('slow');
326 Functions.ajaxShowMessage(data.error, false);
329 } // end "if (that.validate())"
330 }; // end of function that handles the submission of the Editor
331 that.buttonOptions[Messages.strClose] = function () {
332 $(this).dialog('close');
335 * Display the dialog to the user
337 that.$ajaxDialog = $('<div id="rteDialog">' + data.message + '</div>').dialog({
340 buttons: that.buttonOptions,
341 // Issue #15810 - use button titles for modals (eg: new procedure)
342 // Respect the order: title on href tag, href content, title sent in response
343 title: $this.attr('title') || $this.text() || $(data.title).text(),
346 $('#rteDialog').dialog('option', 'max-height', $(window).height());
347 if ($('#rteDialog').parents('.ui-dialog').height() > $(window).height()) {
348 $('#rteDialog').dialog('option', 'height', $(window).height());
350 $(this).find('input[name=item_name]').trigger('focus');
351 $(this).find('input.datefield').each(function () {
352 Functions.addDatepicker($(this).css('width', '95%'), 'date');
354 $(this).find('input.datetimefield').each(function () {
355 Functions.addDatepicker($(this).css('width', '95%'), 'datetime');
357 $.datepicker.initialized = false;
364 * @var mode Used to remeber whether the editor is in
365 * "Edit" or "Add" mode
368 if ($('input[name=editor_process_edit]').length > 0) {
371 // Attach syntax highlighted editor to the definition
373 * @var elm jQuery object containing the reference to
374 * the Definition textarea.
376 var $elm = $('textarea[name=item_definition]').last();
377 var linterOptions = {};
378 linterOptions[that.editorType + '_editor'] = true;
379 that.syntaxHiglighter = Functions.getSqlEditor($elm, {}, null, linterOptions);
381 // Execute item-specific code
382 that.postDialogShow(data);
384 Functions.ajaxShowMessage(data.error, false);
389 dropDialog: function ($this) {
391 * @var $curr_row Object containing reference to the current row
393 var $currRow = $this.parents('tr');
395 * @var question String containing the question to be asked for confirmation
397 var question = $('<div></div>').text(
398 $currRow.children('td').children('.drop_sql').html()
400 // We ask for confirmation first here, before submitting the ajax request
401 $this.confirm(question, $this.attr('href'), function (url) {
403 * @var msg jQuery object containing the reference to
404 * the AJAX message shown to the user
406 var $msg = Functions.ajaxShowMessage(Messages.strProcessingRequest);
407 var params = Functions.getJsConfirmCommonParam(this, $this.getPostData());
408 $.post(url, params, function (data) {
409 if (data.success === true) {
411 * @var $table Object containing reference
412 * to the main list of elements
414 var $table = $currRow.parent();
415 // Check how many rows will be left after we remove
416 // the one that the user has requested us to remove
417 if ($table.find('tr').length === 3) {
418 // If there are two rows left, it means that they are
419 // the header of the table and the rows that we are
420 // about to remove, so after the removal there will be
421 // nothing to show in the table, so we hide it.
422 $table.hide('slow', function () {
423 $(this).find('tr.even, tr.odd').remove();
424 $('.withSelected').remove();
425 $('#nothing2display').show('slow');
428 $currRow.hide('slow', function () {
430 // Now we have removed the row from the list, but maybe
431 // some row classes are wrong now. So we will itirate
432 // throught all rows and assign correct classes to them.
434 * @var ct Count of processed rows
438 * @var rowclass Class to be attached to the row
439 * that is being processed
442 $table.find('tr').has('td').each(function () {
443 rowclass = (ct % 2 === 1) ? 'odd' : 'even';
444 $(this).removeClass().addClass(rowclass);
449 // Get rid of the "Loading" message
450 Functions.ajaxRemoveMessage($msg);
451 // Show the query that we just executed
452 Functions.slidingMessage(data.sql_query);
455 Functions.ajaxShowMessage(data.error, false);
461 dropMultipleDialog: function ($this) {
462 // We ask for confirmation here
463 $this.confirm(Messages.strDropRTEitems, '', function () {
465 * @var msg jQuery object containing the reference to
466 * the AJAX message shown to the user
468 var $msg = Functions.ajaxShowMessage(Messages.strProcessingRequest);
470 // drop anchors of all selected rows
471 var dropAnchors = $('input.checkall:checked').parents('tr').find('.drop_anchor');
473 var count = dropAnchors.length;
476 dropAnchors.each(function () {
477 var $anchor = $(this);
479 * @var $curr_row Object containing reference to the current row
481 var $currRow = $anchor.parents('tr');
482 var params = Functions.getJsConfirmCommonParam(this, $anchor.getPostData());
483 $.post($anchor.attr('href'), params, function (data) {
485 if (data.success === true) {
487 * @var $table Object containing reference
488 * to the main list of elements
490 var $table = $currRow.parent();
491 // Check how many rows will be left after we remove
492 // the one that the user has requested us to remove
493 if ($table.find('tr').length === 3) {
494 // If there are two rows left, it means that they are
495 // the header of the table and the rows that we are
496 // about to remove, so after the removal there will be
497 // nothing to show in the table, so we hide it.
498 $table.hide('slow', function () {
499 $(this).find('tr.even, tr.odd').remove();
500 $('.withSelected').remove();
501 $('#nothing2display').show('slow');
504 $currRow.hide('fast', function () {
506 // Now we have removed the row from the list, but maybe
507 // some row classes are wrong now. So we will itirate
508 // throught all rows and assign correct classes to them.
510 * @var ct Count of processed rows
514 * @var rowclass Class to be attached to the row
515 * that is being processed
518 $table.find('tr').has('td').each(function () {
519 rowclass = (ct % 2 === 1) ? 'odd' : 'even';
520 $(this).removeClass().addClass(rowclass);
525 if (returnCount === count) {
527 // Get rid of the "Loading" message
528 Functions.ajaxRemoveMessage($msg);
529 $('#rteListForm_checkall').prop({ checked: false, indeterminate: false });
534 Functions.ajaxShowMessage(data.error, false);
536 if (returnCount === count) {
541 }); // end drop_anchors.each()
544 }; // end RTE namespace
547 * @var RTE.EVENT JavaScript functionality for events
550 validateCustom: function () {
552 * @var elm a jQuery object containing the reference
553 * to an element that is being validated
556 if (this.$ajaxDialog.find('select[name=item_type]').find(':selected').val() === 'RECURRING') {
557 // The interval field must not be empty for recurring events
558 $elm = this.$ajaxDialog.find('input[name=item_interval_value]');
559 if ($elm.val() === '') {
560 $elm.trigger('focus');
561 alert(Messages.strFormEmpty);
565 // The execute_at field must not be empty for "once off" events
566 $elm = this.$ajaxDialog.find('input[name=item_execute_at]');
567 if ($elm.val() === '') {
568 $elm.trigger('focus');
569 alert(Messages.strFormEmpty);
578 * @var RTE.ROUTINE JavaScript functionality for routines
582 * Overriding the postDialogShow() function defined in common.js
584 * @param data JSON-encoded data from the ajax request
586 postDialogShow: function (data) {
587 // Cache the template for a parameter table row
588 RTE.paramTemplate = data.paramTemplate;
590 // Make adjustments in the dialog to make it AJAX compatible
591 $('td.routine_param_remove').show();
592 $('input[name=routine_removeparameter]').remove();
593 $('input[name=routine_addparameter]').css('width', '100%');
594 // Enable/disable the 'options' dropdowns for parameters as necessary
595 $('table.routine_params_table').last().find('th[colspan=2]').attr('colspan', '1');
596 $('table.routine_params_table').last().find('tr').has('td').each(function () {
597 that.setOptionsForParameter(
598 $(this).find('select[name^=item_param_type]'),
599 $(this).find('input[name^=item_param_length]'),
600 $(this).find('select[name^=item_param_opts_text]'),
601 $(this).find('select[name^=item_param_opts_num]')
604 // Enable/disable the 'options' dropdowns for
605 // function return value as necessary
606 this.setOptionsForParameter(
607 $('table.rte_table').last().find('select[name=item_returntype]'),
608 $('table.rte_table').last().find('input[name=item_returnlength]'),
609 $('table.rte_table').last().find('select[name=item_returnopts_text]'),
610 $('table.rte_table').last().find('select[name=item_returnopts_num]')
612 // Allow changing parameter order
613 $('.routine_params_table tbody').sortable({
614 containment: '.routine_params_table tbody',
615 handle: '.dragHandle',
617 that.reindexParameters();
622 * Reindexes the parameters after dropping a parameter or reordering parameters
624 reindexParameters: function () {
626 * @var index Counter used for reindexing the input
627 * fields in the routine parameters table
630 $('table.routine_params_table tbody').find('tr').each(function () {
631 $(this).find(':input').each(function () {
633 * @var inputname The value of the name attribute of
634 * the input field being reindexed
636 var inputname = $(this).attr('name');
637 if (inputname.substr(0, 14) === 'item_param_dir') {
638 $(this).attr('name', inputname.substr(0, 14) + '[' + index + ']');
639 } else if (inputname.substr(0, 15) === 'item_param_name') {
640 $(this).attr('name', inputname.substr(0, 15) + '[' + index + ']');
641 } else if (inputname.substr(0, 15) === 'item_param_type') {
642 $(this).attr('name', inputname.substr(0, 15) + '[' + index + ']');
643 } else if (inputname.substr(0, 17) === 'item_param_length') {
644 $(this).attr('name', inputname.substr(0, 17) + '[' + index + ']');
645 $(this).attr('id', 'item_param_length_' + index);
646 } else if (inputname.substr(0, 20) === 'item_param_opts_text') {
647 $(this).attr('name', inputname.substr(0, 20) + '[' + index + ']');
648 } else if (inputname.substr(0, 19) === 'item_param_opts_num') {
649 $(this).attr('name', inputname.substr(0, 19) + '[' + index + ']');
656 * Overriding the validateCustom() function defined in common.js
658 validateCustom: function () {
660 * @var isSuccess Stores the outcome of the validation
662 var isSuccess = true;
664 * @var inputname The value of the "name" attribute for
665 * the field that is being processed
668 this.$ajaxDialog.find('table.routine_params_table').last().find('tr').each(function () {
669 // Every parameter of a routine must have
670 // a non-empty direction, name and type
672 $(this).find(':input').each(function () {
673 inputname = $(this).attr('name');
674 if (inputname.substr(0, 14) === 'item_param_dir' ||
675 inputname.substr(0, 15) === 'item_param_name' ||
676 inputname.substr(0, 15) === 'item_param_type') {
677 if ($(this).val() === '') {
678 $(this).trigger('focus');
689 alert(Messages.strFormEmpty);
692 this.$ajaxDialog.find('table.routine_params_table').last().find('tr').each(function () {
693 // SET, ENUM, VARCHAR and VARBINARY fields must have length/values
694 var $inputtyp = $(this).find('select[name^=item_param_type]');
695 var $inputlen = $(this).find('input[name^=item_param_length]');
696 if ($inputtyp.length && $inputlen.length) {
697 if (($inputtyp.val() === 'ENUM' || $inputtyp.val() === 'SET' || $inputtyp.val().substr(0, 3) === 'VAR') &&
698 $inputlen.val() === ''
700 $inputlen.trigger('focus');
707 alert(Messages.strFormEmpty);
710 if (this.$ajaxDialog.find('select[name=item_type]').find(':selected').val() === 'FUNCTION') {
711 // The length/values of return variable for functions must
712 // be set, if the type is SET, ENUM, VARCHAR or VARBINARY.
713 var $returntyp = this.$ajaxDialog.find('select[name=item_returntype]');
714 var $returnlen = this.$ajaxDialog.find('input[name=item_returnlength]');
715 if (($returntyp.val() === 'ENUM' || $returntyp.val() === 'SET' || $returntyp.val().substr(0, 3) === 'VAR') &&
716 $returnlen.val() === ''
718 $returnlen.trigger('focus');
719 alert(Messages.strFormEmpty);
723 if ($('select[name=item_type]').find(':selected').val() === 'FUNCTION') {
724 // A function must contain a RETURN statement in its definition
725 if (this.$ajaxDialog.find('table.rte_table').find('textarea[name=item_definition]').val().toUpperCase().indexOf('RETURN') < 0) {
726 this.syntaxHiglighter.focus();
727 alert(Messages.MissingReturn);
734 * Enable/disable the "options" dropdown and "length" input for
735 * parameters and the return variable in the routine editor
738 * @param type a jQuery object containing the reference
739 * to the "Type" dropdown box
740 * @param len a jQuery object containing the reference
741 * to the "Length" input box
742 * @param text a jQuery object containing the reference
743 * to the dropdown box with options for
744 * parameters of text type
745 * @param num a jQuery object containing the reference
746 * to the dropdown box with options for
747 * parameters of numeric type
749 setOptionsForParameter: function ($type, $len, $text, $num) {
751 * @var no_opts a jQuery object containing the reference
752 * to an element to be displayed when no
753 * options are available
755 var $noOpts = $text.parent().parent().find('.no_opts');
757 * @var no_len a jQuery object containing the reference
758 * to an element to be displayed when no
759 * "length/values" field is available
761 var $noLen = $len.parent().parent().find('.no_len');
763 // Process for parameter options
764 switch ($type.val()) {
774 $text.parent().hide();
775 $num.parent().show();
786 $text.parent().show();
787 $num.parent().hide();
791 $text.parent().hide();
792 $num.parent().hide();
796 // Process for parameter length
797 switch ($type.val()) {
807 $text.closest('tr').find('a:first').hide();
808 $len.parent().hide();
812 if ($type.val() === 'ENUM' || $type.val() === 'SET') {
813 $text.closest('tr').find('a:first').show();
815 $text.closest('tr').find('a:first').hide();
817 $len.parent().show();
822 executeDialog: function ($this) {
825 * @var msg jQuery object containing the reference to
826 * the AJAX message shown to the user
828 var $msg = Functions.ajaxShowMessage();
829 var params = Functions.getJsConfirmCommonParam($this[0], $this.getPostData());
830 $.post($this.attr('href'), params, function (data) {
831 if (data.success === true) {
832 Functions.ajaxRemoveMessage($msg);
833 // If 'data.dialog' is true we show a dialog with a form
834 // to get the input parameters for routine, otherwise
835 // we just show the results of the query
837 // Define the function that is called when
838 // the user presses the "Go" button
839 that.buttonOptions[Messages.strGo] = function () {
841 * @var data Form data to be sent in the AJAX request
843 var data = $('form.rte_form').last().serialize();
844 $msg = Functions.ajaxShowMessage(
845 Messages.strProcessingRequest
847 $.post('db_routines.php', data, function (data) {
848 if (data.success === true) {
849 // Routine executed successfully
850 Functions.ajaxRemoveMessage($msg);
851 Functions.slidingMessage(data.message);
852 $ajaxDialog.dialog('close');
854 Functions.ajaxShowMessage(data.error, false);
858 that.buttonOptions[Messages.strClose] = function () {
859 $(this).dialog('close');
862 * Display the dialog to the user
864 var $ajaxDialog = $('<div>' + data.message + '</div>').dialog({
866 buttons: that.buttonOptions,
873 $ajaxDialog.find('input[name^=params]').first().trigger('focus');
875 * Attach the datepickers to the relevant form fields
877 $ajaxDialog.find('input.datefield, input.datetimefield').each(function () {
878 Functions.addDatepicker($(this).css('width', '95%'));
881 * Define the function if the user presses enter
883 $('form.rte_form').on('keyup', function (event) {
884 event.preventDefault();
885 if (event.keyCode === 13) {
887 * @var data Form data to be sent in the AJAX request
889 var data = $(this).serialize();
890 $msg = Functions.ajaxShowMessage(
891 Messages.strProcessingRequest
893 var url = $(this).attr('action');
894 $.post(url, data, function (data) {
895 if (data.success === true) {
896 // Routine executed successfully
897 Functions.ajaxRemoveMessage($msg);
898 Functions.slidingMessage(data.message);
899 $('form.rte_form').off('keyup');
900 $ajaxDialog.remove();
902 Functions.ajaxShowMessage(data.error, false);
908 // Routine executed successfully
909 Functions.slidingMessage(data.message);
912 Functions.ajaxShowMessage(data.error, false);
919 * Attach Ajax event handlers for the Routines, Triggers and Events editor
923 * Attach Ajax event handlers for the Add/Edit functionality.
925 $(document).on('click', 'a.ajax.add_anchor, a.ajax.edit_anchor', function (event) {
926 event.preventDefault();
927 var type = $(this).attr('href').substr(0, $(this).attr('href').indexOf('?'));
928 if (type.indexOf('routine') !== -1) {
930 } else if (type.indexOf('trigger') !== -1) {
932 } else if (type.indexOf('event') !== -1) {
937 var dialog = new RTE.Object(type);
938 dialog.editorDialog($(this).hasClass('add_anchor'), $(this));
939 }); // end $(document).on()
942 * Attach Ajax event handlers for the Execute routine functionality
944 $(document).on('click', 'a.ajax.exec_anchor', function (event) {
945 event.preventDefault();
946 var dialog = new RTE.Object('routine');
947 dialog.executeDialog($(this));
948 }); // end $(document).on()
951 * Attach Ajax event handlers for Export of Routines, Triggers and Events
953 $(document).on('click', 'a.ajax.export_anchor', function (event) {
954 event.preventDefault();
955 var dialog = new RTE.Object();
956 dialog.exportDialog($(this));
957 }); // end $(document).on()
959 $(document).on('click', '#rteListForm.ajax .mult_submit[value="export"]', function (event) {
960 event.preventDefault();
961 var dialog = new RTE.Object();
962 dialog.exportDialog($(this));
963 }); // end $(document).on()
966 * Attach Ajax event handlers for Drop functionality
967 * of Routines, Triggers and Events.
969 $(document).on('click', 'a.ajax.drop_anchor', function (event) {
970 event.preventDefault();
971 var dialog = new RTE.Object();
972 dialog.dropDialog($(this));
973 }); // end $(document).on()
975 $(document).on('click', '#rteListForm.ajax .mult_submit[value="drop"]', function (event) {
976 event.preventDefault();
977 var dialog = new RTE.Object();
978 dialog.dropMultipleDialog($(this));
979 }); // end $(document).on()
982 * Attach Ajax event handlers for the "Change event/routine type"
983 * functionality in the events editor, so that the correct
984 * rows are shown in the editor when changing the event type
986 $(document).on('change', 'select[name=item_type]', function () {
989 .find('tr.recurring_event_row, tr.onetime_event_row, tr.routine_return_row, .routine_direction_cell')
991 }); // end $(document).on()
994 * Attach Ajax event handlers for the "Change parameter type"
995 * functionality in the routines editor, so that the correct
996 * option/length fields, if any, are shown when changing
999 $(document).on('change', 'select[name^=item_param_type]', function () {
1001 * @var row jQuery object containing the reference to
1002 * a row in the routine parameters table
1004 var $row = $(this).parents('tr').first();
1005 var rte = new RTE.Object('routine');
1006 rte.setOptionsForParameter(
1007 $row.find('select[name^=item_param_type]'),
1008 $row.find('input[name^=item_param_length]'),
1009 $row.find('select[name^=item_param_opts_text]'),
1010 $row.find('select[name^=item_param_opts_num]')
1012 }); // end $(document).on()
1015 * Attach Ajax event handlers for the "Change the type of return
1016 * variable of function" functionality, so that the correct fields,
1017 * if any, are shown when changing the function return type type
1019 $(document).on('change', 'select[name=item_returntype]', function () {
1020 var rte = new RTE.Object('routine');
1021 var $table = $(this).closest('table.rte_table');
1022 rte.setOptionsForParameter(
1023 $table.find('select[name=item_returntype]'),
1024 $table.find('input[name=item_returnlength]'),
1025 $table.find('select[name=item_returnopts_text]'),
1026 $table.find('select[name=item_returnopts_num]')
1028 }); // end $(document).on()
1031 * Attach Ajax event handlers for the "Add parameter to routine" functionality
1033 $(document).on('click', 'input[name=routine_addparameter]', function (event) {
1034 event.preventDefault();
1036 * @var routine_params_table jQuery object containing the reference
1037 * to the routine parameters table
1039 var $routineParamsTable = $(this).closest('div.ui-dialog').find('.routine_params_table');
1041 * @var new_param_row A string containing the HTML code for the
1042 * new row for the routine parameters table
1044 var newParamRow = RTE.paramTemplate.replace(/%s/g, $routineParamsTable.find('tr').length - 1);
1045 // Append the new row to the parameters table
1046 $routineParamsTable.append(newParamRow);
1047 // Make sure that the row is correctly shown according to the type of routine
1048 if ($(this).closest('div.ui-dialog').find('table.rte_table select[name=item_type]').val() === 'FUNCTION') {
1049 $('tr.routine_return_row').show();
1050 $('td.routine_direction_cell').hide();
1053 * @var newrow jQuery object containing the reference to the newly
1054 * inserted row in the routine parameters table
1056 var $newrow = $(this).closest('div.ui-dialog').find('table.routine_params_table').find('tr').has('td').last();
1057 // Enable/disable the 'options' dropdowns for parameters as necessary
1058 var rte = new RTE.Object('routine');
1059 rte.setOptionsForParameter(
1060 $newrow.find('select[name^=item_param_type]'),
1061 $newrow.find('input[name^=item_param_length]'),
1062 $newrow.find('select[name^=item_param_opts_text]'),
1063 $newrow.find('select[name^=item_param_opts_num]')
1065 }); // end $(document).on()
1068 * Attach Ajax event handlers for the
1069 * "Remove parameter from routine" functionality
1071 $(document).on('click', 'a.routine_param_remove_anchor', function (event) {
1072 event.preventDefault();
1073 $(this).parent().parent().remove();
1074 // After removing a parameter, the indices of the name attributes in
1075 // the input fields lose the correct order and need to be reordered.
1076 RTE.ROUTINE.reindexParameters();
1077 }); // end $(document).on()