gutenberg
4 years ago
admin.js
4 years ago
admin.min.js
4 years ago
deactivation-feedback.js
3 years ago
deactivation-feedback.min.js
3 years ago
editor.js
8 years ago
editor.min.js
5 years ago
evf-admin-email.js
3 years ago
evf-admin-email.min.js
3 years ago
evf-clipboard.js
8 years ago
evf-clipboard.min.js
8 years ago
evf-enhanced-select.js
3 years ago
evf-enhanced-select.min.js
3 years ago
evf-file-uploader.js
3 years ago
evf-file-uploader.min.js
3 years ago
evf-setup.js
3 years ago
evf-setup.min.js
3 years ago
extensions.js
4 years ago
extensions.min.js
4 years ago
form-builder.js
3 years ago
form-builder.min.js
3 years ago
form-template-controller.js
3 years ago
form-template-controller.min.js
3 years ago
settings.js
4 years ago
settings.min.js
4 years ago
tools.js
4 years ago
tools.min.js
4 years ago
upgrade.js
5 years ago
upgrade.min.js
5 years ago
evf-setup.js
275 lines
| 1 | /* global evf_setup_params */ |
| 2 | jQuery( function( $ ) { |
| 3 | |
| 4 | /** |
| 5 | * Setup actions. |
| 6 | */ |
| 7 | var evf_setup_actions = { |
| 8 | $setup_form: $( '.everest-forms-setup--form' ), |
| 9 | $button_install: evf_data.i18n_activating, |
| 10 | init: function() { |
| 11 | this.title_focus(); |
| 12 | |
| 13 | // Template actions. |
| 14 | $( document ).on( 'click', '.everest-forms-template-install-addon', this.install_addon ); |
| 15 | $( document ).on( 'click', '.everest-forms-builder-setup .upgrade-modal', this.message_upgrade ); |
| 16 | $( document ).on( 'click', '.everest-forms-builder-setup .evf-template-preview', this.template_preview ); |
| 17 | |
| 18 | // Select and apply a template. |
| 19 | this.$setup_form.on( 'click', '.evf-template-select', this.template_select ); |
| 20 | |
| 21 | // Prevent <ENTER> key for setup actions. |
| 22 | $( document.body ).on( 'keypress', '.everest-forms-setup-form-name input', this.input_keypress ); |
| 23 | |
| 24 | // <ENTER> key for setup actions. |
| 25 | $( document.body ).on( 'keypress', 'input#everest-forms-setup-name', function ( event ) { |
| 26 | if( event.key === "Enter" ) { |
| 27 | event.preventDefault(); |
| 28 | $( this ).parents( 'div.jconfirm-content-pane' ).next( 'div.jconfirm-buttons' ).find( 'button.everest-forms-btn.everest-forms-btn-primary' ).trigger( 'click' ); |
| 29 | } |
| 30 | } ); |
| 31 | }, |
| 32 | title_focus: function() { |
| 33 | setTimeout( function (){ |
| 34 | $( '#everest-forms-setup-name' ).focus(); |
| 35 | }, 100 ); |
| 36 | }, |
| 37 | install_addon: function( event ) { |
| 38 | var pluginsList = $( '.plugins-list-table' ).find( '#the-list tr' ), |
| 39 | $target = $( event.target ), |
| 40 | success = 0, |
| 41 | error = 0, |
| 42 | errorMessages = []; |
| 43 | |
| 44 | wp.updates.maybeRequestFilesystemCredentials(event); |
| 45 | |
| 46 | $( '.everest-forms-template-install-addon' ).html( '<div class="evf-loading evf-loading-active"></div>' + evf_setup_actions.$button_install ).prop( 'disabled', true ); |
| 47 | |
| 48 | $( document ).trigger( 'wp-plugin-bulk-install', pluginsList ); |
| 49 | |
| 50 | // Find all the plugins which are required. |
| 51 | pluginsList.each( function( index, element ) { |
| 52 | var $itemRow = $(element); |
| 53 | |
| 54 | // Only add inactive items to the update queue. |
| 55 | if ( ! $itemRow.hasClass( 'inactive' ) || $itemRow.find( 'notice-error' ).length ) { |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | // Add it to the queue. |
| 60 | wp.updates.queue.push({ |
| 61 | action: 'everest_forms_install_extension', |
| 62 | data: { |
| 63 | page: pagenow, |
| 64 | name: $itemRow.data( 'name' ), |
| 65 | slug: $itemRow.data( 'slug' ) |
| 66 | } |
| 67 | }); |
| 68 | }); |
| 69 | |
| 70 | // Display bulk notification for install of plugin. |
| 71 | $( document ).on( 'wp-plugin-bulk-install-success wp-plugin-bulk-install-error', function( event, response ) { |
| 72 | var $itemRow = $( '[data-slug="' + response.slug + '"]' ), $bulkActionNotice, itemName; |
| 73 | |
| 74 | if ( 'wp-' + response.install + '-bulk-install-success' === event.type ) { |
| 75 | success++; |
| 76 | } else { |
| 77 | itemName = response.pluginName ? response.pluginName : $itemRow.find( '.plugin-name' ).text(); |
| 78 | error++; |
| 79 | errorMessages.push( itemName + ': ' + response.errorMessage ); |
| 80 | } |
| 81 | |
| 82 | wp.updates.adminNotice = wp.template( 'wp-bulk-installs-admin-notice' ); |
| 83 | |
| 84 | // Remove previous error messages, if any. |
| 85 | $( '.everest-forms-recommend-addons .bulk-action-notice' ).remove(); |
| 86 | |
| 87 | $( '.everest-forms-recommend-addons .plugins-info' ).after( wp.updates.adminNotice({ |
| 88 | id: 'bulk-action-notice', |
| 89 | className: 'bulk-action-notice notice-alt', |
| 90 | successes: success, |
| 91 | errors: error, |
| 92 | errorMessages: errorMessages, |
| 93 | type: response.install |
| 94 | }) |
| 95 | ); |
| 96 | |
| 97 | $bulkActionNotice = $( '#bulk-action-notice' ).on( 'click', 'button', function() { |
| 98 | // $( this ) is the clicked button, no need to get it again. |
| 99 | $( this ) |
| 100 | .toggleClass( 'bulk-action-errors-collapsed' ) |
| 101 | .attr( 'aria-expanded', ! $( this ).hasClass( 'bulk-action-errors-collapsed' ) ); |
| 102 | // Show the errors list. |
| 103 | $bulkActionNotice.find( '.bulk-action-errors' ).toggleClass( 'hidden' ); |
| 104 | }); |
| 105 | |
| 106 | if ( ! wp.updates.queue.length ) { |
| 107 | if ( error > 0 ) { |
| 108 | $target |
| 109 | .removeClass( 'updating-message' ) |
| 110 | .text( $target.data( 'originaltext' ) ); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | if ( 0 === wp.updates.queue.length ) { |
| 115 | $( '.everest-forms-template-install-addon' ).remove(); |
| 116 | $( '.everest-forms-builder-setup .jconfirm-buttons button' ).show(); |
| 117 | } |
| 118 | } ); |
| 119 | |
| 120 | // Check the queue, now that the event handlers have been added. |
| 121 | wp.updates.queueChecker(); |
| 122 | }, |
| 123 | message_upgrade: function( e ) { |
| 124 | var templateName = $( this ).data( 'template-name-raw' ); |
| 125 | |
| 126 | e.preventDefault(); |
| 127 | |
| 128 | $.alert( { |
| 129 | title: templateName + ' ' + evf_setup_params.upgrade_title, |
| 130 | theme: 'jconfirm-modern jconfirm-everest-forms', |
| 131 | icon: 'dashicons dashicons-lock', |
| 132 | backgroundDismiss: false, |
| 133 | scrollToPreviousElement: false, |
| 134 | content: evf_setup_params.upgrade_message, |
| 135 | type: 'red', |
| 136 | boxWidth: '565px', |
| 137 | buttons: { |
| 138 | confirm: { |
| 139 | text: evf_setup_params.upgrade_button, |
| 140 | btnClass: 'btn-confirm', |
| 141 | keys: ['enter'], |
| 142 | action: function () { |
| 143 | window.open( evf_setup_params.upgrade_url, '_blank' ); |
| 144 | } |
| 145 | }, |
| 146 | cancel: { |
| 147 | text: evf_data.i18n_ok |
| 148 | } |
| 149 | } |
| 150 | } ); |
| 151 | }, |
| 152 | template_preview: function() { |
| 153 | var $this = $(this), |
| 154 | previewLink = $this.data('preview-link'); |
| 155 | |
| 156 | $this.closest( '.everest-forms-setup--form' ).find( '.evf-template-preview-iframe #frame' ).attr( 'src', previewLink ); |
| 157 | }, |
| 158 | template_select: function( event ) { |
| 159 | var $this = $( this ), |
| 160 | template = $this.data( 'template' ), |
| 161 | templateName = $this.data( 'template-name-raw' ), |
| 162 | formName = '', |
| 163 | namePrompt = evf_setup_params.i18n_form_name, |
| 164 | nameField = '<input autofocus="" type="text" id="everest-forms-setup-name" class="everest-forms-setup-name" placeholder="'+evf_setup_params.i18n_form_placeholder+'">', |
| 165 | nameError = '<p class="error">' + evf_setup_params.i18n_form_error_name + '</p>'; |
| 166 | |
| 167 | event.preventDefault(); |
| 168 | |
| 169 | $target = $( event.target ); |
| 170 | |
| 171 | if ( $target.hasClass( 'disabled' ) || $target.hasClass( 'updating-message' ) ) { |
| 172 | return; |
| 173 | } |
| 174 | |
| 175 | $.confirm( { |
| 176 | title: evf_setup_params.i18n_form_title, |
| 177 | theme: 'jconfirm-modern jconfirm-everest-forms-left', |
| 178 | backgroundDismiss: false, |
| 179 | scrollToPreviousElement: false, |
| 180 | content: function() { |
| 181 | // Fire AJAX. |
| 182 | var self = this, |
| 183 | button = evf_data.i18n_install_only; |
| 184 | |
| 185 | if ( $target.closest( '.evf-template' ).find( 'span.everest-forms-badge' ).length ) { |
| 186 | var data = { |
| 187 | action: 'everest_forms_template_licence_check', |
| 188 | plan: $this.attr( 'data-licence-plan' ).replace('-lifetime',''), |
| 189 | slug: $this.attr( 'data-template' ), |
| 190 | security: evf_setup_params.template_licence_check_nonce |
| 191 | }; |
| 192 | |
| 193 | return $.ajax( { |
| 194 | url: evf_email_params.ajax_url, |
| 195 | data: data, |
| 196 | type: 'POST', |
| 197 | } ).done( function( response ) { |
| 198 | self.setContentAppend( namePrompt+nameField+nameError+response.data.html ); |
| 199 | |
| 200 | if ( response.data.activate ) { |
| 201 | $( '.everest-forms-builder-setup .jconfirm-buttons button' ).show(); |
| 202 | } else { |
| 203 | if ( response.data.html.includes( 'install-now' ) ) { |
| 204 | button = evf_data.i18n_install_activate; |
| 205 | evf_setup_actions.$button_install = evf_data.i18n_installing; |
| 206 | } |
| 207 | var installButton = '<a href="#" class="everest-forms-btn everest-forms-btn-primary everest-forms-template-install-addon">' + button + '</a>'; |
| 208 | $( '.everest-forms-builder-setup .jconfirm-buttons' ).append( installButton ); |
| 209 | } |
| 210 | } ); |
| 211 | } else { |
| 212 | $( '.everest-forms-builder-setup .jconfirm-buttons button' ).show(); |
| 213 | return namePrompt+nameField+nameError; |
| 214 | } |
| 215 | }, |
| 216 | buttons: { |
| 217 | Continue: { |
| 218 | isHidden: true, // Hide the button. |
| 219 | btnClass: 'everest-forms-btn everest-forms-btn-primary', |
| 220 | action: function () { |
| 221 | var $formName = $( '#everest-forms-setup-name' ), |
| 222 | overlay = $( '.everest-forms-loader-overlay' ); |
| 223 | |
| 224 | // Check that form title is provided. |
| 225 | if ( ! $formName.val() ) { |
| 226 | formName = templateName; |
| 227 | var error = this.$content.find( '.error' ); |
| 228 | $( '.everest-forms-setup-name' ).addClass( 'everest-forms-required' ).focus(); |
| 229 | error.show(); |
| 230 | return false; |
| 231 | } else { |
| 232 | formName = $formName.val(); |
| 233 | } |
| 234 | |
| 235 | overlay.show(); |
| 236 | |
| 237 | var data = { |
| 238 | title: formName, |
| 239 | action: 'everest_forms_create_form', |
| 240 | template: template, |
| 241 | security: evf_setup_params.create_form_nonce |
| 242 | }; |
| 243 | |
| 244 | $.post( evf_setup_params.ajax_url, data, function( response ) { |
| 245 | if ( response.success ) { |
| 246 | window.location.href = response.data.redirect; |
| 247 | } else { |
| 248 | overlay.hide(); |
| 249 | $( '.everest-forms-setup-name' ).addClass( 'everest-forms-required' ).focus(); |
| 250 | window.console.log( response ); |
| 251 | } |
| 252 | }).fail( function( xhr ) { |
| 253 | window.console.log( xhr.responseText ); |
| 254 | }); |
| 255 | } |
| 256 | }, |
| 257 | } |
| 258 | } ); |
| 259 | }, |
| 260 | input_keypress: function ( e ) { |
| 261 | var button = e.keyCode || e.which; |
| 262 | |
| 263 | $( this ).removeClass( 'everest-forms-required' ); |
| 264 | |
| 265 | // Enter key. |
| 266 | if ( 13 === button && e.target.tagName.toLowerCase() === 'input' ) { |
| 267 | e.preventDefault(); |
| 268 | return false; |
| 269 | } |
| 270 | } |
| 271 | }; |
| 272 | |
| 273 | evf_setup_actions.init(); |
| 274 | }); |
| 275 |