Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement - Upgrade to the pro improve for dragging a field #1124

7 changes: 5 additions & 2 deletions assets/css/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
166 changes: 166 additions & 0 deletions assets/js/admin/evf-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@ jQuery( function( $ ) {
$( 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 );

//Active addon.
$(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));
});

//Install addon.
$(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 );

Expand Down Expand Up @@ -268,6 +286,154 @@ jQuery( function( $ ) {
e.preventDefault();
return false;
}
},
/**
*Active the addon from form builder.
*
* @param {any} node
*/
active_addon_from_buidler:function( node ) {
var url = $(node).attr("href");
var plugin = $(node).data("plugin");
var activating = $.alert({
title:evf_setup_params.activate_title,
theme: 'jconfirm-modern jconfirm-everest-forms',
icon: 'dashicons dashicons-success',
buttons:false,
content: evf_setup_params.activate_message,
type: 'green',
});
$.ajax({
type: 'POST',
url: evf_setup_params.ajax_url,
data: {
action: 'everest_forms_active_addons',
plugin_file : plugin,
security : evf_setup_params.evf_active_nonce
},
success:function(res) {
activating.close();
if(res.success === true) {
$.confirm({
title: evf_setup_params.active_confirmation_title,
theme: 'jconfirm-modern jconfirm-everest-forms',
icon: 'success',
backgroundDismiss: false,
scrollToPreviousElement: false,
type:'green',
content: evf_setup_params.active_confirmation_message,
buttons: {
confirm: {
text: evf_setup_params.save_changes_text,
btnClass:'btn-warning',
action: function () {
$('.everest-forms-save-button').trigger('click');
location.reload(true);
}
},
cancel: {
text: evf_setup_params.reload_text,
btnClass:'btn-warning',
action: function () {
location.reload(true);
}
}
},
});
} else {
$.alert({
title:evf_setup_params.activate_title,
theme: 'jconfirm-modern jconfirm-everest-forms',
icon: 'dashicons dashicons-warning',
buttons:false,
content: res.data.message,
type: 'red',
});
}
}
})
},

/**
*Install the addon from form builder.
*
* @param {any} event
*/
install_now_from_buidler:function(event) {
var alertInstance = $.alert( {
title:evf_setup_params.installing_title,
icon: 'success',
buttons:false,
content: evf_setup_params.installing_message,
type: 'success',
} );
wp.updates.maybeRequestFilesystemCredentials(event);
evf_setup_actions.$button_install = evf_setup_params.i18n_installing;
$(event)
.html(
evf_setup_actions.$button_install +
'<div class="ur-spinner"></div>'
)
.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) {
alertInstance.close();
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.install_confirmation_title,
theme: 'jconfirm-modern jconfirm-everest-forms',
icon: 'success',
backgroundDismiss: false,
scrollToPreviousElement: false,
content: evf_setup_params.install_confirmation_message,
buttons: {
confirm: {
text: evf_setup_params.save_changes_text,
btnClass:'btn-warning',
action: function () {
$('.everest-forms-save-button').trigger('click');
location.reload();
}
},
cancel: {
text: evf_setup_params.reload_text,
btnClass:'btn-warning',
action: function () {
location.reload();
}
}
},
type:'green',
});
}
}
}
);

// Check the queue, now that the event handlers have been added.
wp.updates.queueChecker();
}
};

Expand Down
23 changes: 20 additions & 3 deletions assets/js/admin/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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' );
Expand Down Expand Up @@ -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;
Expand All @@ -165,7 +182,7 @@
return;
}

if ( wp.updates.maybeHandleCredentialError( response, 'install-plugin' ) ) {
if ( wp.updates.maybeHandleCredentialError( response, 'install-plugin' ) ) {
return;
}

Expand Down
63 changes: 63 additions & 0 deletions assets/js/admin/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ jQuery( function( $ ) {
var evf_upgrade_actions = {
init: function() {
$( document.body ).on( 'click dragstart', '.evf-registered-item.upgrade-modal', this.field_upgrade );
$( document.body ).on( 'click dragstart', '.evf-registered-item.evf-upgrade-addon', this.evf_upgrade_addon );
$( document.body ).on( 'click dragstart', '.evf-registered-item.enable-stripe-model', this.enable_stripe_model );
$( document.body ).on( 'click dragstart', '.evf-registered-item.enable-authorize-net-model', this.enable_authorize_net_model );
$( document.body ).on( 'click dragstart', '.everest-forms-field-option-row.upgrade-modal', this.feature_upgrade );
Expand All @@ -22,6 +23,68 @@ jQuery( function( $ ) {

evf_upgrade_actions.upgrade_modal( $( this ).data( 'feature' ) ? $( this ).data( 'feature' ) : $( this ).text() + ' field' );
},
evf_upgrade_addon:function(e){
e.preventDefault();
var fieldType = $(this).data('field-type'),
fieldPlan = $(this).data('field-plan'),
addonSlug = $(this).data('addon-slug');
$.ajax({
type: 'POST',
url: evf_upgrade.ajax_url,
data: {
action: 'everest_forms_install_and_active_addons',
field_plan: fieldPlan,
field_type: fieldType,
addon_slug: addonSlug,
security : evf_upgrade.evf_install_and_active_nonce
},
success: function(res) {
if(res.success === true) {
$.alert( {
title: res.data.title,
theme: 'jconfirm-modern jconfirm-everest-forms',
icon: 'dashicons dashicons-lock',
backgroundDismiss: false,
scrollToPreviousElement: false,
content: res.data.message,
buttons:{
confirm:{
text:res.data.content,
keys:['enter'],
},
},
type: 'blue',
boxWidth: '565px',
} );
}
if(res.success === false) {
$.alert( {
title: res.data.addon.name + ' ' + evf_upgrade.upgrade_plan_title,
theme: 'jconfirm-modern jconfirm-everest-forms',
icon: 'dashicons dashicons-lock',
backgroundDismiss: false,
scrollToPreviousElement: false,
content: evf_upgrade.upgrade_plan_message,
type: 'red',
boxWidth: '565px',
buttons: {
confirm: {
text: evf_upgrade.upgrade_plan_button,
btnClass: 'btn-confirm',
keys: ['enter'],
action: function () {
window.open( evf_upgrade.upgrade_url, '_blank' );
}
},
cancel: {
text: evf_data.i18n_ok
}
}
} );
}
}
})
},
upgrade_modal: function( feature ) {
var message = evf_upgrade.upgrade_message.replace( /%name%/g, feature );

Expand Down
3 changes: 2 additions & 1 deletion includes/abstracts/class-evf-form-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions includes/admin/builder/class-evf-builder-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,12 @@ public function output_fields() {
<div class="everest-forms-add-fields-group open">
<a href="#" class="everest-forms-add-fields-heading" data-group="<?php echo esc_attr( $group ); ?>"><?php echo esc_html( evf_get_fields_group( $group ) ); ?><i class="handlediv"></i></a>
<div class="evf-registered-buttons">
<?php foreach ( $form_field as $field ) : ?>
<button type="button" id="everest-forms-add-fields-<?php echo esc_attr( $field->type ); ?>" class="evf-registered-item <?php echo sanitize_html_class( $field->class ); ?>" data-field-type="<?php echo esc_attr( $field->type ); ?>">
<?php
foreach ( $form_field as $field ) :
$field_plan = isset( $field->plan ) ? $field->plan : '';
$addon_slug = isset( $field->addon ) ? $field->addon : '';
?>
<button type="button" id="everest-forms-add-fields-<?php echo esc_attr( $field->type ); ?>" class="evf-registered-item <?php echo sanitize_html_class( $field->class ); ?>" data-field-type="<?php echo esc_attr( $field->type ); ?>" data-field-plan="<?php echo esc_attr( $field_plan ); ?>" data-addon-slug="<?php echo esc_attr( $addon_slug ); ?>">
<?php if ( isset( $field->icon ) ) : ?>
<i class="<?php echo esc_attr( $field->icon ); ?>"></i>
<?php endif; ?>
Expand Down
Loading