8889841cwp-content/plugins/the-events-calendar/src/resources/js/custom-tables-v1/ct1-upgrade.min.js000064400000016645150516125250033554 0ustar00home/clixcotz/tcchp.clix.co.tz/** * This JS file was auto-generated via Terser. * * Contributors should avoid editing this file, but instead edit the associated * non minified file file. For more information, check out our engineering docs * on how we handle JS minification in our engineering docs. * * @see: https://evnt.is/dev-docs-minification */ let pastCurrentPage,upcomingCurrentPage,upgradeBoxElement=null,localizedData=null,ajaxUrl=null,pollInterval=5e3,pollTimeoutId=null,currentViewState={poll:!0};export const selectors={upgradeBox:"#tec-ct1-upgrade-dynamic",startPreviewButton:".tec-ct1-upgrade-start-migration-preview",startMigrationButton:".tec-ct1-upgrade-start-migration",cancelMigrationButton:".tec-ct1-upgrade-cancel-migration",revertMigrationButton:".tec-ct1-upgrade-revert-migration",paginateButton:"[data-events-paginate]"};export const buildQueryString=(data={})=>{if(!(data instanceof Object&&!Array.isArray(data)||"string"==typeof data))throw new Error("data must be an object or a string");if("string"==typeof data){const extractedData={};data.split("&").map((keyAndValue=>{const[key,value]=keyAndValue.split("=",2);extractedData[key]=value})),data=extractedData}const queryString=Object.keys(data).map((function(k){return encodeURIComponent(k)+"="+encodeURIComponent(data[k])})).join("&");return queryString?"?"+queryString:""};export const ajaxGet=(url,data={},onSuccess,onFailure,onError)=>{if(!url)return;const compiledUrl=url+buildQueryString(data),request=new XMLHttpRequest;request.open("GET",compiledUrl,!0),request.onreadystatechange=function(){if(request.readyState===XMLHttpRequest.DONE){const status=request.status;if(0===status||status>=200&&status<400)try{onSuccess&&onSuccess(JSON.parse(this.response))}catch(e){onError&&onError(this.response)}else onFailure&&onFailure(this.response)}},request.onerror=function(){onError&&onError()},request.send()};export const getUpgradeBoxElement=()=>document.getElementById(selectors.upgradeBox.substr(1));export const onSuccess=()=>{};export const onFailure=()=>{};export const onError=()=>{};export const recursePollForReport=()=>{syncReportData(pollForReport)};export const shouldPoll=()=>currentViewState.poll||tecCt1Upgrade.forcePolling;export const pollForReport=()=>{(currentViewState.poll||tecCt1Upgrade.forcePolling)&&(pollTimeoutId=setTimeout(recursePollForReport,pollInterval))};export const handleReportData=function(data){const{nodes:nodes,key:key,html:html}=data;"stop"!==key?(currentViewState.key&¤tViewState.key===key||(getUpgradeBoxElement().innerHTML=html,bindNodes(key)),nodes.forEach((node=>{if(isNodeDiff(node.key,node.hash)){let element=document.querySelector(node.target);element&&(node.prepend?element.innerHTML=node.html+element.innerHTML:node.append?element.innerHTML=element.innerHTML+node.html:element.innerHTML=node.html,bindNodes(node.key))}})),currentViewState=data):currentViewState.poll=!1};export const bindNodes=key=>{let element;element=document.querySelectorAll(selectors.startPreviewButton),element&&element.forEach((function(node){node.removeEventListener("click",handleStartMigrationWithPreview),node.addEventListener("click",handleStartMigrationWithPreview)})),element=document.querySelectorAll(selectors.startMigrationButton),element&&element.forEach((function(node){node.removeEventListener("click",handleStartMigration),node.addEventListener("click",handleStartMigration)})),element=document.querySelectorAll(selectors.cancelMigrationButton),element&&element.forEach((function(node){node.removeEventListener("click",handleCancelMigration),node.addEventListener("click",handleCancelMigration)})),element=document.querySelectorAll(selectors.revertMigrationButton),element&&element.forEach((function(node){node.removeEventListener("click",handleRevertMigration),node.addEventListener("click",handleRevertMigration)})),element=document.querySelectorAll(selectors.paginateButton),element&&element.forEach((function(node){node.removeEventListener("click",handlePaginateClick(node)),node.addEventListener("click",handlePaginateClick(node))}))};const handlePaginateClick=node=>e=>{e.preventDefault();const isUpcoming=!!node.dataset.eventsPaginateUpcoming,category=node.dataset.eventsPaginateCategory,defaultPage=node.dataset.eventsPaginateStartPage;isUpcoming?upcomingCurrentPage||(upcomingCurrentPage=defaultPage):pastCurrentPage||(pastCurrentPage=defaultPage);const page=isUpcoming?upcomingCurrentPage++:pastCurrentPage++;ajaxGet(tecCt1Upgrade.ajaxUrl,{action:tecCt1Upgrade.actions.paginateEvents,page:page,upcoming:isUpcoming?1:0,report_category:category,_ajax_nonce:tecCt1Upgrade.nonce},(({html:html,append:append,prepend:prepend,has_more:has_more})=>{const element=document.querySelector(`.tec-ct1-upgrade-events-category-${category}`);if(element.innerHTML=prepend?html+element.innerHTML:append?element.innerHTML+html:html,!has_more){let element=document.querySelector(".tec-ct1-upgrade-migration-pagination-separator");element&&element.remove(),e.target.remove()}}))};export const handleCancelMigration=e=>{e.preventDefault(),confirm(tecCt1Upgrade.text_dictionary.confirm_cancel_migration)&&(e.target.setAttribute("disabled","disabled"),e.target.removeEventListener("click",handleCancelMigration),undoMigration(tecCt1Upgrade.actions.cancelMigration))};export const handleRevertMigration=e=>{e.preventDefault(),confirm(tecCt1Upgrade.text_dictionary.confirm_revert_migration)&&(e.target.setAttribute("disabled","disabled"),e.target.removeEventListener("click",handleRevertMigration),undoMigration(tecCt1Upgrade.actions.revertMigration))};export const undoMigration=action=>{cancelReportPoll(),ajaxGet(tecCt1Upgrade.ajaxUrl,{action:action,_ajax_nonce:tecCt1Upgrade.nonce},(response=>{handleReportData(response),pollForReport()}))};export const handleStartMigrationWithPreview=e=>{e.preventDefault(),e.target.setAttribute("disabled","disabled"),e.target.removeEventListener("click",handleStartMigrationWithPreview),startMigration(!0)};export const handleStartMigration=e=>{e.preventDefault();const message=tecCt1Upgrade.text_dictionary.migration_in_progress_paragraph+" "+tecCt1Upgrade.text_dictionary.migration_prompt_plugin_state_addendum;confirm(message)&&(e.target.setAttribute("disabled","disabled"),e.target.removeEventListener("click",handleStartMigration),startMigration(!1))};export const startMigration=isPreview=>{cancelReportPoll(),ajaxGet(tecCt1Upgrade.ajaxUrl,{action:tecCt1Upgrade.actions.startMigration,tec_events_custom_tables_v1_migration_dry_run:isPreview?1:0,_ajax_nonce:tecCt1Upgrade.nonce},(response=>{handleReportData(response),pollForReport()}))};export const cancelReportPoll=()=>{clearTimeout(pollTimeoutId)};export const isNodeDiff=(searchKey,searchHash)=>{const{nodes:nodes}=currentViewState;if(!nodes)return!0;const node=nodes.find((({key:key})=>key===searchKey));return!node||node.hash!==searchHash};export const syncReportData=function(successCallback=null){getReport((function(response){handleReportData(response),successCallback&&successCallback(response)}))};export const getReport=successCallback=>{var queryArgs={action:tecCt1Upgrade.actions.getReport,_ajax_nonce:tecCt1Upgrade.nonce};tecCt1Upgrade.isMaintenanceMode&&(queryArgs.is_maintenance_mode="1"),ajaxGet(tecCt1Upgrade.ajaxUrl,queryArgs,successCallback)};export const init=()=>{localizedData=window.tecCt1Upgrade,localizedData&&(upgradeBoxElement=getUpgradeBoxElement(),ajaxUrl=localizedData.ajaxUrl,pollInterval=localizedData.pollInterval||pollInterval,0!==pollInterval&&syncReportData(pollForReport))};"loading"!==document.readyState?init():document.addEventListener("DOMContentLoaded",init);