/** * Alpus Patcher Admin JS * * @since 1.3.0 */ jQuery( document ).ready( function( $ ) { 'use strict'; $( '#patch-apply:not(.inactive)' ).on( 'click', function( e ) { e.preventDefault(); $( '#patcher-tbody' ).addClass( 'loading' ).append( '' ); $( '.alpus-patch-layout .button' ).attr( 'disabled', true ); $.ajax( { url: alpus_admin_vars.ajax_url, type: 'POST', data: { 'action': 'alpus_apply_patches', 'nonce': alpus_admin_vars.nonce, }, success: function( response ) { $( '.apply-alert' ).remove(); if ( response.success ) { if ( response.data ) { var update_patches = response.data.update, delete_patches = response.data.delete; if ( 'object' == typeof update_patches ) { update_patches = Object.keys( update_patches ); update_patches.forEach( patch => { $( '[data-path="update-' + patch ).remove(); } ); } if ( 'object' == typeof delete_patches ) { delete_patches = Object.keys( delete_patches ); delete_patches.forEach( patch => { $( '[data-path="delete-' + patch ).remove(); } ); } } if ( response.data.error ) { console.log( response.data ); $( '.alpus-patch-table-main' ).prepend( '

' + wp.i18n.__( 'The below patches could not be applied. Because your files have write permission or aren\'t existed.', 'alpus' ) + '

' ); } else { $( '.alpus-patch-table-main' ).prepend( '

' + wp.i18n.__( 'All files patched successfully.', 'alpus' ) + '

' ); // Remove Apply Patch Button $('.action-footer .button-primary').remove(); // Change Patch Status Icon $('.alpus-patch-log:not(.alpus-patch-applied) svg:first-child').css('display', 'none'); $('.alpus-patch-log:not(.alpus-patch-applied) svg:nth-child(2)').css('display', 'block'); // Update Changelog Style. $('.alpus-patch-log:not(alpus-patch-applied)').addClass('alpus-patch-applied'); } } else { $( '.alpus-patch-table-main' ).prepend( '

' + wp.i18n.__( 'The API server could not be reached.', 'alpus' ) + '

' ); } $( '#patcher-tbody' ).removeClass( 'loading' ).find( '.alpus-ajax-loader' ).remove(); $( '.alpus-patch-layout .button' ).removeAttr( 'disabled' ); }, } ); } ) } );