gutenberg
2 years ago
admin.js
3 years ago
admin.min.js
3 years ago
deactivation-feedback.js
3 years ago
deactivation-feedback.min.js
3 years ago
editor.js
7 years ago
editor.min.js
5 years ago
evf-admin-email.js
2 years ago
evf-admin-email.min.js
2 years ago
evf-clipboard.js
7 years ago
evf-clipboard.min.js
7 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
2 years ago
evf-setup.min.js
2 years ago
extensions.js
2 years ago
extensions.min.js
2 years ago
form-builder.js
2 years ago
form-builder.min.js
2 years ago
form-template-controller.js
3 years ago
form-template-controller.min.js
3 years ago
settings.js
3 years ago
settings.min.js
3 years ago
tools.js
4 years ago
tools.min.js
4 years ago
upgrade.js
2 years ago
upgrade.min.js
2 years ago
evf-setup.js
442 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 | //Active addon. |
| 19 | $(document).on('click', '.activate-now', function(e) { |
| 20 | e.preventDefault(); |
| 21 | if(!$(this).closest('body.everest-forms_page_evf-builder').length) { |
| 22 | return; |
| 23 | } |
| 24 | evf_setup_actions.active_addon_from_buidler($(this)); |
| 25 | }); |
| 26 | |
| 27 | //Install addon. |
| 28 | $(document).on('click', '.install-from-builder', function(e) { |
| 29 | e.preventDefault(); |
| 30 | if(!$(this).closest('body.everest-forms_page_evf-builder').length) { |
| 31 | return; |
| 32 | } |
| 33 | evf_setup_actions.install_now_from_buidler($(this)); |
| 34 | }); |
| 35 | |
| 36 | // Select and apply a template. |
| 37 | this.$setup_form.on( 'click', '.evf-template-select', this.template_select ); |
| 38 | |
| 39 | // Prevent <ENTER> key for setup actions. |
| 40 | $( document.body ).on( 'keypress', '.everest-forms-setup-form-name input', this.input_keypress ); |
| 41 | |
| 42 | // <ENTER> key for setup actions. |
| 43 | $( document.body ).on( 'keypress', 'input#everest-forms-setup-name', function ( event ) { |
| 44 | if( event.key === "Enter" ) { |
| 45 | event.preventDefault(); |
| 46 | $( this ).parents( 'div.jconfirm-content-pane' ).next( 'div.jconfirm-buttons' ).find( 'button.everest-forms-btn.everest-forms-btn-primary' ).trigger( 'click' ); |
| 47 | } |
| 48 | } ); |
| 49 | }, |
| 50 | title_focus: function() { |
| 51 | setTimeout( function (){ |
| 52 | $( '#everest-forms-setup-name' ).focus(); |
| 53 | }, 100 ); |
| 54 | }, |
| 55 | install_addon: function( event ) { |
| 56 | var pluginsList = $( '.plugins-list-table' ).find( '#the-list tr' ), |
| 57 | $target = $( event.target ), |
| 58 | success = 0, |
| 59 | error = 0, |
| 60 | errorMessages = []; |
| 61 | |
| 62 | wp.updates.maybeRequestFilesystemCredentials(event); |
| 63 | |
| 64 | $( '.everest-forms-template-install-addon' ).html( '<div class="evf-loading evf-loading-active"></div>' + evf_setup_actions.$button_install ).prop( 'disabled', true ); |
| 65 | |
| 66 | $( document ).trigger( 'wp-plugin-bulk-install', pluginsList ); |
| 67 | |
| 68 | // Find all the plugins which are required. |
| 69 | pluginsList.each( function( index, element ) { |
| 70 | var $itemRow = $(element); |
| 71 | |
| 72 | // Only add inactive items to the update queue. |
| 73 | if ( ! $itemRow.hasClass( 'inactive' ) || $itemRow.find( 'notice-error' ).length ) { |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | // Add it to the queue. |
| 78 | wp.updates.queue.push({ |
| 79 | action: 'everest_forms_install_extension', |
| 80 | data: { |
| 81 | page: pagenow, |
| 82 | name: $itemRow.data( 'name' ), |
| 83 | slug: $itemRow.data( 'slug' ) |
| 84 | } |
| 85 | }); |
| 86 | }); |
| 87 | |
| 88 | // Display bulk notification for install of plugin. |
| 89 | $( document ).on( 'wp-plugin-bulk-install-success wp-plugin-bulk-install-error', function( event, response ) { |
| 90 | var $itemRow = $( '[data-slug="' + response.slug + '"]' ), $bulkActionNotice, itemName; |
| 91 | |
| 92 | if ( 'wp-' + response.install + '-bulk-install-success' === event.type ) { |
| 93 | success++; |
| 94 | } else { |
| 95 | itemName = response.pluginName ? response.pluginName : $itemRow.find( '.plugin-name' ).text(); |
| 96 | error++; |
| 97 | errorMessages.push( itemName + ': ' + response.errorMessage ); |
| 98 | } |
| 99 | |
| 100 | wp.updates.adminNotice = wp.template( 'wp-bulk-installs-admin-notice' ); |
| 101 | |
| 102 | // Remove previous error messages, if any. |
| 103 | $( '.everest-forms-recommend-addons .bulk-action-notice' ).remove(); |
| 104 | |
| 105 | $( '.everest-forms-recommend-addons .plugins-info' ).after( wp.updates.adminNotice({ |
| 106 | id: 'bulk-action-notice', |
| 107 | className: 'bulk-action-notice notice-alt', |
| 108 | successes: success, |
| 109 | errors: error, |
| 110 | errorMessages: errorMessages, |
| 111 | type: response.install |
| 112 | }) |
| 113 | ); |
| 114 | |
| 115 | $bulkActionNotice = $( '#bulk-action-notice' ).on( 'click', 'button', function() { |
| 116 | // $( this ) is the clicked button, no need to get it again. |
| 117 | $( this ) |
| 118 | .toggleClass( 'bulk-action-errors-collapsed' ) |
| 119 | .attr( 'aria-expanded', ! $( this ).hasClass( 'bulk-action-errors-collapsed' ) ); |
| 120 | // Show the errors list. |
| 121 | $bulkActionNotice.find( '.bulk-action-errors' ).toggleClass( 'hidden' ); |
| 122 | }); |
| 123 | |
| 124 | if ( ! wp.updates.queue.length ) { |
| 125 | if ( error > 0 ) { |
| 126 | $target |
| 127 | .removeClass( 'updating-message' ) |
| 128 | .text( $target.data( 'originaltext' ) ); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | if ( 0 === wp.updates.queue.length ) { |
| 133 | $( '.everest-forms-template-install-addon' ).remove(); |
| 134 | $( '.everest-forms-builder-setup .jconfirm-buttons button' ).show(); |
| 135 | } |
| 136 | } ); |
| 137 | |
| 138 | // Check the queue, now that the event handlers have been added. |
| 139 | wp.updates.queueChecker(); |
| 140 | }, |
| 141 | message_upgrade: function( e ) { |
| 142 | var templateName = $( this ).data( 'template-name-raw' ); |
| 143 | |
| 144 | e.preventDefault(); |
| 145 | |
| 146 | $.alert( { |
| 147 | title: templateName + ' ' + evf_setup_params.upgrade_title, |
| 148 | theme: 'jconfirm-modern jconfirm-everest-forms', |
| 149 | icon: 'dashicons dashicons-lock', |
| 150 | backgroundDismiss: false, |
| 151 | scrollToPreviousElement: false, |
| 152 | content: evf_setup_params.upgrade_message, |
| 153 | type: 'red', |
| 154 | boxWidth: '565px', |
| 155 | buttons: { |
| 156 | confirm: { |
| 157 | text: evf_setup_params.upgrade_button, |
| 158 | btnClass: 'btn-confirm', |
| 159 | keys: ['enter'], |
| 160 | action: function () { |
| 161 | window.open( evf_setup_params.upgrade_url, '_blank' ); |
| 162 | } |
| 163 | }, |
| 164 | cancel: { |
| 165 | text: evf_data.i18n_ok |
| 166 | } |
| 167 | } |
| 168 | } ); |
| 169 | }, |
| 170 | template_preview: function() { |
| 171 | var $this = $(this), |
| 172 | previewLink = $this.data('preview-link'); |
| 173 | |
| 174 | $this.closest( '.everest-forms-setup--form' ).find( '.evf-template-preview-iframe #frame' ).attr( 'src', previewLink ); |
| 175 | }, |
| 176 | template_select: function( event ) { |
| 177 | var $this = $( this ), |
| 178 | template = $this.data( 'template' ), |
| 179 | templateName = $this.data( 'template-name-raw' ), |
| 180 | formName = '', |
| 181 | namePrompt = evf_setup_params.i18n_form_name, |
| 182 | nameField = '<input autofocus="" type="text" id="everest-forms-setup-name" class="everest-forms-setup-name" placeholder="'+evf_setup_params.i18n_form_placeholder+'">', |
| 183 | nameError = '<p class="error">' + evf_setup_params.i18n_form_error_name + '</p>'; |
| 184 | |
| 185 | event.preventDefault(); |
| 186 | |
| 187 | $target = $( event.target ); |
| 188 | |
| 189 | if ( $target.hasClass( 'disabled' ) || $target.hasClass( 'updating-message' ) ) { |
| 190 | return; |
| 191 | } |
| 192 | |
| 193 | $.confirm( { |
| 194 | title: evf_setup_params.i18n_form_title, |
| 195 | theme: 'jconfirm-modern jconfirm-everest-forms-left', |
| 196 | backgroundDismiss: false, |
| 197 | scrollToPreviousElement: false, |
| 198 | content: function() { |
| 199 | // Fire AJAX. |
| 200 | var self = this, |
| 201 | button = evf_data.i18n_install_only; |
| 202 | |
| 203 | if ( $target.closest( '.evf-template' ).find( 'span.everest-forms-badge' ).length ) { |
| 204 | var data = { |
| 205 | action: 'everest_forms_template_licence_check', |
| 206 | plan: $this.attr( 'data-licence-plan' ).replace('-lifetime',''), |
| 207 | slug: $this.attr( 'data-template' ), |
| 208 | security: evf_setup_params.template_licence_check_nonce |
| 209 | }; |
| 210 | |
| 211 | return $.ajax( { |
| 212 | url: evf_email_params.ajax_url, |
| 213 | data: data, |
| 214 | type: 'POST', |
| 215 | } ).done( function( response ) { |
| 216 | self.setContentAppend( namePrompt+nameField+nameError+response.data.html ); |
| 217 | |
| 218 | if ( response.data.activate ) { |
| 219 | $( '.everest-forms-builder-setup .jconfirm-buttons button' ).show(); |
| 220 | } else { |
| 221 | if ( response.data.html.includes( 'install-now' ) ) { |
| 222 | button = evf_data.i18n_install_activate; |
| 223 | evf_setup_actions.$button_install = evf_data.i18n_installing; |
| 224 | } |
| 225 | var installButton = '<a href="#" class="everest-forms-btn everest-forms-btn-primary everest-forms-template-install-addon">' + button + '</a>'; |
| 226 | $( '.everest-forms-builder-setup .jconfirm-buttons' ).append( installButton ); |
| 227 | } |
| 228 | } ); |
| 229 | } else { |
| 230 | $( '.everest-forms-builder-setup .jconfirm-buttons button' ).show(); |
| 231 | return namePrompt+nameField+nameError; |
| 232 | } |
| 233 | }, |
| 234 | buttons: { |
| 235 | Continue: { |
| 236 | isHidden: true, // Hide the button. |
| 237 | btnClass: 'everest-forms-btn everest-forms-btn-primary', |
| 238 | action: function () { |
| 239 | var $formName = $( '#everest-forms-setup-name' ), |
| 240 | overlay = $( '.everest-forms-loader-overlay' ); |
| 241 | console.log($formName.val()); |
| 242 | |
| 243 | // Check that form title is provided. |
| 244 | if ( ! $formName.val() || "" === $formName.val().trim() ) { |
| 245 | formName = templateName; |
| 246 | var error = this.$content.find( '.error' ); |
| 247 | $( '.everest-forms-setup-name' ).addClass( 'everest-forms-required' ).focus(); |
| 248 | error.show(); |
| 249 | return false; |
| 250 | } else { |
| 251 | formName = $formName.val(); |
| 252 | } |
| 253 | |
| 254 | overlay.show(); |
| 255 | |
| 256 | var data = { |
| 257 | title: formName, |
| 258 | action: 'everest_forms_create_form', |
| 259 | template: template, |
| 260 | security: evf_setup_params.create_form_nonce |
| 261 | }; |
| 262 | |
| 263 | $.post( evf_setup_params.ajax_url, data, function( response ) { |
| 264 | if ( response.success ) { |
| 265 | window.location.href = response.data.redirect; |
| 266 | } else { |
| 267 | overlay.hide(); |
| 268 | $( '.everest-forms-setup-name' ).addClass( 'everest-forms-required' ).focus(); |
| 269 | window.console.log( response ); |
| 270 | } |
| 271 | }).fail( function( xhr ) { |
| 272 | window.console.log( xhr.responseText ); |
| 273 | }); |
| 274 | } |
| 275 | }, |
| 276 | } |
| 277 | } ); |
| 278 | }, |
| 279 | input_keypress: function ( e ) { |
| 280 | var button = e.keyCode || e.which; |
| 281 | |
| 282 | $( this ).removeClass( 'everest-forms-required' ); |
| 283 | |
| 284 | // Enter key. |
| 285 | if ( 13 === button && e.target.tagName.toLowerCase() === 'input' ) { |
| 286 | e.preventDefault(); |
| 287 | return false; |
| 288 | } |
| 289 | }, |
| 290 | /** |
| 291 | *Active the addon from form builder. |
| 292 | * |
| 293 | * @param {any} node |
| 294 | */ |
| 295 | active_addon_from_buidler:function( node ) { |
| 296 | var url = $(node).attr("href"); |
| 297 | var plugin = $(node).data("plugin"); |
| 298 | var activating = $.alert({ |
| 299 | title:evf_setup_params.activate_title, |
| 300 | theme: 'jconfirm-modern jconfirm-everest-forms', |
| 301 | icon: 'dashicons dashicons-success', |
| 302 | buttons:false, |
| 303 | content: evf_setup_params.activate_message, |
| 304 | type: 'green', |
| 305 | }); |
| 306 | $.ajax({ |
| 307 | type: 'POST', |
| 308 | url: evf_setup_params.ajax_url, |
| 309 | data: { |
| 310 | action: 'everest_forms_active_addons', |
| 311 | plugin_file : plugin, |
| 312 | security : evf_setup_params.evf_active_nonce |
| 313 | }, |
| 314 | success:function(res) { |
| 315 | activating.close(); |
| 316 | if(res.success === true) { |
| 317 | $.confirm({ |
| 318 | title: evf_setup_params.active_confirmation_title, |
| 319 | theme: 'jconfirm-modern jconfirm-everest-forms', |
| 320 | icon: 'success', |
| 321 | backgroundDismiss: false, |
| 322 | scrollToPreviousElement: false, |
| 323 | type:'green', |
| 324 | content: evf_setup_params.active_confirmation_message, |
| 325 | buttons: { |
| 326 | confirm: { |
| 327 | text: evf_setup_params.save_changes_text, |
| 328 | btnClass:'btn-warning', |
| 329 | action: function () { |
| 330 | $('.everest-forms-save-button').trigger('click'); |
| 331 | location.reload(true); |
| 332 | } |
| 333 | }, |
| 334 | cancel: { |
| 335 | text: evf_setup_params.reload_text, |
| 336 | btnClass:'btn-warning', |
| 337 | action: function () { |
| 338 | location.reload(true); |
| 339 | } |
| 340 | } |
| 341 | }, |
| 342 | }); |
| 343 | } else { |
| 344 | $.alert({ |
| 345 | title:evf_setup_params.activate_title, |
| 346 | theme: 'jconfirm-modern jconfirm-everest-forms', |
| 347 | icon: 'dashicons dashicons-warning', |
| 348 | buttons:false, |
| 349 | content: res.data.message, |
| 350 | type: 'red', |
| 351 | }); |
| 352 | } |
| 353 | } |
| 354 | }) |
| 355 | }, |
| 356 | |
| 357 | /** |
| 358 | *Install the addon from form builder. |
| 359 | * |
| 360 | * @param {any} event |
| 361 | */ |
| 362 | install_now_from_buidler:function(event) { |
| 363 | var alertInstance = $.alert( { |
| 364 | title:evf_setup_params.installing_title, |
| 365 | icon: 'success', |
| 366 | buttons:false, |
| 367 | content: evf_setup_params.installing_message, |
| 368 | type: 'green', |
| 369 | } ); |
| 370 | wp.updates.maybeRequestFilesystemCredentials(event); |
| 371 | evf_setup_actions.$button_install = evf_setup_params.i18n_installing; |
| 372 | $(event) |
| 373 | .html( |
| 374 | evf_setup_actions.$button_install + |
| 375 | '<div class="ur-spinner"></div>' |
| 376 | ) |
| 377 | .closest("button") |
| 378 | .prop("disabled", true); |
| 379 | |
| 380 | wp.updates.queue.push({ |
| 381 | action: 'everest_forms_install_extension', |
| 382 | data: { |
| 383 | page: pagenow, |
| 384 | name: $(event).data( 'name' ), |
| 385 | slug: $(event).data( 'slug' ) |
| 386 | } |
| 387 | }); |
| 388 | |
| 389 | $(document).on( |
| 390 | "wp-plugin-install-success wp-plugin-install-error", |
| 391 | function (event, response) { |
| 392 | alertInstance.close(); |
| 393 | if ( |
| 394 | typeof response.errorMessage !== "undefined" && |
| 395 | response.errorMessage.length > 0 |
| 396 | ) { |
| 397 | $.alert({ |
| 398 | title: response.errorMessage, |
| 399 | content: evf_setup_params.download_failed, |
| 400 | icon: "error", |
| 401 | }); |
| 402 | } else { |
| 403 | if (0 === wp.updates.queue.length) { |
| 404 | $.alert({ |
| 405 | title: evf_setup_params.install_confirmation_title, |
| 406 | theme: 'jconfirm-modern jconfirm-everest-forms', |
| 407 | icon: 'success', |
| 408 | backgroundDismiss: false, |
| 409 | scrollToPreviousElement: false, |
| 410 | content: evf_setup_params.install_confirmation_message, |
| 411 | buttons: { |
| 412 | confirm: { |
| 413 | text: evf_setup_params.save_changes_text, |
| 414 | btnClass:'btn-warning', |
| 415 | action: function () { |
| 416 | $('.everest-forms-save-button').trigger('click'); |
| 417 | location.reload(); |
| 418 | } |
| 419 | }, |
| 420 | cancel: { |
| 421 | text: evf_setup_params.reload_text, |
| 422 | btnClass:'btn-warning', |
| 423 | action: function () { |
| 424 | location.reload(); |
| 425 | } |
| 426 | } |
| 427 | }, |
| 428 | type:'green', |
| 429 | }); |
| 430 | } |
| 431 | } |
| 432 | } |
| 433 | ); |
| 434 | |
| 435 | // Check the queue, now that the event handlers have been added. |
| 436 | wp.updates.queueChecker(); |
| 437 | } |
| 438 | }; |
| 439 | |
| 440 | evf_setup_actions.init(); |
| 441 | }); |
| 442 |