(function( $ ) { /** * The list table used on the current page. * plugins.php : .wp-list-table.plugins * update-core.php : #update-plugins-table * @type {Object} */ const $listTable = $( '#update-plugins-table,.wp-list-table.plugins' ); /** * Class representing a single plugin in the context of a list table of plugin updates. * * @param {object} data * @param {Plugin|undefined} parent * @constructor */ const Plugin = function( data, parent ) { /** * Data provided by the server. * @type {Object} */ this.data = data; /** * Parent Plugin instance, if representing an add-on. * @type {Plugin|undefined} */ this.parent = parent; /** * Object for the checkbox allowing the plugin to be submitted for update. * @type {Object} jQuery */ this.$check = $listTable.find( '.check-column [value="' + data.basename + '"]' ); /** * Object for the primary list table row for this plugin. * @type {Object} jQuery */ this.$row = this.$check.closest( 'tr' ); /** * Object for the container which holds update notices for this plugin. * This container represents the main difference between the two list tables. * * This property is only initialized for plugins with license errors. * * @type {Object} jQuery */ this.$noticeContainer = null; }; /** * Get the html for this plugin's check license again link. * * @returns {string} */ Plugin.prototype.checkAgainLink = function() { return ' ' + as3cf_dbrains.strings.check_licence_again + ''; }; /** * Does this plugin have any errors for its license? * * @returns {boolean} */ Plugin.prototype.hasLicenseErrors = function() { const license = this.isAddon() ? this.parent.data.license : this.data.license; return !_.isEmpty( license.errors ); }; /** * Disable the plugin's list table checkbox. */ Plugin.prototype.disableUpdateCheckbox = function() { if ( $listTable.is( '#update-plugins-table' ) ) { this.$check.prop( { disabled: true, checked: false } ); } }; /** * Enable the plugin's list table checkbox. */ Plugin.prototype.enableUpdateCheckbox = function() { if ( $listTable.is( '#update-plugins-table' ) ) { this.$check.prop( { disabled: false } ); } }; /** * Set the update notice with the given html. * * @param {string} html */ Plugin.prototype.setNotice = function( html ) { this.$noticeContainer.find( '.as3cf-licence-notice' ).remove(); this.$noticeContainer.append( '
' ); }; /** * Fade out our license notice and remove it, then restore WP update notices, if any. */ Plugin.prototype.clearNotice = function() { const plugin = this; const $notice = this.$noticeContainer.find( '.as3cf-licence-notice' ); $.when( $notice.fadeOut() ).done( function() { $notice.remove(); plugin.$row.children().css( 'box-shadow', '' ); plugin.$noticeContainer.find( '.update-message' ).show(); } ); }; /** * Render the plugin's state to the DOM. */ Plugin.prototype.render = function() { if ( this.hasLicenseErrors() ) { this.initNoticeContainer(); this.disableUpdateCheckbox(); this.$noticeContainer.find( '.update-message:not(".as3cf-licence-notice")' ).hide(); this.setNotice( this.getLicenseNotice() ); } else if ( this.$noticeContainer ) { this.enableUpdateCheckbox(); this.clearNotice(); } if ( !this.isAddon() ) { _.invoke( this.addons, 'render' ); } }; /** * Initialize the notice container. */ Plugin.prototype.initNoticeContainer = function() { if ( this.$noticeContainer ) { return; } // Check if it is the Plugins update table if ( !$listTable.is( '#update-plugins-table' ) ) { // Check for an existing plugin-update notice row to use. const $noticeRow = $listTable.find( '.plugin-update-tr[data-plugin="' + this.data.basename + '"]' ); if ( $noticeRow.length ) { this.$noticeContainer = $noticeRow.find( '.plugin-update' ); } else { const colspan = this.$row.children().length; // If there is no plugin-update row, the plugin did not have an update, so inject a row to use. this.$row.after( '