jQuery(document).ready(function($){ var btnBackup = $('#atlex_tools').find('input#backup'); var btnRestore = $('#atlex_tools').find('input#restore'); var btnDelete = $('#atlex_tools').find('input#delete'); var archiveList = $("#sql_archive"); var btnUpload = $('#atlex_tools').find('input#upload_dir'); var btnDownload = $('#atlex_tools').find('input#download_dir'); var btnDeleteDir = $('#atlex_tools').find('input#delete_dir'); var dirsList = $("#dirs_archive"); var btnSyncStart = $('#atlex_tools').find('input#sync'); function loadArchive( path ){ archiveList.children().remove(); archiveList.append(new Option(atlexOptions.msg_loading + '...', '')); $.ajax({ url: atlexOptions.ajax_url, type: 'POST', data: { nonce: atlexOptions.nonce, action: 'atlex_ajax_load_archives', path: path, }, success: function (result) { var res = jQuery.parseJSON(result); if(res.error != undefined){ alert(res.error) } else { archiveList.children().remove(); $.each(res.archives, function (i, data) { archiveList.append(new Option(data.name, data.path)); }); } }, error: function (response) { alert(response.statusText); } }); } function loadDirs( path ){ dirsList.children().remove(); dirsList.append(new Option(atlexOptions.msg_loading + '...', '')); $.ajax({ url: atlexOptions.ajax_url, type: 'POST', data: { nonce: atlexOptions.nonce, action: 'atlex_ajax_load_dirs', path: path, }, success: function (result) { var res = jQuery.parseJSON(result); if(res.error != undefined){ alert(res.error) } else { dirsList.children().remove(); $.each(res.archives, function (i, data) { dirsList.append(new Option(data.name, data.path)); }); } }, error: function (response) { alert(response.statusText); } }); } loadArchive(atlexOptions.path_sql_container); loadDirs(atlexOptions.path_dir_container); archiveList.on('change',function() { btnRestore.removeAttr('disabled'); btnDelete.removeAttr('disabled'); }); dirsList.on('change',function() { btnDownload.removeAttr('disabled'); btnDeleteDir.removeAttr('disabled'); }); btnSyncStart.on('click',function(e){ btnSyncStart.attr('disabled','disabled'); $('#atlex_tools').find('img#sync_loading').show(); $.ajax({ url: atlexOptions.ajax_url, type: 'POST', data: { nonce: atlexOptions.nonce, action: 'atlex_ajax_mediafiles_upload', }, success: function (result) { btnSyncStart.removeAttr('disabled'); $('#atlex_tools').find('img#sync_loading').hide(); }, error: function (response) { alert(response.statusText); } }); }); btnBackup.on('click',function(e){ btnBackup.attr('disabled','disabled'); btnRestore.attr('disabled','disabled'); btnDelete.attr('disabled','disabled'); archiveList.attr('disabled','disabled'); var name = $('#atlex_tools').find('input#archive_name').val(); $('#atlex_tools').find('img#backup_loading').show(); //alert(atlexOptions.ajax_url) $.ajax({ url: atlexOptions.ajax_url, type: 'POST', data: { nonce: atlexOptions.nonce, action: 'atlex_ajax_archive_create', name: name, }, success: function (result) { var res = jQuery.parseJSON(result); if(res.error != undefined){ alert(res.error) } loadArchive(atlexOptions.path_sql_container); btnBackup.removeAttr('disabled'); archiveList.removeAttr('disabled'); $('#atlex_tools').find('img#backup_loading').hide(); }, error: function (response) { alert(response.statusText); } }); }); btnDelete.on('click',function(e){ if(confirm(atlexOptions.msg_sql_delete)) { btnRestore.attr('disabled', 'disabled'); btnDelete.attr('disabled', 'disabled'); archiveList.attr('disabled', 'disabled'); var path = archiveList.val(); $.ajax({ url: atlexOptions.ajax_url, type: 'POST', data: { nonce: atlexOptions.nonce, action: 'atlex_ajax_archive_delete', path: path, }, success: function (result) { var res = jQuery.parseJSON(result); if(res.error != undefined){ alert(res.error) } loadArchive(atlexOptions.path_sql_container); archiveList.removeAttr('disabled'); }, error: function (response) { alert(response.statusText); } }); } }); btnRestore.on('click',function(e){ if(confirm(atlexOptions.msg_sql_restore)) { btnBackup.attr('disabled', 'disabled'); btnRestore.attr('disabled', 'disabled'); btnDelete.attr('disabled', 'disabled'); archiveList.attr('disabled', 'disabled'); $('#atlex_tools').find('img#backup_loading').show(); var path = archiveList.val(); $.ajax({ url: atlexOptions.ajax_url, type: 'POST', data: { nonce: atlexOptions.nonce, action: 'atlex_ajax_archive_restore', path: path, }, success: function (result) { var res = jQuery.parseJSON(result); if(res.error != undefined){ alert(res.error) } loadArchive(atlexOptions.path_sql_container); archiveList.removeAttr('disabled'); btnBackup.removeAttr('disabled'); $('#atlex_tools').find('img#backup_loading').hide(); }, error: function (response) { alert(response.statusText); } }); } }); btnUpload.on('click',function(e){ btnUpload.attr('disabled','disabled'); btnDeleteDir.attr('disabled','disabled'); btnDownload.attr('disabled','disabled'); dirsList.attr('disabled','disabled'); var object_name = $('#atlex_tools').find('input#object_name').val(); var path = $('#atlex_tools').find('input#dir_name').val(); $('#atlex_tools').find('img#dir_loading').show(); $.ajax({ url: atlexOptions.ajax_url, type: 'POST', data: { nonce: atlexOptions.nonce, action: 'atlex_ajax_dir_upload', object_name: object_name, path: path, }, success: function (result) { var res = jQuery.parseJSON(result); if(res.error != undefined){ alert(res.error) } loadDirs(atlexOptions.path_dir_container); btnUpload.removeAttr('disabled'); dirsList.removeAttr('disabled'); $('#atlex_tools').find('img#dir_loading').hide(); }, error: function (response) { alert(response.statusText); } }); }); btnDeleteDir.on('click',function(e){ if(confirm(atlexOptions.msg_dir_delete)) { btnDownload.attr('disabled', 'disabled'); btnDeleteDir.attr('disabled', 'disabled'); dirsList.attr('disabled', 'disabled'); var path = dirsList.val(); $.ajax({ url: atlexOptions.ajax_url, type: 'POST', data: { nonce: atlexOptions.nonce, action: 'atlex_ajax_archive_delete', path: path, }, success: function (result) { var res = jQuery.parseJSON(result); if(res.error != undefined){ alert(res.error) } loadDirs(atlexOptions.path_dir_container); dirsList.removeAttr('disabled'); }, error: function (response) { alert(response.statusText); } }); } }); btnDownload.on('click',function(e){ btnUpload.attr('disabled', 'disabled'); btnDownload.attr('disabled', 'disabled'); btnDeleteDir.attr('disabled', 'disabled'); dirsList.attr('disabled', 'disabled'); $('#atlex_tools').find('img#dir_loading').show(); var path = dirsList.val(); $.ajax({ url: atlexOptions.ajax_url, type: 'POST', data: { nonce: atlexOptions.nonce, action: 'atlex_ajax_dir_download', path: path, }, success: function (result) { btnUpload.removeAttr('disabled'); btnDownload.removeAttr('disabled'); btnDeleteDir.removeAttr('disabled'); dirsList.removeAttr('disabled'); $('#atlex_tools').find('img#dir_loading').hide(); var res = jQuery.parseJSON(result); if(res.error != undefined){ alert(res.error) }else { alert(atlexOptions.msg_success_download) } }, error: function (response) { alert(response.statusText); } }); }); });