Skip to content

Commit d1b910e

Browse files
committed
Added 'delete all value mappings' button
1 parent 3102a5e commit d1b910e

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

Diff for: html/settings.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,13 @@
132132
<td class="pdf-field"><input type="text" class="pdf-value" /></td>
133133
<td class="buttons">
134134
<a class="button button-small delete-valuemapping-button" href="#">{delete}</a>
135+
<a class="button button-small delete-all-valuemappings-button" href="#">{delete-all}</a>
135136
</td>
136137
</tr>
137138
<tr class="delete-all-row">
138139
<td colspan="3"></td>
139140
<td class="buttons">
140-
<a class="button button-small delete-all-mappings-button" href="#">{delete-all-mappings}</a>
141+
<a class="button button-small delete-all-mappings-button" href="#">{delete-all}</a>
141142
</td>
142143
</tr>
143144
</tbody>

Diff for: js/admin.js

+34-1
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,19 @@ jQuery(document).ready(function($) {
10581058
tag.find('input.wpf-value').val(data.wpf_value);
10591059
tag.find('input.pdf-value').val(data.pdf_value);
10601060

1061+
// make sure the "Delete All" button is shown in the list of value mappings for current field mapping only once
1062+
var manageDeleteAllValueMappingsButton = function(mapping_id) {
1063+
1064+
var value_mapping_rows = template.parent().find('.pdf-valuemapping-row').filter(function() {
1065+
return jQuery(this).data('mapping_id') === mapping_id;
1066+
});
1067+
1068+
value_mapping_rows.find('.delete-all-valuemappings-button').hide();
1069+
1070+
if(value_mapping_rows.length > 1) // no need to show the "Delete All" button if there is only one value mapping
1071+
value_mapping_rows.last().find('.delete-all-valuemappings-button').show();
1072+
};
1073+
10611074
var delete_button = tag.find('.delete-valuemapping-button');
10621075
delete_button.data('value_mapping_id', data.value_mapping_id);
10631076
delete_button.click(function(event) {
@@ -1071,11 +1084,31 @@ jQuery(document).ready(function($) {
10711084

10721085
deleteValueMapping(jQuery(this).data('value_mapping_id'));
10731086

1074-
jQuery(this).closest('.pdf-valuemapping-row').remove();
1087+
var value_mapping_row = jQuery(this).closest('.pdf-valuemapping-row');
1088+
var mapping_id = value_mapping_row.data('mapping_id');
1089+
value_mapping_row.remove();
1090+
manageDeleteAllValueMappingsButton(mapping_id);
1091+
});
1092+
1093+
var delete_all_button = tag.find('.delete-all-valuemappings-button');
1094+
delete_all_button.data('mapping_id', data.mapping_id);
1095+
delete_all_button.click(function(event) {
1096+
1097+
// prevent running default button click handlers
1098+
event.stopPropagation();
1099+
event.preventDefault();
1100+
1101+
if(!confirm(pdf_forms_for_wpforms.__Confirm_Delete_All_Value_Mappings))
1102+
return;
1103+
1104+
var mapping_id = jQuery(this).data('mapping_id');
1105+
deleteValueMappings(mapping_id);
10751106
});
10761107

10771108
var mappingTag = jQuery('.pdf-forms-for-wpforms-admin .pdf-mapping-row[data-mapping_id="'+data.mapping_id+'"]');
10781109
tag.insertAfter(mappingTag);
1110+
1111+
manageDeleteAllValueMappingsButton(data.mapping_id);
10791112
};
10801113

10811114
var addMapping = function(data)

Diff for: pdf-forms-for-wpforms.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -1624,7 +1624,7 @@ public function add_settings_content( $instance )
16241624
'pdf-field' => esc_html__( 'PDF field', 'pdf-forms-for-wpforms' ),
16251625
'wpf-field' => esc_html__( 'WPForms field / smart tags', 'pdf-forms-for-wpforms' ),
16261626
'add-mapping' => esc_html__( 'Add Mapping', 'pdf-forms-for-wpforms' ),
1627-
'delete-all-mappings' => esc_html__( 'Delete All', 'pdf-forms-for-wpforms' ),
1627+
'delete-all' => esc_html__( 'Delete All', 'pdf-forms-for-wpforms' ),
16281628
'new-field' => esc_html__( 'New Field:', 'pdf-forms-for-wpforms' ),
16291629
'image-embedding' => esc_html__( 'Image Embedding Tool', 'pdf-forms-for-wpforms' ),
16301630
'image-embedding-help'=> esc_html__( 'This tool allows embedding of images into PDF files. Images are taken from file upload fields or URL field values. You can select a PDF file page and draw a bounding box for image insertion. Alternatively, you can insert your image in the center of every page.', 'pdf-forms-for-wpforms' ),
@@ -1689,6 +1689,7 @@ public function admin_enqueue_scripts( $hook )
16891689
'__Confirm_Delete_Attachment' => __( 'Are you sure you want to delete this file? This will delete field mappings and image embeds associated with this file.', 'pdf-forms-for-wpforms' ),
16901690
'__Confirm_Delete_Mapping' => __( 'Are you sure you want to delete this mapping?', 'pdf-forms-for-wpforms' ),
16911691
'__Confirm_Delete_All_Mappings' => __( 'Are you sure you want to delete all mappings?', 'pdf-forms-for-wpforms' ),
1692+
'__Confirm_Delete_All_Value_Mappings' => __( 'Are you sure you want to delete all value mappings?', 'pdf-forms-for-wpforms' ),
16921693
'__Confirm_Attach_Empty_Pdf' => __( 'Are you sure you want to attach a PDF file without any form fields?', 'pdf-forms-for-wpforms' ),
16931694
'__Confirm_Delete_Embed' => __( 'Are you sure you want to delete this embeded image?', 'pdf-forms-for-wpforms' ),
16941695
'__Show_Help' => __( 'Show Help', 'pdf-forms-for-wpforms' ),

0 commit comments

Comments
 (0)