db_central_columns.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /* vim: set expandtab sw=4 ts=4 sts=4: */
  2. /**
  3. * @fileoverview events handling from central columns page
  4. * @name Central columns
  5. *
  6. * @requires jQuery
  7. */
  8. /**
  9. * AJAX scripts for db_central_columns.php
  10. *
  11. * Actions ajaxified here:
  12. * Inline Edit and save of a result row
  13. * Delete a row
  14. * Multiple edit and delete option
  15. *
  16. */
  17. AJAX.registerTeardown('db_central_columns.js', function () {
  18. $('.edit').off('click');
  19. $('.edit_save_form').off('click');
  20. $('.edit_cancel_form').off('click');
  21. $('.del_row').off('click');
  22. $(document).off('keyup', '.filter_rows');
  23. $('.edit_cancel_form').off('click');
  24. $('#table-select').off('change');
  25. $('#column-select').off('change');
  26. $('#add_col_div').find('>a').off('click');
  27. $('#add_new').off('submit');
  28. $('#multi_edit_central_columns').off('submit');
  29. $('select.default_type').off('change');
  30. $('button[name=\'delete_central_columns\']').off('click');
  31. $('button[name=\'edit_central_columns\']').off('click');
  32. });
  33. AJAX.registerOnload('db_central_columns.js', function () {
  34. $('#tableslistcontainer input,#tableslistcontainer select,#tableslistcontainer .default_value,#tableslistcontainer .open_enum_editor').hide();
  35. $('#tableslistcontainer').find('.checkall').show();
  36. $('#tableslistcontainer').find('.checkall_box').show();
  37. if ($('#table_columns').find('tbody tr').length > 0) {
  38. $('#table_columns').tablesorter({
  39. headers: {
  40. 0: { sorter: false },
  41. 1: { sorter: false }, // hidden column
  42. 4: { sorter: 'integer' }
  43. }
  44. });
  45. }
  46. $('#tableslistcontainer').find('button[name="delete_central_columns"]').click(function (event) {
  47. event.preventDefault();
  48. var multi_delete_columns = $('.checkall:checkbox:checked').serialize();
  49. if (multi_delete_columns === '') {
  50. PMA_ajaxShowMessage(PMA_messages.strRadioUnchecked);
  51. return false;
  52. }
  53. PMA_ajaxShowMessage();
  54. $('#del_col_name').val(multi_delete_columns);
  55. $('#del_form').submit();
  56. });
  57. $('#tableslistcontainer').find('button[name="edit_central_columns"]').click(function (event) {
  58. event.preventDefault();
  59. var editColumnList = $('.checkall:checkbox:checked').serialize();
  60. if (editColumnList === '') {
  61. PMA_ajaxShowMessage(PMA_messages.strRadioUnchecked);
  62. return false;
  63. }
  64. var argsep = PMA_commonParams.get('arg_separator');
  65. 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'));
  66. PMA_ajaxShowMessage();
  67. AJAX.source = $(this);
  68. $.post('db_central_columns.php', editColumnData, AJAX.responseHandler);
  69. });
  70. $('#multi_edit_central_columns').submit(function (event) {
  71. event.preventDefault();
  72. event.stopPropagation();
  73. var argsep = PMA_commonParams.get('arg_separator');
  74. 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'));
  75. PMA_ajaxShowMessage();
  76. AJAX.source = $(this);
  77. $.post('db_central_columns.php', multi_column_edit_data, AJAX.responseHandler);
  78. });
  79. $('#add_new').find('td').each(function () {
  80. if ($(this).attr('name') !== 'undefined') {
  81. $(this).find('input,select:first').attr('name', $(this).attr('name'));
  82. }
  83. });
  84. $('#field_0_0').attr('required','required');
  85. $('#add_new input[type="text"], #add_new input[type="number"], #add_new select')
  86. .css({
  87. 'width' : '10em',
  88. '-moz-box-sizing' : 'border-box'
  89. });
  90. window.scrollTo(0, 0);
  91. $(document).on('keyup', '.filter_rows', function () {
  92. // get the column names
  93. var cols = $('th.column_heading').map(function () {
  94. return $.trim($(this).text());
  95. }).get();
  96. $.uiTableFilter($('#table_columns'), $(this).val(), cols, null, 'td span');
  97. });
  98. $('.edit').click(function () {
  99. var rownum = $(this).parent().data('rownum');
  100. $('#save_' + rownum).show();
  101. $(this).hide();
  102. $('#f_' + rownum + ' td span').hide();
  103. $('#f_' + rownum + ' input, #f_' + rownum + ' select, #f_' + rownum + ' .open_enum_editor').show();
  104. var attribute_val = $('#f_' + rownum + ' td[name=col_attribute] span').html();
  105. $('#f_' + rownum + ' select[name=field_attribute\\[' + rownum + '\\] ] option[value="' + attribute_val + '"]').attr('selected','selected');
  106. if ($('#f_' + rownum + ' .default_type').val() === 'USER_DEFINED') {
  107. $('#f_' + rownum + ' .default_type').siblings('.default_value').show();
  108. } else {
  109. $('#f_' + rownum + ' .default_type').siblings('.default_value').hide();
  110. }
  111. });
  112. $('.del_row').click(function (event) {
  113. event.preventDefault();
  114. event.stopPropagation();
  115. var $td = $(this);
  116. var question = PMA_messages.strDeleteCentralColumnWarning;
  117. $td.PMA_confirm(question, null, function (url) {
  118. var rownum = $td.data('rownum');
  119. $('#del_col_name').val('selected_fld%5B%5D=' + $('#checkbox_row_' + rownum).val());
  120. $('#del_form').submit();
  121. });
  122. });
  123. $('.edit_cancel_form').click(function (event) {
  124. event.preventDefault();
  125. event.stopPropagation();
  126. var rownum = $(this).data('rownum');
  127. $('#save_' + rownum).hide();
  128. $('#edit_' + rownum).show();
  129. $('#f_' + rownum + ' td span').show();
  130. $('#f_' + rownum + ' input, #f_' + rownum + ' select,#f_' + rownum + ' .default_value, #f_' + rownum + ' .open_enum_editor').hide();
  131. $('#tableslistcontainer').find('.checkall').show();
  132. });
  133. $('.edit_save_form').click(function (event) {
  134. event.preventDefault();
  135. event.stopPropagation();
  136. var rownum = $(this).data('rownum');
  137. $('#f_' + rownum + ' td').each(function () {
  138. if ($(this).attr('name') !== 'undefined') {
  139. $(this).find(':input[type!="hidden"],select:first')
  140. .attr('name', $(this).attr('name'));
  141. }
  142. });
  143. if ($('#f_' + rownum + ' .default_type').val() === 'USER_DEFINED') {
  144. $('#f_' + rownum + ' .default_type').attr('name','col_default_sel');
  145. } else {
  146. $('#f_' + rownum + ' .default_value').attr('name','col_default_val');
  147. }
  148. var datastring = $('#f_' + rownum + ' :input').serialize();
  149. $.ajax({
  150. type: 'POST',
  151. url: 'db_central_columns.php',
  152. data: datastring + PMA_commonParams.get('arg_separator') + 'ajax_request=true',
  153. dataType: 'json',
  154. success: function (data) {
  155. if (data.message !== '1') {
  156. PMA_ajaxShowMessage(
  157. '<div class="error">' +
  158. data.message +
  159. '</div>',
  160. false
  161. );
  162. } else {
  163. $('#f_' + rownum + ' td input[id=checkbox_row_' + rownum + ']').val($('#f_' + rownum + ' input[name=col_name]').val()).html();
  164. $('#f_' + rownum + ' td[name=col_name] span').text($('#f_' + rownum + ' input[name=col_name]').val()).html();
  165. $('#f_' + rownum + ' td[name=col_type] span').text($('#f_' + rownum + ' select[name=col_type]').val()).html();
  166. $('#f_' + rownum + ' td[name=col_length] span').text($('#f_' + rownum + ' input[name=col_length]').val()).html();
  167. $('#f_' + rownum + ' td[name=collation] span').text($('#f_' + rownum + ' select[name=collation]').val()).html();
  168. $('#f_' + rownum + ' td[name=col_attribute] span').text($('#f_' + rownum + ' select[name=col_attribute]').val()).html();
  169. $('#f_' + rownum + ' td[name=col_isNull] span').text($('#f_' + rownum + ' input[name=col_isNull]').is(':checked') ? 'Yes' : 'No').html();
  170. $('#f_' + rownum + ' td[name=col_extra] span').text($('#f_' + rownum + ' input[name=col_extra]').is(':checked') ? 'auto_increment' : '').html();
  171. $('#f_' + rownum + ' td[name=col_default] span').text($('#f_' + rownum + ' :input[name=col_default]').val()).html();
  172. }
  173. $('#save_' + rownum).hide();
  174. $('#edit_' + rownum).show();
  175. $('#f_' + rownum + ' td span').show();
  176. $('#f_' + rownum + ' input, #f_' + rownum + ' select,#f_' + rownum + ' .default_value, #f_' + rownum + ' .open_enum_editor').hide();
  177. $('#tableslistcontainer').find('.checkall').show();
  178. },
  179. error: function () {
  180. PMA_ajaxShowMessage(
  181. '<div class="error">' +
  182. PMA_messages.strErrorProcessingRequest +
  183. '</div>',
  184. false
  185. );
  186. }
  187. });
  188. });
  189. $('#table-select').change(function (e) {
  190. var selectvalue = $(this).val();
  191. var default_column_select = $('#column-select').find('option:first');
  192. var href = 'db_central_columns.php';
  193. var params = {
  194. 'ajax_request' : true,
  195. 'server' : PMA_commonParams.get('server'),
  196. 'db' : PMA_commonParams.get('db'),
  197. 'selectedTable' : selectvalue,
  198. 'populateColumns' : true
  199. };
  200. $('#column-select').html('<option value="">' + PMA_messages.strLoading + '</option>');
  201. if (selectvalue !== '') {
  202. $.post(href, params, function (data) {
  203. $('#column-select').empty().append(default_column_select);
  204. $('#column-select').append(data.message);
  205. });
  206. }
  207. });
  208. $('#column-select').change(function (e) {
  209. var selectvalue = $(this).val();
  210. if (selectvalue !== '') {
  211. $('#add_column').submit();
  212. }
  213. });
  214. $('#add_col_div').find('>a').click(function (event) {
  215. $('#add_new').slideToggle('slow');
  216. var $addColDivLinkSpan = $('#add_col_div').find('>a span');
  217. if ($addColDivLinkSpan.html() === '+') {
  218. $addColDivLinkSpan.html('-');
  219. } else {
  220. $addColDivLinkSpan.html('+');
  221. }
  222. });
  223. $('#add_new').submit(function (event) {
  224. $('#add_new').toggle();
  225. });
  226. $('#tableslistcontainer').find('select.default_type').change(function () {
  227. if ($(this).val() === 'USER_DEFINED') {
  228. $(this).siblings('.default_value').attr('name','col_default');
  229. $(this).attr('name','col_default_sel');
  230. } else {
  231. $(this).attr('name','col_default');
  232. $(this).siblings('.default_value').attr('name','col_default_val');
  233. }
  234. });
  235. });