let btn_select_field_all_trans = $('#btn_select_all_trans'), btn_select_field_single_trans = $('#btn_select_one_trans'), btn_unselect_field_all_trans = $('#btn_unselect_all_trans'), btn_unselect_field_single_trans = $('#btn_unselect_one_trans'), select_fields_available_trans = $('#export_trans_available_fields_trans'), select_fields_selected_trans = $('#export_trans_selected_fields_trans') btn_submit_modal_export_trans = $('#modalExportTransFile_submit'), selected_ids = [] ; function btnManagementTrans(){ let available_options_trans = $('#export_trans_available_fields_trans option'), selected_options_trans = $('#export_trans_selected_fields_trans option'), available_length_selected_trans = $('#export_trans_available_fields_trans option:selected').length, selected_length_selected_trans = $('#export_trans_selected_fields_trans option:selected').length ; if(0 < available_options_trans.length){ $(btn_select_field_all_trans).removeClass('disabled'); } else { $(btn_select_field_all_trans).removeClass('disabled'); $(btn_select_field_all_trans).addClass('enabled'); } if(0 < selected_options_trans.length){ $(btn_unselect_field_all_trans).removeClass('disabled'); $(btn_submit_modal_export_trans).removeClass('disabled'); } else { $(btn_unselect_field_all_trans).addClass('disabled'); $(btn_submit_modal_export_trans).addClass('disabled'); } if(0 < available_length_selected_trans){ $(btn_select_field_single_trans).removeClass('disabled'); } else { $(btn_select_field_single_trans).addClass('disabled'); } if(0 < selected_length_selected_trans){ $(btn_unselect_field_single_trans).removeClass('disabled'); } else { $(btn_unselect_field_single_trans).addClass('disabled'); } $(available_options_trans).unbind('click'); $(available_options_trans).bind('click',function() { btnManagementTrans(); }); $(selected_options_trans).unbind('click'); $(selected_options_trans).bind('click',function() { btnManagementTrans(); }); $(btn_submit_modal_export_trans).unbind('click'); let has_clicked = false $(btn_submit_modal_export_trans).bind('click', function () { if(!has_clicked){ has_clicked = true; let btn_initial_state = $(this).html(); let data = { 'fields':[], 'selection_only': $('#export_selection_only_trans').is(':checked'), 'selected_ids' : selected_ids, 'separator': $('#export_separator_trans').val(), 'charset': $('#export_charset_trans').val(), 'file_format': $('#export_file_format_trans').val(), 'token' : "{{ csrf_token('app_export') }}", 'code_export' : 'export_kb_trans' } let selected_fields = $('#export_trans_selected_fields_trans option'); $(selected_fields).each(function(){ let value = $(this).val(); data.fields.push(value); }); $(btn_submit_modal_export_trans).html(btn_spin); $.ajax({ url: "{{ url('app_export') }}", data: data, method: 'POST', xhr:function(){ var xhr = new XMLHttpRequest(); xhr.responseType = 'blob' return xhr; }, success: function (response,status, headers) { const regex = /filename=(.*?)$/g let content_disposition = headers.getResponseHeader('Content-Disposition'); let search = regex.exec(content_disposition); const url = window.URL.createObjectURL(response); const a = document.createElement('a'); a.style.display = 'none'; a.href = url; a.download = (search.length >= 1) ? search[1] : 'export.xlsx'; document.body.appendChild(a); a.click(); window.URL.revokeObjectURL(url); $(btn_submit_modal_export_trans).html(btn_initial_state); $('#modalExportTransFile').foundation('close'); has_clicked = false; } }); } }); } btnManagementTrans(); $(btn_select_field_all_trans).click(function(){ let btn = this; if(!$(btn).hasClass('disabled')){ let available_options_trans = $('#export_trans_available_fields_trans option'); $(available_options_trans).each(function(){ selectOptionTrans(this); }); btnManagementTrans(); } }); $(btn_select_field_single_trans).click(function(){ let btn = this; if(!$(btn).hasClass('disabled')){ let available_fields = $('#export_trabs_available_fields_trans option:selected'); $(available_fields).each(function(){ selectOptionTrans(this); }); btnManagementTrans(); } }); $(btn_unselect_field_all_trans).click(function(){ let btn = this; if(!$(btn).hasClass('disabled')){ let selected_fields = $('#export_trans_selected_fields_trans option'); $(selected_fields).each(function(){ unselectOptionTrans(this); }); btnManagementTrans(); } }); $(btn_unselect_field_single_trans).click(function(){ let btn = this; if(!$(btn).hasClass('disabled')){ let selected_fields = $('#export_trans_selected_fields_trans option:selected'); $(selected_fields).each(function(){ unselectOptionTrans(this); }); btnManagementTrans(); } }); function selectOptionTrans(option){ $(option).detach().appendTo(select_fields_selected_trans); } function unselectOptionTrans(option){ $(option).detach().appendTo(select_fields_available_trans); }