From f083f2e5d668fecfd6774d45ebc5c6a6b40841c2 Mon Sep 17 00:00:00 2001 From: Milan Chaudhary Date: Tue, 4 Jul 2023 17:58:55 +0545 Subject: [PATCH 1/9] Add - Install and Active addon button on builder --- assets/css/admin.scss | 7 +- assets/js/admin/evf-setup.js | 116 ++++++++++++++++++ assets/js/admin/extensions.js | 23 +++- includes/abstracts/class-evf-form-fields.php | 3 +- .../builder/class-evf-builder-fields.php | 8 +- includes/admin/class-evf-admin-assets.php | 7 +- includes/fields/class-evf-field-captcha.php | 2 + .../fields/class-evf-field-credit-card.php | 1 + includes/fields/class-evf-field-likert.php | 2 + .../class-evf-field-payment-authorize-net.php | 3 + .../fields/class-evf-field-payment-coupon.php | 2 + includes/fields/class-evf-field-repeater.php | 2 + .../fields/class-evf-field-scale-rating.php | 2 + includes/fields/class-evf-field-yes-no.php | 2 + 14 files changed, 171 insertions(+), 9 deletions(-) diff --git a/assets/css/admin.scss b/assets/css/admin.scss index a37c89cb4..4162738b0 100644 --- a/assets/css/admin.scss +++ b/assets/css/admin.scss @@ -2159,9 +2159,12 @@ p.search-box { display: block; margin: 0 auto; } - + &.evf-upgrade-addon { + cursor: not-allowed; + } &.upgrade-modal, - &.enable-stripe-model, + &.evf-upgrade-addon, + &.enable-stripe-model, &.enable-authorize-net-model { opacity: 0.45; } diff --git a/assets/js/admin/evf-setup.js b/assets/js/admin/evf-setup.js index bb26db26e..075db758f 100644 --- a/assets/js/admin/evf-setup.js +++ b/assets/js/admin/evf-setup.js @@ -14,6 +14,20 @@ jQuery( function( $ ) { $( document ).on( 'click', '.everest-forms-template-install-addon', this.install_addon ); $( document ).on( 'click', '.everest-forms-builder-setup .upgrade-modal', this.message_upgrade ); $( document ).on( 'click', '.everest-forms-builder-setup .evf-template-preview', this.template_preview ); + $(document).on('click', '.activate-now', function(e) { + e.preventDefault(); + if(!$(this).closest('body.everest-forms_page_evf-builder').length) { + return; + } + evf_setup_actions.active_addon_from_buidler($(this)); + }); + $(document).on('click', '.install-from-builder', function(e) { + e.preventDefault(); + if(!$(this).closest('body.everest-forms_page_evf-builder').length) { + return; + } + evf_setup_actions.install_now_from_buidler($(this)); + }); // Select and apply a template. this.$setup_form.on( 'click', '.evf-template-select', this.template_select ); @@ -268,6 +282,108 @@ jQuery( function( $ ) { e.preventDefault(); return false; } + }, + active_addon_from_buidler:function( node ) { + var url = $(node).attr("href"); + console.log(url); + $.alert({ + title: evf_setup_params.confirmation_title, + content: false, + theme: 'jconfirm-modern jconfirm-everest-forms', + type:'blue', + backgroundDismiss: false, + scrollToPreviousElement: false, + preOpen:{ + action:function(){ + window.location.replace(url); + } + }, + buttons: { + confirm: { + text: evf_setup_params.save_changes_text, + btnClass:'btn-confirm', + action: function () { + $('.everest-forms-save-button').trigger('click'); + location.reload(); + } + }, + cancel: { + text: evf_setup_params.reload_text, + btnClass:'btn-confirm', + action: function () { + location.reload(); + } + } + }, + }); + }, + install_now_from_buidler:function(event) { + wp.updates.maybeRequestFilesystemCredentials(event); + evf_setup_actions.$button_install = evf_setup_params.i18n_installing; + $(event) + .html( + evf_setup_actions.$button_install + + '
' + ) + .closest("button") + .prop("disabled", true); + + wp.updates.queue.push({ + action: 'everest_forms_install_extension', + data: { + page: pagenow, + name: $(event).data( 'name' ), + slug: $(event).data( 'slug' ) + } + }); + + $(document).on( + "wp-plugin-install-success wp-plugin-install-error", + function (event, response) { + if ( + typeof response.errorMessage !== "undefined" && + response.errorMessage.length > 0 + ) { + $.alert({ + title: response.errorMessage, + content: evf_setup_params.download_failed, + icon: "error", + }); + } else { + if (0 === wp.updates.queue.length) { + $.alert({ + title: evf_setup_params.confirmation_title, + content: false, + theme: 'jconfirm-modern jconfirm-everest-forms', + type:'blue', + backgroundDismiss: false, + scrollToPreviousElement: false, + buttons: { + confirm: { + text: evf_setup_params.save_changes_text, + btnClass:'btn-confirm', + action: function () { + $('.everest-forms-save-button').trigger('click'); + location.reload(); + } + }, + cancel: { + text: evf_setup_params.reload_text, + btnClass:'btn-confirm', + action: function () { + location.reload(); + } + } + }, + boxWidth: '565px', + }); + } + } + } + ); + + // Check the queue, now that the event handlers have been added. + wp.updates.queueChecker(); } }; diff --git a/assets/js/admin/extensions.js b/assets/js/admin/extensions.js index 906881c96..845b73aef 100644 --- a/assets/js/admin/extensions.js +++ b/assets/js/admin/extensions.js @@ -64,7 +64,19 @@ */ wp.updates.installExtensionSuccess = function( response ) { if ( 'everest-forms_page_evf-builder' === pagenow ) { - var $pluginRow = $( 'tr[data-slug="' + response.slug + '"]' ).removeClass( 'install' ).addClass( 'installed' ), + if ( + !$(document).find(".everest-forms-form-template-wrapper") + .length + ) { + wp.a11y.speak( + __("Installation completed successfully."), + "polite" + ); + + $document.trigger("wp-plugin-install-success", response); + $document.trigger("ur-plugin-install-success", response); + } else { + var $pluginRow = $( 'tr[data-slug="' + response.slug + '"]' ).removeClass( 'install' ).addClass( 'installed' ), $updateMessage = $pluginRow.find( '.plugin-status span' ); $updateMessage @@ -84,7 +96,7 @@ $document.trigger( 'wp-plugin-bulk-install-success', response ); - + } } else { var $message = $( '.plugin-card-' + response.slug ).find( '.install-now' ), $status = $( '.plugin-card-' + response.slug ).find( '.status-label' ); @@ -157,6 +169,11 @@ */ wp.updates.installExtensionError = function( response ) { if ( 'everest-forms_page_evf-builder' === pagenow ) { + if(!$(document).find(".everest-forms-form-template-wrapper") + .length + ) { + return; + } var $pluginRow = $( 'tr[data-slug="' + response.slug + '"]' ), $updateMessage = $pluginRow.find( '.plugin-status span' ), errorMessage; @@ -165,7 +182,7 @@ return; } - if ( wp.updates.maybeHandleCredentialError( response, 'install-plugin' ) ) { + if ( wp.updates.maybeHandleCredentialError( response, 'install-plugin' ) ) { return; } diff --git a/includes/abstracts/class-evf-form-fields.php b/includes/abstracts/class-evf-form-fields.php index 7f9d7d088..25e806c63 100644 --- a/includes/abstracts/class-evf-form-fields.php +++ b/includes/abstracts/class-evf-form-fields.php @@ -87,7 +87,8 @@ abstract class EVF_Form_Fields { * Constructor. */ public function __construct() { - $this->class = $this->is_pro ? 'upgrade-modal' : $this->class; + $get_license = evf_get_license_plan(); + $this->class = $this->is_pro ? ( false === $get_license ? 'upgrade-modal' : 'evf-upgrade-addon' ) : $this->class; $this->form_id = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : false; // phpcs:ignore WordPress.Security.NonceVerification // Init hooks. diff --git a/includes/admin/builder/class-evf-builder-fields.php b/includes/admin/builder/class-evf-builder-fields.php index dbc48e4b3..c765364fc 100644 --- a/includes/admin/builder/class-evf-builder-fields.php +++ b/includes/admin/builder/class-evf-builder-fields.php @@ -119,8 +119,12 @@ public function output_fields() {
- -