PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 2.0.3
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v2.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-manage-fields-live-change.js

jquery-manage-fields-live-change.js in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 2.0.3, at assets/js/jquery-manage-fields-live-change.js

525 lines 20.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 var fields = {
2 'Default - Name (Heading)': { 'show_rows' : [
3 '.row-field-title',
4 '.row-description',
5 ],
6 'properties': {
7 'meta_name_value' : ''
8 }
9 },
10
11 'Default - Contact Info (Heading)': { 'show_rows' : [
12 '.row-field-title',
13 '.row-description',
14 ],
15 'properties': {
16 'meta_name_value' : ''
17 }
18 },
19
20 'Default - About Yourself (Heading)': { 'show_rows' : [
21 '.row-field-title',
22 '.row-description',
23 ],
24 'properties': {
25 'meta_name_value' : ''
26 }
27 },
28
29 'Default - Username': { 'show_rows' : [
30 '.row-field-title',
31 '.row-description',
32 '.row-default-value',
33 '.row-required'
34 ],
35 'properties': {
36 'meta_name_value' : ''
37 },
38 'required' : [
39 true
40 ]
41 },
42
43 'Default - First Name': { 'show_rows' : [
44 '.row-field-title',
45 '.row-meta-name',
46 '.row-description',
47 '.row-default-value',
48 '.row-required'
49 ],
50 'properties': {
51 'meta_name_value' : 'first_name'
52 }
53 },
54
55 'Default - Last Name': { 'show_rows' : [
56 '.row-field-title',
57 '.row-meta-name',
58 '.row-description',
59 '.row-default-value',
60 '.row-required'
61 ],
62 'properties': {
63 'meta_name_value' : 'last_name'
64 }
65 },
66
67 'Default - Nickname': { 'show_rows' : [
68 '.row-field-title',
69 '.row-meta-name',
70 '.row-description',
71 '.row-default-value',
72 '.row-required'
73 ],
74 'properties': {
75 'meta_name_value' : 'nickname'
76 },
77 'required' : [
78 true
79 ]
80 },
81
82 'Default - E-mail': { 'show_rows' : [
83 '.row-field-title',
84 '.row-description',
85 '.row-default-value',
86 '.row-required'
87 ],
88 'properties': {
89 'meta_name_value' : ''
90 },
91 'required' : [
92 true
93 ]
94 },
95
96 'Default - Website': { 'show_rows' : [
97 '.row-field-title',
98 '.row-description',
99 '.row-default-value',
100 '.row-required'
101 ],
102 'properties': {
103 'meta_name_value' : ''
104 }
105 },
106
107 'Default - AIM': { 'show_rows' : [
108 '.row-field-title',
109 '.row-meta-name',
110 '.row-description',
111 '.row-default-value',
112 '.row-required'
113 ],
114 'properties': {
115 'meta_name_value' : 'aim'
116 }
117 },
118
119 'Default - Yahoo IM': { 'show_rows' : [
120 '.row-field-title',
121 '.row-meta-name',
122 '.row-description',
123 '.row-default-value',
124 '.row-required'
125 ],
126 'properties': {
127 'meta_name_value' : 'yim'
128 }
129 },
130
131 'Default - Jabber / Google Talk': { 'show_rows' : [
132 '.row-field-title',
133 '.row-meta-name',
134 '.row-description',
135 '.row-default-value',
136 '.row-required'
137 ],
138 'properties': {
139 'meta_name_value' : 'jabber'
140 }
141 },
142
143 'Default - Password': { 'show_rows' : [
144 '.row-field-title',
145 '.row-description',
146 '.row-default-value',
147 '.row-required'
148 ],
149 'properties': {
150 'meta_name_value' : ''
151 },
152 'required' : [
153 true
154 ]
155 },
156
157 'Default - Repeat Password': { 'show_rows' : [
158 '.row-field-title',
159 '.row-description',
160 '.row-default-value',
161 '.row-required'
162 ],
163 'properties': {
164 'meta_name_value' : ''
165 },
166 'required' : [
167 true
168 ]
169 },
170
171 'Default - Biographical Info': { 'show_rows' : [
172 '.row-field-title',
173 '.row-meta-name',
174 '.row-description',
175 '.row-row-count',
176 '.row-default-content',
177 '.row-required'
178 ],
179 'properties': {
180 'meta_name_value' : 'description'
181 }
182 },
183
184 'Default - Display name publicly as': { 'show_rows' : [
185 '.row-field-title',
186 '.row-description',
187 '.row-default-value',
188 '.row-required'
189 ],
190 'properties': {
191 'meta_name_value' : ''
192 }
193 },
194
195 'Heading': { 'show_rows' : [
196 '.row-field-title',
197 '.row-description',
198 ],
199 'properties': {
200 'meta_name_value' : ''
201 }
202 },
203
204 'Input': { 'show_rows' : [
205 '.row-field-title',
206 '.row-meta-name',
207 '.row-description',
208 '.row-default-value',
209 '.row-required',
210 '.row-overwrite-existing'
211 ]
212 },
213 'Input (Hidden)': { 'show_rows' : [
214 '.row-field-title',
215 '.row-meta-name',
216 '.row-description',
217 '.row-default-value',
218 '.row-overwrite-existing'
219 ]
220 },
221
222 'Textarea': { 'show_rows' : [
223 '.row-field-title',
224 '.row-meta-name',
225 '.row-description',
226 '.row-default-content',
227 '.row-required',
228 '.row-row-count',
229 '.row-overwrite-existing'
230 ]
231 },
232
233 'Select': { 'show_rows' : [
234 '.row-field-title',
235 '.row-meta-name',
236 '.row-description',
237 '.row-default-option',
238 '.row-required',
239 '.row-overwrite-existing',
240 '.row-options',
241 '.row-labels'
242 ]
243 },
244 'Select (Multiple)': { 'show_rows' : [
245 '.row-field-title',
246 '.row-meta-name',
247 '.row-description',
248 '.row-default-options',
249 '.row-required',
250 '.row-overwrite-existing',
251 '.row-options',
252 '.row-labels'
253 ]
254 },
255
256 'Select (Country)': { 'show_rows' : [
257 '.row-field-title',
258 '.row-meta-name',
259 '.row-description',
260 '.row-required',
261 '.row-overwrite-existing'
262 ]
263 },
264
265 'Select (Timezone)': { 'show_rows' : [
266 '.row-field-title',
267 '.row-meta-name',
268 '.row-description',
269 '.row-required',
270 '.row-overwrite-existing'
271 ]
272 },
273
274 'Checkbox': { 'show_rows' : [
275 '.row-field-title',
276 '.row-meta-name',
277 '.row-description',
278 '.row-default-options',
279 '.row-required',
280 '.row-overwrite-existing',
281 '.row-options',
282 '.row-labels'
283 ]
284 },
285
286 'Checkbox (Terms and Conditions)': { 'show_rows' : [
287 '.row-field-title',
288 '.row-meta-name',
289 '.row-description',
290 '.row-required',
291 '.row-overwrite-existing'
292 ],
293 'required' : [
294 true
295 ]
296 },
297
298 'Radio': { 'show_rows' : [
299 '.row-field-title',
300 '.row-meta-name',
301 '.row-description',
302 '.row-default-option',
303 '.row-required',
304 '.row-overwrite-existing',
305 '.row-options',
306 '.row-labels'
307 ]
308 },
309
310 'Upload': { 'show_rows' : [
311 '.row-field-title',
312 '.row-meta-name',
313 '.row-description',
314 '.row-allowed-extensions',
315 '.row-required',
316 '.row-allowed-upload-extensions'
317 ]
318 },
319
320 'Avatar': { 'show_rows' : [
321 '.row-field-title',
322 '.row-meta-name',
323 '.row-description',
324 '.row-allowed-image-extensions',
325 '.row-avatar-size',
326 '.row-required',
327 '.row-overwrite-existing'
328 ]
329 },
330
331 'Datepicker': { 'show_rows' : [
332 '.row-field-title',
333 '.row-meta-name',
334 '.row-description',
335 '.row-default-value',
336 '.row-required',
337 '.row-date-format',
338 '.row-overwrite-existing'
339 ]
340 },
341
342 'reCAPTCHA': { 'show_rows' : [
343 '.row-field-title',
344 '.row-meta-name',
345 '.row-description',
346 '.row-public-key',
347 '.row-private-key',
348 '.row-required',
349 '.row-overwrite-existing'
350 ],
351 'required' : [
352 true
353 ]
354 }
355 }
356 var fields_to_show = [
357 '.row-field-title',
358 '.row-field',
359 '.row-meta-name',
360 '.row-required'
361 ]
362
363 function wppb_hide_properties_for_already_added_fields( container_name ){
364
365 jQuery( container_name + ' tr' ).each(function() {
366
367 field = jQuery('.row-field', this).text();
368 field = jQuery.trim(field.replace('Field: ', ''));
369
370
371 jQuery( 'li', this ).each(function() {
372 var class_name = '';
373
374 class_name = jQuery(this).attr('class');
375 jQuery(this).hide();
376
377 if ( ( field in fields ) ){
378 var to_show = fields[field]['show_rows'];
379 for (var key in to_show) {
380 if ('.'+class_name == fields_to_show[key]){
381 jQuery(this).show();
382 }
383 }
384 }
385
386 });
387 });
388
389 /* hide the delete button for username,password and email fields */
390 jQuery( container_name + ' ' + '.element_type_default-e-mail .mbdelete,' + ' ' + container_name + ' ' + '.element_type_default-password .mbdelete,' + ' ' + container_name + ' ' + '.element_type_default-username .mbdelete' ).hide(); // PB specific line
391 }
392
393
394
395 function wppb_hide_all ( container_name ){
396 jQuery( container_name + ' ' + '.mb-list-entry-fields > li' ).each(function() {
397 if ( !( ( jQuery(this).hasClass('row-field') ) || ( jQuery(this).children().hasClass('button-primary') ) ) ){
398 jQuery(this).hide();
399 }
400 });
401
402 jQuery( container_name + ' ' + '.mb-list-entry-fields .button-primary' ).attr( 'disabled', true );
403
404 jQuery( container_name + ' ' + '.element_type_default-e-mail .mbdelete,' + ' ' + container_name + ' ' + '.element_type_default-password .mbdelete,' + ' ' + container_name + ' ' + '.element_type_default-username .mbdelete' ).hide(); // PB specific line
405 jQuery( container_name + ' ' + '.element_type_default-e-mail #field' + ', ' + container_name + ' ' + '.element_type_default-password #field' + ', ' + container_name + ' ' + '.element_type_default-username #field' + ', ' + container_name + ' ' + '.element_type_default-e-mail #required' + ', ' + container_name + ' ' + '.element_type_default-password #required,' + container_name + ' ' + '.element_type_default-username #required,' + container_name + ' ' + '.element_type_checkbox-terms-and-conditions #required,' + container_name + ' ' + '.element_type_recaptcha #required' ).attr( 'disabled', true ); // PB specific line
406 }
407
408
409 function wppb_disable_add_entry_button( container_name ){
410 jQuery( container_name + ' ' + '.mb-list-entry-fields .button-primary' ).each( function(){
411
412 jQuery(this).data('myclick', this.onclick );
413 this.onclick = function(event) {
414 if ( jQuery(this).attr( 'disabled' ) ) {
415 return false;
416 }
417
418 jQuery(this).data('myclick').call(this, event || window.event);
419 };
420 });
421
422 }
423
424
425 function wppb_edit_form_properties( container_name, element_id ){
426 wppb_hide_all ( container_name );
427 wppb_disable_add_entry_button ( container_name );
428
429 field = jQuery( container_name + ' #' + element_id + ' ' + '#field' ).val();
430
431 if ( ( field in fields ) ){
432 var to_show = fields[jQuery.trim(field)]['show_rows'];
433 for (var key in to_show)
434 jQuery( container_name + ' #' + element_id + ' ' + to_show[key] ).show();
435
436 jQuery( container_name + ' ' + '.mb-list-entry-fields .button-primary' ).removeAttr( 'disabled' );
437 }
438 }
439
440
441 function wppb_display_needed_fields( index, container_name, current_field_select ){
442 var show_rows = fields[jQuery.trim(index)]['show_rows'];
443 for (var key in show_rows) {
444 jQuery( show_rows[key], jQuery( current_field_select ).parents( '.mb-list-entry-fields' ) ).show();
445 }
446
447 var properties = fields[jQuery.trim(index)]['properties'];
448 if ( ( ( typeof properties !== 'undefined' ) && ( properties ) ) ) { //the extra (second) condition is a particular case since only the username is defined in our global array that has no meta-name
449 for (var key in properties) {
450 if ( ( typeof properties['meta_name_value'] !== 'undefined' ) ){
451 jQuery( container_name + ' ' + '#meta-name' ).val( properties['meta_name_value'] );
452 jQuery( container_name + ' ' + '#meta-name' ).attr( 'readonly', true );
453 }
454 }
455
456 }else{
457 /* meta value when editing a field shouldn't change so we take it from the current entered value which is displayed above the edit form */
458 if( jQuery( current_field_select).parents('.update_container_wppb_manage_fields').length != 0 ){
459 meta_value = jQuery( '.row-meta-name pre', jQuery( current_field_select).parents( '.update_container_wppb_manage_fields' ).prev() ).text();
460 }
461 /* for the add form it should change */
462 else{
463 numbers = new Array();
464 jQuery( '#container_wppb_manage_fields .row-meta-name pre').each(function(){
465 meta_name = jQuery(this).text();
466 if( meta_name.indexOf( 'custom_field' ) !== -1 ){
467 var meta_name = meta_name.replace('custom_field', '' );
468 /* backwards compatibility check in PB 1.3 meta_name was custom_field_# */
469 meta_name = meta_name.replace('_', '' );
470 if( isNaN( meta_name ) ){
471 meta_name = Math.floor((Math.random() * 200) + 100);
472 }
473 numbers.push( meta_name );
474 }
475 });
476 if( numbers.length > 0 ){
477 numbers.sort();
478 numbers.reverse();
479 meta_number = parseInt(numbers[0])+1;
480 }
481 else
482 meta_number = 1;
483
484 meta_value = 'custom_field'+meta_number;
485 }
486 jQuery( container_name + ' ' + '#meta-name' ).val( meta_value );
487 jQuery( container_name + ' ' + '#meta-name' ).attr( 'readonly', false );
488 }
489
490
491 var set_required = fields[jQuery.trim(index)]['required'];
492 if ( ( typeof set_required !== 'undefined' ) && ( set_required ) ){
493 jQuery( container_name + ' ' + '#required' ).val( 'Yes' );
494 jQuery( container_name + ' ' + '#required' ).attr( 'disabled', true );
495
496 }else{
497 jQuery( container_name + ' ' + '#required' ).val( 'No' );
498 jQuery( container_name + ' ' + '#required' ).attr( 'disabled', false );
499 }
500
501 jQuery( container_name + ' ' + '.mb-list-entry-fields .button-primary' ).removeAttr( 'disabled' );
502 }
503
504
505 function wppb_initialize_live_select( container_name ){
506 wppb_hide_all( container_name );
507 jQuery(document).on( 'change', container_name + ' ' + '.mb-list-entry-fields #field', function () {
508 field = jQuery(this).val();
509
510 if ( field != ''){
511 wppb_hide_all( container_name );
512 wppb_display_needed_fields( field, container_name, this );
513 }else{
514 wppb_hide_all( container_name );
515 }
516 });
517 }
518
519 jQuery(function(){
520 wppb_initialize_live_select ( '#wppb_manage_fields' );
521 wppb_initialize_live_select ( '#container_wppb_manage_fields' );
522
523 wppb_hide_properties_for_already_added_fields( '#container_wppb_manage_fields' );
524 wppb_disable_add_entry_button ( '#wppb_manage_fields' );
525 });