| 1 |
(function($) { |
| 2 |
"use strict"; |
| 3 |
$( document ).ready( function () { |
| 4 |
$("body").on("change",".pdfcreator_wpforms",function(){ |
| 5 |
var form_id = $(this).val(); |
| 6 |
$("#pdfcreator_wpforms_entry").html("<option>Loading...</option>"); |
| 7 |
$.ajax({ |
| 8 |
url: ajaxurl, |
| 9 |
'type': "POST", |
| 10 |
data: { |
| 11 |
action: 'yeepdf_wp_get_entries', |
| 12 |
form_id: form_id |
| 13 |
}, |
| 14 |
success: function(msg){ |
| 15 |
var ot = '<option value="0">Sample to show</option>'; |
| 16 |
ot += msg; |
| 17 |
$("#pdfcreator_wpforms_entry").html(ot); |
| 18 |
} |
| 19 |
}); |
| 20 |
}) |
| 21 |
$("body").on("change","#wpforms-panel-field-settings-yeepdf_creator_enable",function(e){ |
| 22 |
if($(this).is(":checked")){ |
| 23 |
$(".wpforms-yeepdf_creator").show().removeClass("hidden"); |
| 24 |
}else{ |
| 25 |
$(".wpforms-yeepdf_creator").hide().addClass("hidden"); |
| 26 |
} |
| 27 |
}) |
| 28 |
$("body").on("click",".wpforms-yeepdf_creator-add",function(e){ |
| 29 |
var $el = $(this); |
| 30 |
var $builder = $("#wpforms-builder"); |
| 31 |
var nextID = Number( $el.attr( 'data-next-id' ) ), |
| 32 |
panelID = $el.closest( '.wpforms-panel-content-section' ).data( 'panel' ), |
| 33 |
blockType = $el.data( 'block-type' ), |
| 34 |
namePrompt = wpforms_builder[ blockType + '_prompt' ], |
| 35 |
nameField = '<input autofocus="" type="text" id="settings-block-name" placeholder="' + wpforms_builder[ blockType + '_ph' ] + '">', |
| 36 |
nameError = '<p class="error">' + wpforms_builder[ blockType + '_error' ] + '</p>', |
| 37 |
modalContent = namePrompt + nameField + nameError; |
| 38 |
var modal = $.confirm( { |
| 39 |
container: $builder, |
| 40 |
title: false, |
| 41 |
content: modalContent, |
| 42 |
icon: 'fa fa-info-circle', |
| 43 |
type: 'blue', |
| 44 |
buttons: { |
| 45 |
confirm: { |
| 46 |
text: wpforms_builder.ok, |
| 47 |
btnClass: 'btn-confirm', |
| 48 |
keys: [ 'enter' ], |
| 49 |
action: function() { |
| 50 |
var settingsBlockName = $.trim( this.$content.find( 'input#settings-block-name' ).val() ), |
| 51 |
error = this.$content.find( '.error' ); |
| 52 |
if ( settingsBlockName === '' ) { |
| 53 |
error.show(); |
| 54 |
return false; |
| 55 |
} else { |
| 56 |
var $firstSettingsBlock = $el.closest( '.wpforms-panel-content-section' ).find( '.wpforms-builder-settings-block' ).first(); |
| 57 |
// Restore tooltips before cloning. |
| 58 |
wpf.restoreTooltips( $firstSettingsBlock ); |
| 59 |
var $newSettingsBlock = $firstSettingsBlock.clone(), |
| 60 |
blockID = $firstSettingsBlock.data( 'block-id' ), |
| 61 |
newSettingsBlock; |
| 62 |
$newSettingsBlock.attr( 'data-block-id', nextID ); |
| 63 |
$newSettingsBlock.find( '.wpforms-builder-settings-block-header span' ).text( settingsBlockName ); |
| 64 |
$newSettingsBlock.find( 'input, textarea, select' ).not( '.from-name input' ).not( '.from-email input' ).each( function( index, el ) { |
| 65 |
var $this = $( this ); |
| 66 |
if ( $this.attr( 'name' ) ) { |
| 67 |
$this.val( '' ).attr( 'name', $this.attr( 'name' ).replace( /\[(\d+)\]/, '[' + nextID + ']' ) ); |
| 68 |
if ( $this.is( 'select' ) ) { |
| 69 |
$this.find( 'option' ).prop( 'selected', false ).attr( 'selected', false ); |
| 70 |
$this.find( 'option:first' ).prop( 'selected', true ).attr( 'selected', 'selected' ); |
| 71 |
} else if ( $this.attr( 'type' ) === 'checkbox' ) { |
| 72 |
$this.prop( 'checked', false ).attr( 'checked', false ).val( '1' ); |
| 73 |
} else { |
| 74 |
$this.val( '' ).attr( 'value', '' ); |
| 75 |
} |
| 76 |
} |
| 77 |
} ); |
| 78 |
// Update elements IDs. |
| 79 |
var idPrefixPanel = 'wpforms-panel-field-' + panelID + '-', |
| 80 |
idPrefixBlock = idPrefixPanel + blockID; |
| 81 |
$newSettingsBlock.find( '[id^="' + idPrefixBlock + '"], [for^="' + idPrefixBlock + '"]' ).each( function( index, el ) { |
| 82 |
var $el = $( this ), |
| 83 |
attr = $el.prop( 'tagName' ) === 'LABEL' ? 'for' : 'id', |
| 84 |
elID = $el.attr( attr ).replace( new RegExp( idPrefixBlock, 'g' ), idPrefixPanel + nextID ); |
| 85 |
$el.attr( attr, elID ); |
| 86 |
} ); |
| 87 |
// Update `notification by status` checkboxes. |
| 88 |
var radioGroup = blockID + '-notification-by-status'; |
| 89 |
$newSettingsBlock.find( '[data-radio-group="' + radioGroup + '"]' ).each( function( index, el ) { |
| 90 |
$( this ) |
| 91 |
.removeClass( 'wpforms-radio-group-' + radioGroup ) |
| 92 |
.addClass( 'wpforms-radio-group-' + nextID + '-notification-by-status' ) |
| 93 |
.attr( 'data-radio-group', nextID + '-notification-by-status' ); |
| 94 |
} ); |
| 95 |
$newSettingsBlock.find( '.wpforms-builder-settings-block-header input' ).val( settingsBlockName ).attr( 'value', settingsBlockName ); |
| 96 |
if ( blockType === 'notification' ) { |
| 97 |
$newSettingsBlock.find( '.email-msg textarea' ).val( '{all_fields}' ).attr( 'value', '{all_fields}' ); |
| 98 |
$newSettingsBlock.find( '.email-recipient input' ).val( '{admin_email}' ).attr( 'value', '{admin_email}' ); |
| 99 |
} |
| 100 |
$newSettingsBlock.removeClass( 'wpforms-builder-settings-block-default' ); |
| 101 |
if ( blockType === 'confirmation' ) { |
| 102 |
$newSettingsBlock.find( '.wpforms-panel-field-tinymce' ).remove(); |
| 103 |
if ( typeof WPForms !== 'undefined' ) { |
| 104 |
$newSettingsBlock.find( '.wpforms-panel-field-confirmations-type-wrap' ) |
| 105 |
.after( WPForms.Admin.Builder.Templates |
| 106 |
.get( 'wpforms-builder-confirmations-message-field' )( { |
| 107 |
id: nextID, |
| 108 |
} ) |
| 109 |
); |
| 110 |
} |
| 111 |
} |
| 112 |
// Conditional logic, if present |
| 113 |
var $conditionalLogic = $newSettingsBlock.find( '.wpforms-conditional-block' ); |
| 114 |
if ( $conditionalLogic.length && typeof WPForms !== 'undefined' ) { |
| 115 |
$conditionalLogic |
| 116 |
.html( WPForms.Admin.Builder.Templates |
| 117 |
.get( 'wpforms-builder-conditional-logic-toggle-field' )( { |
| 118 |
id: nextID, |
| 119 |
type: blockType, |
| 120 |
actions: JSON.stringify( $newSettingsBlock.find( '.wpforms-panel-field-conditional_logic-checkbox' ).data( 'actions' ) ), |
| 121 |
actionDesc: $newSettingsBlock.find( '.wpforms-panel-field-conditional_logic-checkbox' ).data( 'action-desc' ), |
| 122 |
} ) |
| 123 |
); |
| 124 |
} |
| 125 |
// Fields Map Table, if present. |
| 126 |
var $fieldsMapTable = $newSettingsBlock.find( '.wpforms-field-map-table' ); |
| 127 |
if ( $fieldsMapTable.length ) { |
| 128 |
$fieldsMapTable.each( function( index, el ) { |
| 129 |
var $table = $( el ); |
| 130 |
// Clean table fields. |
| 131 |
$table.find( 'tr:not(:first-child)' ).remove(); |
| 132 |
var $input = $table.find( '.key input' ), |
| 133 |
$select = $table.find( '.field select' ), |
| 134 |
name = $select.data( 'name' ); |
| 135 |
$input.attr( 'value', '' ); |
| 136 |
$select |
| 137 |
.attr( 'name', '' ) |
| 138 |
.attr( 'data-name', name.replace( /\[(\d+)\]/, '[' + nextID + ']' ) ); |
| 139 |
} ); |
| 140 |
} |
| 141 |
newSettingsBlock = $newSettingsBlock.wrap( '<div>' ).parent().html(); |
| 142 |
newSettingsBlock = newSettingsBlock.replace( /\[conditionals\]\[(\d+)\]\[(\d+)\]/g, '[conditionals][0][0]' ); |
| 143 |
$firstSettingsBlock.before( newSettingsBlock ); |
| 144 |
var $addedSettingBlock = $firstSettingsBlock.prev(); |
| 145 |
// Reset the confirmation type to the 1st one. |
| 146 |
if ( blockType === 'confirmation' ) { |
| 147 |
app.confirmationFieldsToggle( $( '.wpforms-panel-field-confirmations-type' ).first() ); |
| 148 |
} |
| 149 |
// Init the WP Editor. |
| 150 |
if ( typeof tinymce !== 'undefined' && typeof wp.editor !== 'undefined' && blockType === 'confirmation' ) { |
| 151 |
wp.editor.initialize( 'wpforms-panel-field-confirmations-message-' + nextID, s.tinymceDefaults ); |
| 152 |
} |
| 153 |
// Init tooltips for new section. |
| 154 |
wpf.initTooltips(); |
| 155 |
$builder.trigger( 'wpformsSettingsBlockAdded', [ $addedSettingBlock ] ); |
| 156 |
$el.attr( 'data-next-id', nextID + 1 ); |
| 157 |
} |
| 158 |
}, |
| 159 |
}, |
| 160 |
cancel: { |
| 161 |
text: wpforms_builder.cancel, |
| 162 |
}, |
| 163 |
}, |
| 164 |
} ); |
| 165 |
}) |
| 166 |
}) |
| 167 |
})(jQuery); |