gutenberg
7 years ago
admin.js
6 years ago
admin.min.js
6 years ago
editor.js
8 years ago
editor.min.js
7 years ago
evf-admin-email.js
6 years ago
evf-admin-email.min.js
6 years ago
evf-clipboard.js
8 years ago
evf-clipboard.min.js
8 years ago
evf-enhanced-select.js
7 years ago
evf-enhanced-select.min.js
7 years ago
evf-setup.js
6 years ago
evf-setup.min.js
6 years ago
extensions.js
6 years ago
extensions.min.js
6 years ago
form-builder.js
6 years ago
form-builder.min.js
6 years ago
form-template-controller.js
6 years ago
form-template-controller.min.js
6 years ago
plugins.js
7 years ago
plugins.min.js
8 years ago
settings.js
6 years ago
settings.min.js
6 years ago
upgrade.js
7 years ago
upgrade.min.js
7 years ago
evf-admin-email.js
268 lines
| 1 | /** |
| 2 | * EverestFormsEmail JS |
| 3 | * global evf_email_params |
| 4 | */ |
| 5 | ;(function($) { |
| 6 | var s; |
| 7 | var EverestFormsEmail = { |
| 8 | |
| 9 | settings: { |
| 10 | form : $('#everest-forms-builder-form'), |
| 11 | spinner: '<i class="evf-loading evf-loading-active" />' |
| 12 | }, |
| 13 | /** |
| 14 | * Start the engine. |
| 15 | * |
| 16 | */ |
| 17 | init: function() { |
| 18 | s = this.settings; |
| 19 | |
| 20 | $('.everest-forms-active-email-connections-list li').first().addClass('active-user'); |
| 21 | $('.evf-content-email-settings-inner').first().addClass('active-connection'); |
| 22 | |
| 23 | EverestFormsEmail.bindUIActions(); |
| 24 | }, |
| 25 | |
| 26 | ready: function() { |
| 27 | |
| 28 | s.formID = $('#everest-forms-builder-form').data('id'); |
| 29 | }, |
| 30 | |
| 31 | /** |
| 32 | * Element bindings. |
| 33 | * |
| 34 | */ |
| 35 | bindUIActions: function() { |
| 36 | $(document).on('click', '.everest-forms-email-add', function(e) { |
| 37 | EverestFormsEmail.connectionAdd(this, e); |
| 38 | }); |
| 39 | $(document).on('click', '.everest-forms-active-email-connections-list li', function(e) { |
| 40 | EverestFormsEmail.selectActiveAccount(this, e); |
| 41 | }); |
| 42 | $(document).on('click', '.email-remove', function(e) { |
| 43 | EverestFormsEmail.removeAccount(this, e); |
| 44 | }); |
| 45 | $(document).on('click', '.email-default-remove', function(e) { |
| 46 | EverestFormsEmail.removeDefaultAccount(this, e); |
| 47 | }); |
| 48 | $(document).on('input', '.everest-forms-email-name input', function(e) { |
| 49 | EverestFormsEmail.renameConnection(this, e); |
| 50 | }); |
| 51 | $(document).on('focusin', '.everest-forms-email-name input', function(e) { |
| 52 | EverestFormsEmail.focusConnectionName(this, e); |
| 53 | }); |
| 54 | |
| 55 | }, |
| 56 | |
| 57 | connectionAdd: function(el, e) { |
| 58 | e.preventDefault(); |
| 59 | |
| 60 | var $this = $(el), |
| 61 | source = 'email', |
| 62 | $connections = $this.closest('.everest-forms-panel-sidebar-content'), |
| 63 | $container = $this.parent(), |
| 64 | type = $this.data('type'), |
| 65 | namePrompt = evf_email_params.i18n_email_connection, |
| 66 | nameField = '<input autofocus="" type="text" id="provider-connection-name" placeholder="'+evf_email_params.i18n_email_placeholder+'">', |
| 67 | nameError = '<p class="error">'+evf_email_params.i18n_email_error_name+'</p>', |
| 68 | modalContent = namePrompt+nameField+nameError; |
| 69 | |
| 70 | modalContent = modalContent.replace(/%type%/g,type); |
| 71 | $.confirm({ |
| 72 | title: false, |
| 73 | content: modalContent, |
| 74 | icon: 'dashicons dashicons-info', |
| 75 | type: 'blue', |
| 76 | backgroundDismiss: false, |
| 77 | closeIcon: false, |
| 78 | buttons: { |
| 79 | confirm: { |
| 80 | text: evf_email_params.i18n_email_ok, |
| 81 | btnClass: 'btn-confirm', |
| 82 | keys: ['enter'], |
| 83 | action: function() { |
| 84 | var input = this.$content.find('input#provider-connection-name'); |
| 85 | var error = this.$content.find('.error'); |
| 86 | var value = input.val().trim(); |
| 87 | if ( value.length === 0 ) { |
| 88 | error.show(); |
| 89 | return false; |
| 90 | } else { |
| 91 | var name = value; |
| 92 | |
| 93 | // Fire AJAX |
| 94 | var data = { |
| 95 | action : 'everest_forms_new_email_add', |
| 96 | source : source, |
| 97 | name : name, |
| 98 | id : s.form.data('id'), |
| 99 | security: evf_email_params.ajax_email_nonce |
| 100 | } |
| 101 | $.ajax({ |
| 102 | url: evf_email_params.ajax_url, |
| 103 | data: data, |
| 104 | type: 'POST', |
| 105 | |
| 106 | success: function( response ){ |
| 107 | var cloned_email = $('.evf-content-email-settings-inner').first().clone(); |
| 108 | $('.evf-content-email-settings-inner').removeClass('active-connection'); |
| 109 | cloned_email.find('input:not(#qt_everest_forms_panel_field_email_connection_1_evf_email_message_toolbar input[type="button"], .evf_conditional_logic_container input)').val(''); |
| 110 | |
| 111 | cloned_email.find('.evf_conditional_logic_container input[type="checkbox"]').attr('checked', false); |
| 112 | cloned_email.find('.evf-field-conditional-container').hide(); |
| 113 | cloned_email.find('.evf-field-conditional-wrapper li:not(:first)').remove(); |
| 114 | cloned_email.find('.conditional_or:not(:first)').remove(); |
| 115 | cloned_email.find('.everest-forms-email-name input').val(name); |
| 116 | |
| 117 | setTimeout(function() { |
| 118 | cloned_email.find('.evf-field-conditional-input').val(''); |
| 119 | }, 2000); |
| 120 | |
| 121 | cloned_email.attr('data-connection_id',response.data.connection_id); |
| 122 | cloned_email.find('.evf-field-conditional-container').attr('data-connection_id',response.data.connection_id); |
| 123 | cloned_email.find('#everest-forms-panel-field-email-connection_1-connection_name').attr('name', 'settings[email]['+response.data.connection_id+'][connection_name]'); |
| 124 | cloned_email.find('#everest-forms-panel-field-email-connection_1-evf_to_email').attr('name', 'settings[email]['+response.data.connection_id+'][evf_to_email]'); |
| 125 | cloned_email.find('#everest-forms-panel-field-email-connection_1-evf_to_email').attr('value', '{admin_email}'); |
| 126 | cloned_email.find('#everest-forms-panel-field-email-connection_1-evf_carboncopy').attr('name', 'settings[email]['+response.data.connection_id+'][evf_carboncopy]'); |
| 127 | cloned_email.find('#everest-forms-panel-field-email-connection_1-evf_blindcarboncopy').attr('name', 'settings[email]['+response.data.connection_id+'][evf_blindcarboncopy]'); |
| 128 | cloned_email.find('#everest-forms-panel-field-email-connection_1-evf_from_name').attr('name', 'settings[email]['+response.data.connection_id+'][evf_from_name]'); |
| 129 | cloned_email.find('#everest-forms-panel-field-email-connection_1-evf_from_name').attr('value', evf_email_params.from_name ); |
| 130 | cloned_email.find('#everest-forms-panel-field-email-connection_1-evf_from_email').attr('name', 'settings[email]['+response.data.connection_id+'][evf_from_email]'); |
| 131 | cloned_email.find('#everest-forms-panel-field-email-connection_1-evf_from_email').attr('value', '{admin_email}'); |
| 132 | cloned_email.find('#everest-forms-panel-field-email-connection_1-evf_reply_to').attr('name', 'settings[email]['+response.data.connection_id+'][evf_reply_to]'); |
| 133 | cloned_email.find('#everest-forms-panel-field-email-connection_1-evf_email_subject').attr('name', 'settings[email]['+response.data.connection_id+'][evf_email_subject]'); |
| 134 | cloned_email.find('#everest-forms-panel-field-email-connection_1-evf_email_subject').attr('value', evf_email_params.email_subject ); |
| 135 | cloned_email.find('#everest_forms_panel_field_email_connection_1_evf_email_message').attr('name', 'settings[email]['+response.data.connection_id+'][evf_email_message]'); |
| 136 | cloned_email.find('#everest_forms_panel_field_email_connection_1_evf_email_message').attr('value', '{all_fields}'); |
| 137 | cloned_email.find('#everest-forms-panel-field-settingsemailconnection_1-attach_pdf_to_admin_email').attr('name', 'settings[email]['+response.data.connection_id+'][attach_pdf_to_admin_email]'); |
| 138 | cloned_email.find('#everest-forms-panel-field-settingsemailconnection_1-show_header_in_attachment_pdf_file').attr('name', 'settings[email]['+response.data.connection_id+'][show_header_in_attachment_pdf_file]'); |
| 139 | |
| 140 | cloned_email.find('#everest-forms-panel-field-email-connection_1-conditional_logic_status').attr('name', 'settings[email]['+response.data.connection_id+'][conditional_logic_status]'); |
| 141 | cloned_email.find('.evf_conditional_logic_container input[type="hidden"]').attr('name', 'settings[email]['+response.data.connection_id+'][conditional_logic_status]'); |
| 142 | cloned_email.find('.evf-field-show-hide').attr('name', 'settings[email]['+response.data.connection_id+'][conditional_option]'); |
| 143 | cloned_email.find('.evf-field-conditional-field-select').attr('name', 'settings[email]['+response.data.connection_id+'][conditionals][1][1][field]'); |
| 144 | cloned_email.find('.evf-field-conditional-condition').attr('name', 'settings[email]['+response.data.connection_id+'][conditionals][1][1][operator]'); |
| 145 | cloned_email.find('.evf-field-conditional-input').attr('name', 'settings[email]['+response.data.connection_id+'][conditionals][1][1][value]'); |
| 146 | $cloned_email = cloned_email.append('<input type="hidden" name="settings[email]['+response.data.connection_id+'][connection_name]" value="'+name+'">'); |
| 147 | |
| 148 | $('.evf-content-email-settings').append(cloned_email); |
| 149 | $connections.find('.evf-content-email-settings-inner').last().addClass('active-connection'); |
| 150 | $this.parent().find('.everest-forms-active-email-connections-list li').removeClass('active-user'); |
| 151 | $this.closest('.everest-forms-active-email.active').children('.everest-forms-active-email-connections-list').removeClass('empty-list'); |
| 152 | $this.parent().find('.everest-forms-active-email-connections-list ').append( '<li class="connection-list active-user" data-connection-id= "'+response.data.connection_id+'"><a class="user-nickname" href="#">'+name+'</a><a href="#"><span class="email-remove">Remove</span></a></li>' ); |
| 153 | } |
| 154 | }); |
| 155 | } |
| 156 | } |
| 157 | }, |
| 158 | cancel: { |
| 159 | text: evf_email_params.i18n_email_cancel |
| 160 | } |
| 161 | } |
| 162 | }); |
| 163 | }, |
| 164 | |
| 165 | selectActiveAccount: function(el, e) { |
| 166 | e.preventDefault(); |
| 167 | |
| 168 | var $this = $(el), |
| 169 | connection_id = $this.data('connection-id'), |
| 170 | active_block = $('.evf-content-email-settings').find('[data-connection_id="' + connection_id + '"]'), |
| 171 | lengthOfActiveBlock = $(active_block).length; |
| 172 | |
| 173 | $('.evf-content-email-settings').find('.evf-content-email-settings-inner').removeClass('active-connection'); |
| 174 | $this.siblings().removeClass('active-user'); |
| 175 | $this.addClass('active-user'); |
| 176 | |
| 177 | if( lengthOfActiveBlock ){ |
| 178 | $( active_block ).addClass('active-connection'); |
| 179 | } |
| 180 | |
| 181 | }, |
| 182 | |
| 183 | removeAccount: function(el, e) { |
| 184 | e.preventDefault(); |
| 185 | |
| 186 | var $this = $(el), |
| 187 | connection_id = $this.parent().parent().data('connection-id'), |
| 188 | active_block = $('.evf-content-email-settings').find('[data-connection_id="' + connection_id + '"]'), |
| 189 | lengthOfActiveBlock = $(active_block).length; |
| 190 | $.confirm({ |
| 191 | title: false, |
| 192 | content: "Are you sure you want to delete this Email?", |
| 193 | backgroundDismiss: false, |
| 194 | closeIcon: false, |
| 195 | icon: 'dashicons dashicons-info', |
| 196 | type: 'orange', |
| 197 | buttons: { |
| 198 | confirm: { |
| 199 | text: evf_email_params.i18n_email_ok, |
| 200 | btnClass: 'btn-confirm', |
| 201 | keys: ['enter'], |
| 202 | action: function(){ |
| 203 | if( lengthOfActiveBlock ){ |
| 204 | var toBeRemoved = $this.parent().parent(); |
| 205 | active_block_after = $('.evf-provider-connections').find('[data-connection_id="' + connection_id + '"]'), |
| 206 | lengthOfActiveBlockAfter = $(active_block).length; |
| 207 | if( toBeRemoved.prev().length ){ |
| 208 | toBeRemoved.prev('.connection-list').trigger('click'); |
| 209 | }else { |
| 210 | toBeRemoved.next('.connection-list').trigger('click'); |
| 211 | } |
| 212 | |
| 213 | $( active_block ).remove(); |
| 214 | toBeRemoved.remove(); |
| 215 | } |
| 216 | } |
| 217 | }, |
| 218 | cancel: { |
| 219 | text: evf_email_params.i18n_email_cancel |
| 220 | } |
| 221 | } |
| 222 | }); |
| 223 | }, |
| 224 | |
| 225 | removeDefaultAccount: function( el, e ) { |
| 226 | e.preventDefault; |
| 227 | $.alert({ |
| 228 | title: false, |
| 229 | content: "Default Email can not be deleted !", |
| 230 | icon: 'dashicons dashicons-info', |
| 231 | type: 'blue', |
| 232 | buttons: { |
| 233 | ok: { |
| 234 | text: evf_data.i18n_ok, |
| 235 | btnClass: 'btn-confirm', |
| 236 | keys: [ 'enter' ] |
| 237 | } |
| 238 | } |
| 239 | }); |
| 240 | }, |
| 241 | |
| 242 | focusConnectionName: function( el,e ){ |
| 243 | var $this = $(el); |
| 244 | $this.data('val', $this.val().trim()); |
| 245 | }, |
| 246 | |
| 247 | renameConnection: function( el,e ){ |
| 248 | e.preventDefault; |
| 249 | var $this = $(el); |
| 250 | var connection_id = $this.closest('.evf-content-email-settings-inner').data('connection_id'); |
| 251 | $active_block = $('.everest-forms-active-email-connections-list').find('[data-connection-id="' + connection_id + '"]'); |
| 252 | $active_block.find('.user-nickname').text($this.val()); |
| 253 | if ( $this.val().trim().length === 0 ) { |
| 254 | $this.parent('.everest-forms-email-name').find('.everest-forms-error').remove(); |
| 255 | $this.parent('.everest-forms-email-name').append('<p class="everest-forms-error everest-forms-text-danger">Email name cannot be empty.</p>'); |
| 256 | $this.next('.everest-forms-error').fadeOut(3000); |
| 257 | setTimeout(function() { |
| 258 | if ( $this.val().length === 0 ){ |
| 259 | $this.val($this.data('val')); |
| 260 | $active_block.find('.user-nickname').text($this.data('val')); |
| 261 | } |
| 262 | }, 3000); |
| 263 | } |
| 264 | } |
| 265 | } |
| 266 | EverestFormsEmail.init(); |
| 267 | })(jQuery); |
| 268 |