/** * Array of posts types to index * @type @exp;opSouVars@pro;postTypesToIndex */ var postTypesToIndex = opSouVars.postTypesToIndex || {}; /** * Array of post types with theirs total posts to index * @type @exp;opSouVars@pro;totalPublishedPosts */ var totalPublishedPosts = opSouVars.totalPublishedPosts; /** * Count total posts indexed * @type Number */ var totalPostsIndexed = 0; /** * Count total posts indexed by post type * @type Array */ var totalPostsPerTypeIndexed = {}; var indexPosts = function ( postType, offset ){ offset = offset || 0; var data = { indexPostType: postType, action: opSouVars.ajaxIndexAction, queryOffset: offset, runIndex: 1, _ajax_nonce_index: opSouVars.ajaxIndexNonce }; showProgress( postType, totalPublishedPosts[postType], offset, opSouVars.labels.indexing + opSouVars.labels.postsLabels[postType] ); jQuery.ajax({ url: opSouVars.ajaxUrl, data: data, dataType: 'json', type: 'POST', success: function(response, textStatus) { if(typeof(response) === 'object' && response.error === true){ showError( data.opSouErrorMessage ); }else if( typeof(response) === 'object' && response !== null ) { if ( response['totalIndexed'] ) { totalPostsIndexed += parseInt( response['totalIndexed'] ); totalPostsPerTypeIndexed[postType] += parseInt( response['totalIndexed'] ); } // If something was indexed try with the next page if ( parseInt( response['totalIndexed'] ) > 0 ) { indexPosts( postType, parseInt( offset ) + parseInt( opSouVars.postsPerPage ) ); } else { var nextPostToIndex = getNextPostTypeToIndex( postType ); if( nextPostToIndex ){ indexPosts( nextPostToIndex, 0 ); } else{ processFinished(); } } }else{ showError( opSouVars.labels.indexationError ); } }, error: function(jqXHR, textStatus, errorThrown) { try { errorMsg = JSON.parse(jqXHR.responseText).message; } catch (e) { errorMsg = jqXHR.responseText; } showError(errorMsg); } } ); }; var processFinished = function ( ){ // Indexation is finished so we need to enable the index button jQuery('#opSou_index').removeAttr("disabled"); spinnerHide(); }; function progress( percent, elementId ) { percent = Math.floor( percent ); jQuery( elementId ).progressbar( "value", percent ); } function showProgress( type, totalItems, offset, label ) { var pbarId = '#progressBar_' + type; var pbarHtmlId = 'progressBar_' + type; if( offset === 0 ){ var progressBar = '
' + opSouVars.labels.indexNameChanged + '