1 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 * @fileoverview events handling from central columns page
4 * @name Central columns
10 * AJAX scripts for db_central_columns.php
12 * Actions ajaxified here:
13 * Inline Edit and save of a result row
15 * Multiple edit and delete option
19 AJAX.registerTeardown('db_central_columns.js', function () {
20 $('.edit').off('click');
21 $('.edit_save_form').off('click');
22 $('.edit_cancel_form').off('click');
23 $('.del_row').off('click');
24 $(document).off('keyup', '.filter_rows');
25 $('.edit_cancel_form').off('click');
26 $('#table-select').off('change');
27 $('#column-select').off('change');
28 $('#add_col_div').find('>a').off('click');
29 $('#add_new').off('submit');
30 $('#multi_edit_central_columns').off('submit');
31 $('select.default_type').off('change');
32 $('button[name=\'delete_central_columns\']').off('click');
33 $('button[name=\'edit_central_columns\']').off('click');
36 AJAX.registerOnload('db_central_columns.js', function () {
37 $('#tableslistcontainer input,#tableslistcontainer select,#tableslistcontainer .default_value,#tableslistcontainer .open_enum_editor').hide();
38 $('#tableslistcontainer').find('.checkall').show();
39 $('#tableslistcontainer').find('.checkall_box').show();
40 if ($('#table_columns').find('tbody tr').length > 0) {
41 $('#table_columns').tablesorter({
44 1: { sorter: false }, // hidden column
45 4: { sorter: 'integer' }
49 $('#tableslistcontainer').find('button[name="delete_central_columns"]').click(function (event) {
50 event.preventDefault();
51 var multi_delete_columns = $('.checkall:checkbox:checked').serialize();
52 if (multi_delete_columns === '') {
53 PMA_ajaxShowMessage(PMA_messages.strRadioUnchecked);
56 PMA_ajaxShowMessage();
57 $('#del_col_name').val(multi_delete_columns);
58 $('#del_form').submit();
60 $('#tableslistcontainer').find('button[name="edit_central_columns"]').click(function (event) {
61 event.preventDefault();
62 var editColumnList = $('.checkall:checkbox:checked').serialize();
63 if (editColumnList === '') {
64 PMA_ajaxShowMessage(PMA_messages.strRadioUnchecked);
67 var argsep = PMA_commonParams.get('arg_separator');
68 var editColumnData = editColumnList + '' + argsep + 'edit_central_columns_page=true' + argsep + 'ajax_request=true' + argsep + 'ajax_page_request=true' + argsep + 'db=' + encodeURIComponent(PMA_commonParams.get('db'));
69 PMA_ajaxShowMessage();
70 AJAX.source = $(this);
71 $.post('db_central_columns.php', editColumnData, AJAX.responseHandler);
73 $('#multi_edit_central_columns').submit(function (event) {
74 event.preventDefault();
75 event.stopPropagation();
76 var argsep = PMA_commonParams.get('arg_separator');
77 var multi_column_edit_data = $('#multi_edit_central_columns').serialize() + argsep + 'multi_edit_central_column_save=true' + argsep + 'ajax_request=true' + argsep + 'ajax_page_request=true' + argsep + 'db=' + encodeURIComponent(PMA_commonParams.get('db'));
78 PMA_ajaxShowMessage();
79 AJAX.source = $(this);
80 $.post('db_central_columns.php', multi_column_edit_data, AJAX.responseHandler);
82 $('#add_new').find('td').each(function () {
83 if ($(this).attr('name') !== 'undefined') {
84 $(this).find('input,select:first').attr('name', $(this).attr('name'));
87 $('#field_0_0').attr('required','required');
88 $('#add_new input[type="text"], #add_new input[type="number"], #add_new select')
91 '-moz-box-sizing' : 'border-box'
93 window.scrollTo(0, 0);
94 $(document).on('keyup', '.filter_rows', function () {
95 // get the column names
96 var cols = $('th.column_heading').map(function () {
97 return $.trim($(this).text());
99 $.uiTableFilter($('#table_columns'), $(this).val(), cols, null, 'td span');
101 $('.edit').click(function () {
102 var rownum = $(this).parent().data('rownum');
103 $('#save_' + rownum).show();
105 $('#f_' + rownum + ' td span').hide();
106 $('#f_' + rownum + ' input, #f_' + rownum + ' select, #f_' + rownum + ' .open_enum_editor').show();
107 var attribute_val = $('#f_' + rownum + ' td[name=col_attribute] span').html();
108 $('#f_' + rownum + ' select[name=field_attribute\\[' + rownum + '\\] ] option[value="' + attribute_val + '"]').attr('selected','selected');
109 if ($('#f_' + rownum + ' .default_type').val() === 'USER_DEFINED') {
110 $('#f_' + rownum + ' .default_type').siblings('.default_value').show();
112 $('#f_' + rownum + ' .default_type').siblings('.default_value').hide();
115 $('.del_row').click(function (event) {
116 event.preventDefault();
117 event.stopPropagation();
119 var question = PMA_messages.strDeleteCentralColumnWarning;
120 $td.PMA_confirm(question, null, function (url) {
121 var rownum = $td.data('rownum');
122 $('#del_col_name').val('selected_fld%5B%5D=' + $('#checkbox_row_' + rownum).val());
123 $('#del_form').submit();
126 $('.edit_cancel_form').click(function (event) {
127 event.preventDefault();
128 event.stopPropagation();
129 var rownum = $(this).data('rownum');
130 $('#save_' + rownum).hide();
131 $('#edit_' + rownum).show();
132 $('#f_' + rownum + ' td span').show();
133 $('#f_' + rownum + ' input, #f_' + rownum + ' select,#f_' + rownum + ' .default_value, #f_' + rownum + ' .open_enum_editor').hide();
134 $('#tableslistcontainer').find('.checkall').show();
136 $('.edit_save_form').click(function (event) {
137 event.preventDefault();
138 event.stopPropagation();
139 var rownum = $(this).data('rownum');
140 $('#f_' + rownum + ' td').each(function () {
141 if ($(this).attr('name') !== 'undefined') {
142 $(this).find(':input[type!="hidden"],select:first')
143 .attr('name', $(this).attr('name'));
147 if ($('#f_' + rownum + ' .default_type').val() === 'USER_DEFINED') {
148 $('#f_' + rownum + ' .default_type').attr('name','col_default_sel');
150 $('#f_' + rownum + ' .default_value').attr('name','col_default_val');
153 var datastring = $('#f_' + rownum + ' :input').serialize();
156 url: 'db_central_columns.php',
157 data: datastring + PMA_commonParams.get('arg_separator') + 'ajax_request=true',
159 success: function (data) {
160 if (data.message !== '1') {
162 '<div class="error">' +
168 $('#f_' + rownum + ' td input[id=checkbox_row_' + rownum + ']').val($('#f_' + rownum + ' input[name=col_name]').val()).html();
169 $('#f_' + rownum + ' td[name=col_name] span').text($('#f_' + rownum + ' input[name=col_name]').val()).html();
170 $('#f_' + rownum + ' td[name=col_type] span').text($('#f_' + rownum + ' select[name=col_type]').val()).html();
171 $('#f_' + rownum + ' td[name=col_length] span').text($('#f_' + rownum + ' input[name=col_length]').val()).html();
172 $('#f_' + rownum + ' td[name=collation] span').text($('#f_' + rownum + ' select[name=collation]').val()).html();
173 $('#f_' + rownum + ' td[name=col_attribute] span').text($('#f_' + rownum + ' select[name=col_attribute]').val()).html();
174 $('#f_' + rownum + ' td[name=col_isNull] span').text($('#f_' + rownum + ' input[name=col_isNull]').is(':checked') ? 'Yes' : 'No').html();
175 $('#f_' + rownum + ' td[name=col_extra] span').text($('#f_' + rownum + ' input[name=col_extra]').is(':checked') ? 'auto_increment' : '').html();
176 $('#f_' + rownum + ' td[name=col_default] span').text($('#f_' + rownum + ' :input[name=col_default]').val()).html();
178 $('#save_' + rownum).hide();
179 $('#edit_' + rownum).show();
180 $('#f_' + rownum + ' td span').show();
181 $('#f_' + rownum + ' input, #f_' + rownum + ' select,#f_' + rownum + ' .default_value, #f_' + rownum + ' .open_enum_editor').hide();
182 $('#tableslistcontainer').find('.checkall').show();
186 '<div class="error">' +
187 PMA_messages.strErrorProcessingRequest +
194 $('#table-select').change(function (e) {
195 var selectvalue = $(this).val();
196 var default_column_select = $('#column-select').find('option:first');
197 var href = 'db_central_columns.php';
199 'ajax_request' : true,
200 'server' : PMA_commonParams.get('server'),
201 'db' : PMA_commonParams.get('db'),
202 'selectedTable' : selectvalue,
203 'populateColumns' : true
205 $('#column-select').html('<option value="">' + PMA_messages.strLoading + '</option>');
206 if (selectvalue !== '') {
207 $.post(href, params, function (data) {
208 $('#column-select').empty().append(default_column_select);
209 $('#column-select').append(data.message);
213 $('#column-select').change(function (e) {
214 var selectvalue = $(this).val();
215 if (selectvalue !== '') {
216 $('#add_column').submit();
219 $('#add_col_div').find('>a').click(function (event) {
220 $('#add_new').slideToggle('slow');
221 var $addColDivLinkSpan = $('#add_col_div').find('>a span');
222 if ($addColDivLinkSpan.html() === '+') {
223 $addColDivLinkSpan.html('-');
225 $addColDivLinkSpan.html('+');
228 $('#add_new').submit(function (event) {
229 $('#add_new').toggle();
231 $('#tableslistcontainer').find('select.default_type').change(function () {
232 if ($(this).val() === 'USER_DEFINED') {
233 $(this).siblings('.default_value').attr('name','col_default');
234 $(this).attr('name','col_default_sel');
236 $(this).attr('name','col_default');
237 $(this).siblings('.default_value').attr('name','col_default_val');