jQuery( document ).ready(function() { var toastr_opt = { closeButton: true, showDuration: 300, hideDuration: 200, hideMethod: "slideUp" } //import from old version jQuery('.njt_fbv_import_from_old_now').on('click', function(){ var $this = jQuery(this) if($this.hasClass('updating-message')) return false; $this.addClass('updating-message') get_folders(function(res) { if(res.success) { insert_folder(res.data.folders, 0, function(){ $this.removeClass('updating-message') setTimeout(() => { var mess = '
' + fbv_data.i18n.filebird_db_updated + '
'; mess += ''+ fbv_data.i18n.go_to_media + ''; toastr.success(mess, '', Object.assign(toastr_opt, {timeOut: 0, extendedTimeOut: 0})) }, 100); if(typeof njt_auto_run_import != 'undefined' && njt_auto_run_import == true) { location.replace(njt_fb_settings_page) } }, function(){ $this.removeClass('updating-message') }) } }, function(){ $this.removeClass('updating-message') toastr.error(fbv_data.i18n.import_failed, '', Object.assign(toastr_opt, {timeOut: 0, extendedTimeOut: 0})) }) function get_folders(onDone, onFail) { jQuery.ajax({ dataType: 'json', contentType: 'application/json', url: fbv_data.json_url + '/fb-get-old-data', method: 'POST', headers: { "X-WP-Nonce": fbv_data.rest_nonce, "X-HTTP-Method-Override": "POST" }, }) .done(function(res){ onDone(res) }) .fail(function(res){ onFail(res) }) } function insert_folder(folders, index, onDone, onFail) { if(typeof folders[index] != 'undefined') { jQuery.ajax({ dataType: 'json', contentType: 'application/json', url: fbv_data.json_url + '/fb-insert-old-data', method: 'POST', headers: { "X-WP-Nonce": fbv_data.rest_nonce, "X-HTTP-Method-Override": "POST" }, data: JSON.stringify({ folders: folders[index], autorun: (typeof njt_auto_run_import != 'undefined') && njt_auto_run_import == true }) }) .done(function(res){ insert_folder(folders, index + 1, onDone, onFail) }) .fail(function(res){ onFail(); toastr.error('Please try again.', '', Object.assign(toastr_opt, {timeOut: 0, extendedTimeOut: 0})) }) } else { onDone() } } }) //wipe old data jQuery('.njt_fbv_wipe_old_data').on('click', function(){ if(!confirm(fbv_data.i18n.are_you_sure)) return false; var $this = jQuery(this) if($this.hasClass('updating-message')) return false; $this.addClass('updating-message') jQuery.ajax({ dataType: 'json', contentType: 'application/json', url: fbv_data.json_url + '/fb-wipe-old-data', method: 'POST', headers: { "X-WP-Nonce": fbv_data.rest_nonce, "X-HTTP-Method-Override": "POST" }, }) .done(function(res){ $this.removeClass('updating-message') toastr.success(res.data.mess, '', toastr_opt) }) .fail(function(res){ $this.removeClass('updating-message') toastr.error(res.data.mess, '', toastr_opt) }) }) //clear all data jQuery('.njt_fbv_clear_all_data').on('click', function(){ if(!confirm(fbv_data.i18n.are_you_sure)) return false; var $this = jQuery(this) if($this.hasClass('updating-message')) return false; $this.addClass('updating-message') jQuery.ajax({ dataType: 'json', contentType: 'application/json', url: fbv_data.json_url + '/fb-wipe-clear-all-data', method: 'POST', headers: { "X-WP-Nonce": fbv_data.rest_nonce, "X-HTTP-Method-Override": "POST" }, }) .done(function(res){ $this.removeClass('updating-message') toastr.success(res.data.mess, '', toastr_opt) }) .fail(function(res){ $this.removeClass('updating-message') toastr.error(res.data.mess, '', toastr_opt) }) }) //no thanks btn jQuery('.njt_fb_no_thanks_btn').on('click', function(){ var $this = jQuery(this); $this.addClass('updating-message') jQuery.ajax({ dataType: 'json', contentType: 'application/json', type: "post", url: fbv_data.json_url + '/fb-no-thanks', headers: { "X-WP-Nonce": fbv_data.rest_nonce, "X-HTTP-Method-Override": "POST" }, data: JSON.stringify({ site: $this.data('site'), }), success: function (res) { $this.removeClass('updating-message'); jQuery('.njt.notice.notice-warning.' + $this.data('site')).hide() } }) .fail(function(res){ $this.removeClass('updating-message'); toastr.error('Please try again later', '', toastr_opt) }); }) jQuery('.njt-fb-import').on('click', function(){ var $this = jQuery(this) $this.addClass('updating-message') jQuery.ajax({ dataType: 'json', contentType: 'application/json', url: fbv_data.json_url + '/fb-import', method: 'POST', headers: { "X-WP-Nonce": fbv_data.rest_nonce, "X-HTTP-Method-Override": "POST" }, data: JSON.stringify({ site: $this.data('site'), count: $this.data('count'), }) }) .done(function(res){ if(res.data.folders) { var folders = res.data.folders var site = res.data.site var count = res.data.count import_site(folders, site, 0, {count: count}, function(res){ if(res.success) { $this.removeClass('updating-message') var html_notice = ''+res.data.mess+'