PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 4.0.3
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v4.0.3
4.0.3 4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 341 releases
profile-builder / assets / js / jquery-epf-rf.js

jquery-epf-rf.js in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 4.0.3, at assets/js/jquery-epf-rf.js

166 lines 7.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 function wppb_epf_rf_disable_live_select ( selector ){
2 jQuery( selector ).attr( 'disabled', true );
3 }
4
5 function wppb_rf_epf_change_id( field, container_name, fieldObj ) {
6 var buttonInContainer = jQuery( '.button-primary', fieldObj.parent().parent().parent() );
7 buttonInContainer.attr('disabled',true);
8 buttonInContainer.attr('tempclick', buttonInContainer.attr("onclick") );
9 buttonInContainer.removeAttr('onclick');
10
11 jQuery.post( ajaxurl , { action:"wppb_handle_rf_epf_id_change", field:field, _ajax_nonce: ( typeof wppbEpfRf !== 'undefined' ? wppbEpfRf.nonce : '' ) }, function(response) {
12
13 /**
14 * since version 2.0.2 we have the id directly on the option in the select so this ajax function is a little
15 redundant but can't be sure of the impact on other features so we will just add this
16 */
17 id = fieldObj.find(":selected").attr( 'data-id' );
18 if( !id ){
19 id = response;
20 }
21
22 jQuery( '#id', fieldObj.parent().parent().parent() ).val( id );
23 buttonInContainer.attr('onclick', buttonInContainer.attr("tempclick") );
24 buttonInContainer.removeAttr('tempclick');
25
26 if( ( fieldObj.parents('.update_container_wppb_rf_fields').length || fieldObj.parents('.update_container_wppb_epf_fields').length ) && buttonInContainer.attr('disabled') ) {
27 buttonInContainer.text('Save Changes');
28 }
29
30 buttonInContainer.removeAttr('disabled');
31 });
32 }
33
34 jQuery(function(){
35 wppb_disable_delete_on_default_mandatory_fields();
36 wppb_disable_select_field_options();
37
38 jQuery(document).on( 'change', '#wppb_rf_fields .mb-list-entry-fields #field', function () {
39 wppb_rf_epf_change_id( jQuery(this).val(), '#wppb_rf_fields', jQuery(this) );
40 });
41 jQuery(document).on( 'change', '.update_container_wppb_rf_fields .mb-list-entry-fields #field', function () {
42 wppb_rf_epf_change_id( jQuery(this).val(), '.update_container_wppb_rf_fields', jQuery(this) );
43 });
44
45 jQuery(document).on( 'change', '#wppb_epf_fields .mb-list-entry-fields #field', function () {
46 wppb_rf_epf_change_id( jQuery(this).val(), '#wppb_epf_fields', jQuery(this) );
47 });
48
49 jQuery(document).on( 'change', '.update_container_wppb_epf_fields .mb-list-entry-fields #field', function () {
50 wppb_rf_epf_change_id( jQuery(this).val(), '.update_container_wppb_epf_fields', jQuery(this) );
51 });
52 });
53
54 /* function that removes the delete button and disables changing the field type on edit for username,password and email default fields */
55 function wppb_disable_delete_on_default_mandatory_fields(){
56 jQuery( '#container_wppb_rf_fields [class$="default-username added_fields_list"] .mbdelete, #container_wppb_rf_fields [class$="default-e-mail added_fields_list"] .mbdelete, #container_wppb_rf_fields [class$="default-password added_fields_list"] .mbdelete' ).hide(); // PB specific line
57 jQuery( '[class$="default-username"] #field, [class$="default-e-mail"] #field, [class$="default-password"] #field' ).attr( 'disabled', true ); // PB specific line
58 }
59
60 /* Disables the options in the field select drop-down that are also present in the table below */
61 function wppb_disable_select_field_options() {
62 jQuery('#field option').each( function() {
63 $optionField = jQuery(this);
64 $optionField.removeAttr('disabled');
65
66 var optionFieldId = jQuery(this).attr('data-id');
67
68 jQuery('#container_wppb_rf_fields .row-id pre, #container_wppb_epf_fields .row-id pre').each( function() {
69 if( jQuery(this).text() == optionFieldId ) {
70 $optionField.attr('disabled', true);
71 }
72 });
73 });
74
75 wppb_check_options_disabled_add_field();
76 }
77
78 /*
79 * Check to see if the selected field in the add new field to the list select drop-down is disabled
80 * We don't want this to happen, so select the first option instead
81 */
82 function wppb_check_options_disabled_add_field() {
83 if( jQuery('#wppb_rf_fields #field option:selected, #wppb_epf_fields #field option:selected').is(':disabled') ) {
84 jQuery('#wppb_rf_fields #field option, #wppb_epf_fields #field option').first().attr('selected', true);
85 }
86 }
87
88 /*
89 * Run through all the field drop-downs, in edit mode, and check if the selected option is disabled
90 * If it is, disable the save button and if the date-id of the selected option matches the id of the field
91 * change the text of the button
92 */
93 function wppb_check_options_disabled_edit_field() {
94 jQuery('.update_container_wppb_rf_fields #field, .update_container_wppb_epf_fields #field').each( function() {
95
96 $selectedOption = jQuery(this).children('option:selected');
97 $primaryButton = jQuery(this).parents('.mb-list-entry-fields').find('.button-primary');
98
99 if( $selectedOption.is(':disabled') ) {
100 $rowId = parseInt( jQuery(this).parents('tr').prev().find('.row-id pre').text() );
101
102 $primaryButton.attr('disabled', true);
103 $primaryButton[0].onclick = null;
104
105 if( $rowId != parseInt( $selectedOption.attr('data-id') ) ) {
106 $primaryButton.text('This field has already been added to the form');
107 }
108 } else {
109 $primaryButton.attr('disabled', false);
110
111 var tempBtnOnClick = $primaryButton.attr('onclick');
112 $primaryButton.text('Save Changes').removeAttr('onclick').attr('onclick', tempBtnOnClick);
113 }
114
115 });
116 }
117
118 /*
119 * Check to see if the selected field in the edit field select drop-down is disabled
120 * If it is we want to disable saving, because no changes have been made
121 */
122 function wppb_check_update_field_options_disabled() {
123 jQuery('.update_container_wppb_rf_fields #field, .update_container_wppb_epf_fields #field').each( function() {
124 if( jQuery(this).find('option:selected').is(':disabled') ) {
125 jQuery(this).parents('.mb-list-entry-fields').find('.button-primary').attr('disabled', true);
126 jQuery(this).parents('.mb-list-entry-fields').find('.button-primary')[0].onclick = null;
127 }
128 });
129 }
130
131 /*
132 * Function that sends an ajax request to delete all items(fields) from a form
133 *
134 */
135 function wppb_rf_epf_delete_all_fields(event, delete_all_button_id, nonce) {
136 event.preventDefault();
137 $deleteButton = jQuery('#' + delete_all_button_id);
138
139 var response = confirm( "Are you sure you want to delete all items ?" );
140
141 if( response == true ) {
142 $tableParent = $deleteButton.parents('table');
143
144 var meta = $tableParent.attr('id').replace('container_', '');
145 var post_id = parseInt( $tableParent.attr('post') );
146
147 $tableParent.parent().css({'opacity':'0.4', 'position':'relative'}).append('<div id="mb-ajax-loading"></div>');
148
149 jQuery.post( ajaxurl, { action: "wppb_rf_epf_delete_all_fields", meta: meta, id: post_id, _ajax_nonce: nonce }, function(response) {
150
151 /* refresh the list */
152 jQuery.post( wppbWckAjaxurl, { action: "wck_refresh_list"+meta, meta: meta, id: post_id}, function(response) {
153 jQuery('#container_'+meta).replaceWith(response);
154 $tableParent = jQuery('#container_'+meta);
155
156 $tableParent.find('tbody td').css('width', function(){ return jQuery(this).width() });
157
158 mb_sortable_elements();
159 $tableParent.parent().css('opacity','1');
160
161 jQuery('#mb-ajax-loading').remove();
162 });
163
164 });
165 }
166 }