var task_retry_times=0; var running_backup_taskid=''; var tmp_current_click_backupid = ''; var m_need_update=true; var m_restore_backup_id; var m_backup_task_id; var m_downloading_file_name = ''; var m_downloading_id = ''; var wpvivid_settings_changed = false; var wpvivid_cur_log_page = 1; var wpvivid_completed_backup = 1; var wpvivid_prepare_backup=false; var wpvivid_restoring=false; var wpvivid_location_href=false; var wpvivid_editing_storage_id = ''; var wpvivid_editing_storage_type = ''; var wpvivid_restore_download_array; var wpvivid_restore_download_index = 0; var wpvivid_get_download_restore_progress_retry = 0; var wpvivid_restore_timeout = false; var wpvivid_restore_need_download = false; var wpvivid_display_restore_backup = false; var wpvivid_restore_backup_type = ''; var wpvivid_display_restore_check = false; var wpvivid_restore_sure = false; var wpvivid_resotre_is_migrate=0; (function ($) { 'use strict'; /** * All of the code for your admin-facing JavaScript source * should reside in this file. * * Note: It has been assumed you will write jQuery code here, so the * $ function reference has been prepared for usage within the scope * of this function. * * This enables you to define handlers, for when the DOM is ready: * * $(function() { * * }); * * When the window is loaded: * * $( window ).load(function() { * * }); * * ...and/or other possibilities. * * Ideally, it is not considered best practise to attach more than a * single DOM-ready or window-load handler for a particular page. * Although scripts in the WordPress core, Plugins and Themes may be * practising this, we should strive to set a better example in our own work. */ $(document).ready(function () { //wpvivid_getrequest(); wpvivid_interface_flow_control(); $('input[option=review]').click(function(){ var name = jQuery(this).prop('name'); wpvivid_add_review_info(name); }); $(document).on('click', '.notice-rate .notice-dismiss', function(){ var name = 'dismiss'; wpvivid_add_review_info(name); }); $(document).on('click', '.notice-wp-cron .notice-dismiss', function(){ var ajax_data = { 'action': 'wpvivid_hide_wp_cron_notice' }; wpvivid_post_request(ajax_data, function(res){ }, function(XMLHttpRequest, textStatus, errorThrown) { }); }); }); })(jQuery); function wpvivid_popup_tour(style) { var popup = document.getElementById("wpvivid_popup_tour"); if (popup != null) { popup.classList.add(style); } } window.onbeforeunload = function(e) { if (wpvivid_settings_changed) { if (wpvivid_location_href){ wpvivid_location_href = false; } else { return 'You are leaving the page without saving your changes, any unsaved changes on the page will be lost, are you sure you want to continue?'; } } } /** * Refresh the scheduled task list as regularly as a preset interval(3-minute), to retrieve and activate the scheduled cron jobs. */ function wpvivid_activate_cron(){ var next_get_time = 3 * 60 * 1000; wpvivid_cron_task(); setTimeout("wpvivid_activate_cron()", next_get_time); setTimeout(function(){ m_need_update=true; }, 10000); } /** * Send an Ajax request * * @param ajax_data - Data in Ajax request * @param callback - A callback function when the request is succeeded * @param error_callback - A callback function when the request is failed * @param time_out - The timeout for Ajax request */ function wpvivid_post_request(ajax_data, callback, error_callback, time_out){ if(typeof time_out === 'undefined') time_out = 30000; ajax_data.nonce=wpvivid_ajax_object.ajax_nonce; jQuery.ajax({ type: "post", url: wpvivid_ajax_object.ajax_url, data: ajax_data, success: function (data) { callback(data); }, error: function (XMLHttpRequest, textStatus, errorThrown) { error_callback(XMLHttpRequest, textStatus, errorThrown); }, timeout: time_out }); } /** * Check if there are running tasks (backup and download) */ function wpvivid_check_runningtask(){ var ajax_data = { 'action': 'wpvivid_list_tasks', 'backup_id': tmp_current_click_backupid }; if(wpvivid_restoring === false) { wpvivid_post_request(ajax_data, function (data) { setTimeout(function () { wpvivid_manage_task(); }, 3000); try { var jsonarray = jQuery.parseJSON(data); if (jsonarray.success_notice_html != false) { jQuery('#wpvivid_backup_notice').show(); jQuery('#wpvivid_backup_notice').append(jsonarray.success_notice_html); } if(jsonarray.error_notice_html != false){ jQuery('#wpvivid_backup_notice').show(); jQuery.each(jsonarray.error_notice_html, function (index, value) { jQuery('#wpvivid_backup_notice').append(value.error_msg); }); } if(jsonarray.backuplist_html != false) { jQuery('#wpvivid_backup_list').html(''); jQuery('#wpvivid_backup_list').append(jsonarray.backuplist_html); } var b_has_data = false; if (jsonarray.backup.data.length !== 0) { b_has_data = true; task_retry_times = 0; if (jsonarray.backup.result === 'success') { wpvivid_prepare_backup = false; jQuery.each(jsonarray.backup.data, function (index, value) { if (value.status.str === 'ready') { jQuery('#wpvivid_postbox_backup_percent').html(value.progress_html); m_need_update = true; } else if (value.status.str === 'running') { running_backup_taskid = index; wpvivid_control_backup_lock(); jQuery('#wpvivid_postbox_backup_percent').show(); jQuery('#wpvivid_postbox_backup_percent').html(value.progress_html); m_need_update = true; } else if (value.status.str === 'wait_resume') { running_backup_taskid = index; wpvivid_control_backup_lock(); jQuery('#wpvivid_postbox_backup_percent').show(); jQuery('#wpvivid_postbox_backup_percent').html(value.progress_html); if (value.data.next_resume_time !== 'get next resume time failed.') { wpvivid_resume_backup(index, value.data.next_resume_time); } else { wpvivid_delete_backup_task(index); } } else if (value.status.str === 'no_responds') { running_backup_taskid = index; wpvivid_control_backup_lock(); jQuery('#wpvivid_postbox_backup_percent').show(); jQuery('#wpvivid_postbox_backup_percent').html(value.progress_html); m_need_update = true; } else if (value.status.str === 'completed') { jQuery('#wpvivid_postbox_backup_percent').html(value.progress_html); wpvivid_control_backup_unlock(); jQuery('#wpvivid_postbox_backup_percent').hide(); jQuery('#wpvivid_last_backup_msg').html(jsonarray.last_msg_html); jQuery('#wpvivid_loglist').html(""); jQuery('#wpvivid_loglist').append(jsonarray.log_html); wpvivid_log_count = jsonarray.log_count; wpvivid_display_log_page(); running_backup_taskid = ''; m_backup_task_id = ''; m_need_update = true; } else if (value.status.str === 'error') { jQuery('#wpvivid_postbox_backup_percent').html(value.progress_html); wpvivid_control_backup_unlock(); jQuery('#wpvivid_postbox_backup_percent').hide(); jQuery('#wpvivid_last_backup_msg').html(jsonarray.last_msg_html); jQuery('#wpvivid_loglist').html(""); jQuery('#wpvivid_loglist').append(jsonarray.log_html); running_backup_taskid = ''; m_backup_task_id = ''; m_need_update = true; } }); } } else { if(running_backup_taskid !== '') { jQuery('#wpvivid_backup_cancel_btn').css({'pointer-events': 'auto', 'opacity': '1'}); jQuery('#wpvivid_backup_log_btn').css({'pointer-events': 'auto', 'opacity': '1'}); wpvivid_control_backup_unlock(); jQuery('#wpvivid_postbox_backup_percent').hide(); wpvivid_retrieve_backup_list(); wpvivid_retrieve_last_backup_message(); wpvivid_retrieve_log_list(); running_backup_taskid=''; } } /*if (jsonarray.download.length !== 0) { if(jsonarray.download.result === 'success') { b_has_data = true; task_retry_times = 0; var i = 0; var file_name = ''; jQuery('#wpvivid_file_part_' + tmp_current_click_backupid).html(""); var b_download_finish = false; jQuery.each(jsonarray.download.files, function (index, value) { i++; file_name = index; var progress = '0%'; if (value.status === 'need_download') { if (m_downloading_file_name === file_name) { m_need_update = true; } jQuery('#wpvivid_file_part_' + tmp_current_click_backupid).append(value.html); //b_download_finish=true; } else if (value.status === 'running') { if (m_downloading_file_name === file_name) { wpvivid_lock_download(tmp_current_click_backupid); } m_need_update = true; jQuery('#wpvivid_file_part_' + tmp_current_click_backupid).append(value.html); b_download_finish = false; } else if (value.status === 'completed') { if (m_downloading_file_name === file_name) { wpvivid_unlock_download(tmp_current_click_backupid); m_downloading_id = ''; m_downloading_file_name = ''; } jQuery('#wpvivid_file_part_' + tmp_current_click_backupid).append(value.html); b_download_finish = true; } else if (value.status === 'error') { if (m_downloading_file_name === file_name) { wpvivid_unlock_download(tmp_current_click_backupid); m_downloading_id = ''; m_downloading_file_name = ''; } alert(value.error); jQuery('#wpvivid_file_part_' + tmp_current_click_backupid).append(value.html); b_download_finish = true; } else if (value.status === 'timeout') { if (m_downloading_file_name === file_name) { wpvivid_unlock_download(tmp_current_click_backupid); m_downloading_id = ''; m_downloading_file_name = ''; } alert('Download timeout, please retry.'); jQuery('#wpvivid_file_part_' + tmp_current_click_backupid).append(value.html); b_download_finish = true; } }); jQuery('#wpvivid_file_part_' + tmp_current_click_backupid).append(jsonarray.download.place_html); if (b_download_finish == true) { tmp_current_click_backupid = ''; } } else{ b_has_data = true; alert(jsonarray.download.error); } }*/ if (!b_has_data) { task_retry_times++; if (task_retry_times < 5) { m_need_update = true; } } } catch(err){ alert(err); } }, function (XMLHttpRequest, textStatus, errorThrown) { task_retry_times++; if (task_retry_times < 5) { setTimeout(function () { m_need_update = true; wpvivid_manage_task(); }, 3000); } }); } } /** * This function will show the log on a text box. * * @param data - The log message returned by server */ function wpvivid_show_log(data, content_id){ jQuery('#'+content_id).html(""); try { var jsonarray = jQuery.parseJSON(data); if (jsonarray.result === "success") { var log_data = jsonarray.data; while (log_data.indexOf('\n') >= 0) { var iLength = log_data.indexOf('\n'); var log = log_data.substring(0, iLength); log_data = log_data.substring(iLength + 1); var insert_log = "
" + wpvividlion.warning + notice_msg + "
" + "" + "" + wpvividlion.error + notice_msg + "
" + success_msg + "
" + "" + "" + notice_msg + "
" + "" + "