Skip to:
Content

BuddyPress.org

Changeset 8494


Ignore:
Timestamp:
06/10/2014 12:51:44 PM (11 years ago)
Author:
boonebgorges
Message:

Generate list of xprofile field types that support options for Field Admin, rather than hardcoding

This change allows custom field types to support options, while using the core
admin panel UI.

Fixes #5691

Location:
trunk/src/bp-xprofile
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/admin/js/admin.js

    r8378 r8494  
    6262}
    6363
    64 function show_options(forWhat) {
    65     document.getElementById( 'radio'          ).style.display = 'none';
    66     document.getElementById( 'selectbox'      ).style.display = 'none';
    67     document.getElementById( 'multiselectbox' ).style.display = 'none';
    68     document.getElementById( 'checkbox'       ).style.display = 'none';
    69 
    70     if ( forWhat === 'radio' ) {
    71         document.getElementById( 'radio' ).style.display = '';
    72     }
    73 
    74     if ( forWhat === 'selectbox' ) {
    75         document.getElementById( 'selectbox' ).style.display = '';
    76     }
    77 
    78     if ( forWhat === 'multiselectbox' ) {
    79         document.getElementById( 'multiselectbox' ).style.display = '';
    80     }
    81 
    82     if ( forWhat === 'checkbox' ) {
    83         document.getElementById( 'checkbox' ).style.display = '';
     64/**
     65 * Hide all "options" sections, and show the options section for the forWhat type.
     66 */
     67function show_options( forWhat ) {
     68    for ( var i = 0; i < XProfileAdmin.supports_options_field_types.length; i++ ) {
     69        document.getElementById( XProfileAdmin.supports_options_field_types[i] ).style.display = 'none';
     70    }
     71
     72    if ( XProfileAdmin.supports_options_field_types.indexOf( forWhat ) >= 0 ) {
     73        document.getElementById( forWhat ).style.display = '';
    8474    }
    8575}
  • trunk/src/bp-xprofile/bp-xprofile-cssjs.php

    r7756 r8494  
    4040        $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
    4141        wp_enqueue_script( 'xprofile-admin-js', buddypress()->plugin_url . "bp-xprofile/admin/js/admin{$min}.js", array( 'jquery', 'jquery-ui-sortable' ), bp_get_version() );
     42
     43        // Localize strings.
     44        // supports_options_field_types is a dynamic list of field
     45        // types that support options, for use in showing/hiding the
     46        // "please enter options for this field" section
     47        $strings = array(
     48            'supports_options_field_types' => array(),
     49        );
     50
     51        foreach ( bp_xprofile_get_field_types() as $field_type => $field_type_class ) {
     52            $field = new $field_type_class();
     53            if ( $field->supports_options ) {
     54                $strings['supports_options_field_types'][] = $field_type;
     55            }
     56        }
     57
     58        wp_localize_script( 'xprofile-admin-js', 'XProfileAdmin', $strings );
    4259    }
    4360}
Note: See TracChangeset for help on using the changeset viewer.