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").unbind('click');
21 $(".edit_save_form").unbind('click');
22 $('.edit_cancel_form').unbind('click');
23 $(".del_row").unbind('click');
24 $(document).off("keyup", ".filter_rows");
25 $('.edit_cancel_form').unbind('click');
26 $('#table-select').unbind('change');
27 $('#column-select').unbind('change');
28 $("#add_col_div>a").unbind('click');
29 $('#add_new').unbind('submit');
30 $('#multi_edit_central_columns').unbind('submit');
31 $("select.default_type").unbind('change');
32 $("button[name='delete_central_columns']").unbind('click');
33 $("button[name='edit_central_columns']").unbind('click');
36 AJAX.registerOnload('db_central_columns.js', function () {
37 $('#tableslistcontainer input,#tableslistcontainer select,#tableslistcontainer .default_value,#tableslistcontainer .open_enum_editor').hide();
38 $('#tableslistcontainer .checkall').show();
39 $('#tableslistcontainer .checkall_box').show();
40 if ($('#table_columns tbody tr').length > 0) {
41 $("#table_columns").tablesorter({
44 1: {sorter: false}, // hidden column
45 4: {sorter: "integer"}
49 $('#tableslistcontainer 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 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 editColumnData = editColumnList+ '&edit_central_columns_page=true&ajax_request=true&ajax_page_request=true&token='+PMA_commonParams.get('token')+'&db='+PMA_commonParams.get('db');
68 PMA_ajaxShowMessage();
69 AJAX.source = $(this);
70 $.get('db_central_columns.php', editColumnData, AJAX.responseHandler);
72 $('#multi_edit_central_columns').submit(function(event){
73 event.preventDefault();
74 event.stopPropagation();
75 var multi_column_edit_data = $("#multi_edit_central_columns").serialize()+'&multi_edit_central_column_save=true&ajax_request=true&ajax_page_request=true&token='+PMA_commonParams.get('token')+'&db='+PMA_commonParams.get('db');
76 PMA_ajaxShowMessage();
77 AJAX.source = $(this);
78 $.post('db_central_columns.php', multi_column_edit_data, AJAX.responseHandler);
80 $('#add_new td').each(function(){
81 if ($(this).attr('name') !== 'undefined') {
82 $(this).find('input,select:first').attr('name', $(this).attr('name'));
85 $("#add_new #field_0_0").attr('required','required');
86 $('#add_new input[type="text"], #add_new input[type="number"], #add_new select')
89 '-moz-box-sizing' : 'border-box'
91 window.scrollTo(0, 0);
92 $(document).on("keyup", ".filter_rows", function () {
93 // get the column names
94 var cols = $('th.column_heading').map(function () {
95 return $.trim($(this).text());
97 $.uiTableFilter($("#table_columns"), $(this).val(), cols, null, "td span");
99 $('.edit').click(function() {
100 var rownum = $(this).parent().data('rownum');
101 $('#save_' + rownum).show();
103 $('#f_' + rownum + ' td span').hide();
104 $('#f_' + rownum + ' input, #f_' + rownum + ' select, #f_' + rownum + ' .open_enum_editor').show();
105 var attribute_val = $('#f_' + rownum + ' td[name=col_attribute] span').html();
106 $('#f_' + rownum + ' select[name=field_attribute\\['+ rownum +'\\] ] option[value="' + attribute_val + '"]').attr("selected","selected");
107 if($('#f_' + rownum + ' .default_type').val() === 'USER_DEFINED') {
108 $('#f_' + rownum + ' .default_type').siblings('.default_value').show();
110 $('#f_' + rownum + ' .default_type').siblings('.default_value').hide();
113 $(".del_row").click(function (event) {
114 event.preventDefault();
115 event.stopPropagation();
117 var question = PMA_messages.strDeleteCentralColumnWarning;
118 $td.PMA_confirm(question, null, function (url) {
119 var rownum = $td.data('rownum');
120 $("#del_col_name").val("selected_fld%5B%5D="+$('#checkbox_row_' + rownum ).val());
121 $("#del_form").submit();
124 $('.edit_cancel_form').click(function(event) {
125 event.preventDefault();
126 event.stopPropagation();
127 var rownum = $(this).data('rownum');
128 $('#save_' + rownum).hide();
129 $('#edit_' + rownum).show();
130 $('#f_' + rownum + ' td span').show();
131 $('#f_' + rownum + ' input, #f_' + rownum + ' select,#f_'+rownum+' .default_value, #f_' + rownum + ' .open_enum_editor').hide();
132 $('#tableslistcontainer .checkall').show();
134 $('.edit_save_form').click(function(event) {
136 event.preventDefault();
137 event.stopPropagation();
138 var rownum = $(this).data('rownum');
139 $('#f_' + rownum + ' td').each(function() {
140 if ($(this).attr('name') !== 'undefined') {
141 $(this).find(':input[type!="hidden"],select:first')
142 .attr('name', $(this).attr('name'));
145 if($('#f_' + rownum + ' .default_type').val() === 'USER_DEFINED') {
146 $('#f_' + rownum + ' .default_type').attr('name','col_default_sel');
148 $('#f_' + rownum + ' .default_value').attr('name','col_default_val');
151 var datastring = $('#f_' + rownum + ' :input').serialize();
152 //console.log(datastring);
155 url: "db_central_columns.php",
156 data: datastring+'&ajax_request=true',
158 success: function(data) {
159 if (data.message !== '1') {
161 '<div class="error">' +
167 $('#f_' + rownum + ' td[name=col_name] span').text($('#f_' + rownum + ' input[name=col_name]').val()).html();
168 $('#f_' + rownum + ' td[name=col_type] span').text($('#f_' + rownum + ' select[name=col_type]').val()).html();
169 $('#f_' + rownum + ' td[name=col_length] span').text($('#f_' + rownum + ' input[name=col_length]').val()).html();
170 $('#f_' + rownum + ' td[name=collation] span').text($('#f_' + rownum + ' select[name=collation]').val()).html();
171 $('#f_' + rownum + ' td[name=col_attribute] span').text($('#f_' + rownum + ' select[name=col_attribute]').val()).html();
172 $('#f_' + rownum + ' td[name=col_isNull] span').text($('#f_' + rownum +' input[name=col_isNull]').is(":checked")?"Yes":"No").html();
173 $('#f_' + rownum + ' td[name=col_extra] span').text($('#f_' + rownum + ' input[name=col_extra]').is(":checked") ? "auto_increment" : "").html();
174 $('#f_' + rownum + ' td[name=col_default] span').text($('#f_' + rownum + ' :input[name=col_default]').val()).html();
176 $('#save_' + rownum).hide();
177 $('#edit_' + rownum).show();
178 $('#f_' + rownum + ' td span').show();
179 $('#f_' + rownum + ' input, #f_' + rownum + ' select,#f_' + rownum + ' .default_value, #f_' + rownum + ' .open_enum_editor').hide();
180 $('#tableslistcontainer .checkall').show();
184 '<div class="error">' +
185 PMA_messages.strErrorProcessingRequest +
192 $('#table-select').change(function(e) {
193 var selectvalue = $(this).val();
194 var default_column_select = $('#column-select option:first');
195 var href = "db_central_columns.php";
197 'ajax_request' : true,
198 'token' : PMA_commonParams.get('token'),
199 'server' : PMA_commonParams.get('server'),
200 'db' : PMA_commonParams.get('db'),
201 'selectedTable' : selectvalue,
202 'populateColumns' : true
204 $('#column-select').html('<option value="">' + PMA_messages.strLoading + '</option>');
205 if (selectvalue !== "") {
206 $.post(href, params, function (data) {
207 $('#column-select').empty().append(default_column_select);
208 $('#column-select').append(data.message);
212 $('#column-select').change(function(e) {
213 var selectvalue = $(this).val();
214 if (selectvalue !== "") {
215 $("#add_column").submit();
218 $("#add_col_div>a").click(function(event){
219 $('#add_new').slideToggle("slow");
220 if($("#add_col_div>a span").html() === '+') {
221 $("#add_col_div>a span").html('-');
223 $("#add_col_div>a span").html('+');
226 $('#add_new').submit(function(event){
227 $('#add_new').toggle();
229 $("#tableslistcontainer select.default_type").change(function () {
230 if ($(this).val() === 'USER_DEFINED') {
231 $(this).siblings('.default_value').attr('name','col_default');
232 $(this).attr('name','col_default_sel');
234 $(this).attr('name','col_default');
235 $(this).siblings('.default_value').attr('name','col_default_val');