Skip to content

Commit

Permalink
Add full support for Chosen to the Bundled Products UI. #965
Browse files Browse the repository at this point in the history
  • Loading branch information
pippinsplugins committed Dec 23, 2013
1 parent a4878de commit 9d798d7
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 66 deletions.
4 changes: 3 additions & 1 deletion assets/css/edd-admin.css
Expand Up @@ -92,7 +92,9 @@ textarea#edd_product_notes { width: 100%; height: 4em; margin: 0; }
#edd-purchased-files .inside { margin: 0; padding: 0; }

.edd-price-field { width: 80px; }
.edd_repeatable_upload_wrapper .pricing select, .edd_repeatable_product_wrapper .edd-select { min-width: 100%; }
.edd_repeatable_upload_wrapper .pricing select, .edd_repeatable_product_wrapper .edd-select,
#edd_products .edd-select { min-width: 100%; }
.edd_repeatable_product_wrapper td { overflow: visible; }

/** Stats */
#edd_product_stats .label { width: 70px; display: inline-block; }
Expand Down
15 changes: 12 additions & 3 deletions includes/admin/discounts/add-discount.php
Expand Up @@ -70,8 +70,12 @@
<label for="edd-product-condition"><?php _e( 'Condition', 'edd' ); ?></label>
</p>

<?php echo EDD()->html->product_dropdown( 'products[]', array(), true, true ); ?><br/>

<?php echo EDD()->html->product_dropdown( array(
'name' => 'products[]',
'selected' => array(),
'multiple' => true,
'chosen' => true
) ); ?><br/>
<p class="description"><?php printf( __( '%s required to be purchased for this discount.', 'edd' ), edd_get_label_plural() ); ?></p>

<p>
Expand All @@ -87,7 +91,12 @@
<label for="edd-excluded-products"><?php printf( __( 'Excluded %s', 'edd' ), edd_get_label_plural() ); ?></label>
</th>
<td>
<?php echo EDD()->html->product_dropdown( 'excluded-products[]', array(), true, true ); ?><br/>
<?php echo EDD()->html->product_dropdown( array(
'name' => 'excluded-products[]',
'selected' => array(),
'multiple' => true,
'chosen' => true
) ); ?><br/>
<p class="description"><?php printf( __( '%s that this discount code cannot be applied to.', 'edd' ), edd_get_label_plural() ); ?></p>
</td>
</tr>
Expand Down
14 changes: 12 additions & 2 deletions includes/admin/discounts/edit-discount.php
Expand Up @@ -79,7 +79,12 @@
</select>
<label for="edd-product-condition"><?php _e( 'Condition', 'edd' ); ?></label>
</p>
<?php echo EDD()->html->product_dropdown( 'products[]', $product_reqs, true, true ); ?><br/>
<?php echo EDD()->html->product_dropdown( array(
'name' => 'products[]',
'selected' => $excluded_products,
'multiple' => true,
'chosen' => true
) ); ?><br/>
<p class="description"><?php printf( __( '%s required to be purchased for this discount.', 'edd' ), edd_get_label_plural() ); ?></p>
<p>
<label for="edd-non-global-discount">
Expand All @@ -94,7 +99,12 @@
<label for="edd-excluded-products"><?php printf( __( 'Excluded %s', 'edd' ), edd_get_label_plural() ); ?></label>
</th>
<td>
<?php echo EDD()->html->product_dropdown( 'excluded-products[]', $excluded_products, true, true ); ?><br/>
<?php echo EDD()->html->product_dropdown( array(
'name' => 'excluded-products[]',
'selected' => $excluded_products,
'multiple' => true,
'chosen' => true
) ); ?><br/>
<p class="description"><?php printf( __( '%s that this discount code cannot be applied to.', 'edd' ), edd_get_label_plural() ); ?></p>
</td>
</tr>
Expand Down
60 changes: 13 additions & 47 deletions includes/admin/downloads/metabox.php
Expand Up @@ -468,6 +468,7 @@ function edd_render_product_type_field( $post_id = 0 ) {
<?php echo EDD()->html->select( array(
'options' => $types,
'name' => '_edd_product_type',
'id' => '_edd_product_type',
'selected' => $type,
'show_option_all' => false,
'show_option_none' => false
Expand All @@ -490,39 +491,28 @@ function edd_render_products_field( $post_id ) {
$products = edd_get_bundled_products( $post_id );
?>
<div id="edd_products"<?php echo $display; ?>>
<p>
<strong><?php printf( __( 'Bundled %s:', 'edd' ), edd_get_label_plural() ); ?></strong>
</p>

<div id="edd_file_fields" class="edd_meta_table_wrap">
<table class="widefat" width="100%" cellpadding="0" cellspacing="0">
<thead>
<tr>
<th style="width: 97%"><?php printf( __( '%s Name', 'edd' ), edd_get_label_singular() ); ?></th>
<th><?php printf( __( 'Bundled %s:', 'edd' ), edd_get_label_plural() ); ?></th>
<?php do_action( 'edd_download_products_table_head', $post_id ); ?>
<th style="width: 2%"></th>
</tr>
</thead>
<tbody>
<?php
if ( ! empty( $products ) ) :
foreach ( $products as $product ) :
?>
<tr class="edd_repeatable_product_wrapper">
<?php do_action( 'edd_render_product_row', $product, $post_id ); ?>
</tr>
<?php
endforeach;
else :
?>
<tr class="edd_repeatable_product_wrapper">
<?php do_action( 'edd_render_product_row', 0, $post_id ); ?>
</tr>
<?php endif; ?>
<tr>
<td class="submit" colspan="4" style="float: none; clear:both; background: #fff;">
<a class="button-secondary edd_add_repeatable" style="margin: 6px 0 10px;"><?php printf( __( 'Add %s', 'edd' ), edd_get_label_singular() ); ?></a>
<td>
<?php
echo EDD()->html->product_dropdown( array(
'name' => '_edd_bundled_products[]',
'id' => 'edd_bundled_products',
'selected' => $products,
'multiple' => true,
'chosen' => true
) );
?>
</td>
<?php do_action( 'edd_download_products_table_row', $post_id ); ?>
</tr>
</tbody>
</table>
Expand All @@ -532,30 +522,6 @@ function edd_render_products_field( $post_id ) {
}
add_action( 'edd_meta_box_files_fields', 'edd_render_products_field', 10 );

/**
* TODO Update doc
*
* @since 1.6
* @param int $product_id
* @param $post_id
*/
function edd_render_product_row( $product_id = 0, $post_id ) {

?>
<td>
<?php echo EDD()->html->product_dropdown( '_edd_bundled_products[]', $product_id, false, true ); ?>
</td>

<?php do_action( 'edd_product_table_row', $product_id, $post_id ); ?>

<td>
<a href="#" class="edd_remove_repeatable" data-type="file" style="background: url(<?php echo admin_url('/images/xit.gif'); ?>) no-repeat;">&times;</a>
</td>
<?php
}
add_action( 'edd_render_product_row', 'edd_render_product_row', 10, 2 );


/**
* File Downloads section.
*
Expand Down
39 changes: 26 additions & 13 deletions includes/class-edd-html-elements.php
Expand Up @@ -30,7 +30,19 @@ class EDD_HTML_Elements {
* @param int $selected Download to select automatically
* @return string $output Product dropdown
*/
public function product_dropdown( $name = 'edd_products', $selected = 0, $multiple = false, $chosen = false ) {
public function product_dropdown( $args = array() ) {

$defaults = array(
'name' => 'products',
'id' => 'products',
'class' => '',
'multiple' => false,
'selected' => 0,
'chosen' => false
);

$args = wp_parse_args( $args, $defaults );

$products = get_posts( array(
'post_type' => 'download',
'orderby' => 'title',
Expand All @@ -47,24 +59,25 @@ public function product_dropdown( $name = 'edd_products', $selected = 0, $multip
}

// This ensures that any selected products are included in the drop down
if( is_array( $selected ) ) {
foreach( $selected as $item ) {
if( is_array( $args['selected'] ) ) {
foreach( $args['selected'] as $item ) {
if( ! in_array( $item, $options ) ) {
$options[$item] = get_the_title( $item );
}
}
} else {
if( ! in_array( $selected, $options ) ) {
$options[$selected] = get_the_title( $selected );
if( ! in_array( $args['selected'], $options ) ) {
$options[$args['selected']] = get_the_title( $args['selected'] );
}
}

$output = $this->select( array(
'name' => $name,
'selected' => $selected,
'class' => $chosen ? 'edd-select-chosen' : '',
'name' => $args['name'],
'selected' => $args['selected'],
'id' => $args['id'],
'class' => $args['chosen'] ? 'edd-select-chosen' : '',
'options' => $options,
'multiple' => $multiple,
'multiple' => $args['multiple'],
'show_option_all' => false,
'show_option_none' => __( 'None', 'edd' )
) );
Expand Down Expand Up @@ -210,12 +223,12 @@ public function select( $args = array() ) {
$defaults = array(
'options' => array(),
'name' => null,
'class' => null,
'class' => '',
'id' => '',
'selected' => 0,
'multiple' => false,
'show_option_all' => _x( 'All', 'all dropdown items', 'edd' ),
'show_option_none' => _x( 'None', 'no dropdown items', 'edd' ),
'class' => ''
'show_option_none' => _x( 'None', 'no dropdown items', 'edd' )
);

$args = wp_parse_args( $args, $defaults );
Expand All @@ -226,7 +239,7 @@ public function select( $args = array() ) {
$multiple = '';
}

$output = '<select name="' . esc_attr( $args[ 'name' ] ) . '" id="' . esc_attr( sanitize_key( str_replace( '-', '_', $args[ 'name' ] ) ) ) . '" class="edd-select ' . esc_attr( $args[ 'class'] ) . '"' . $multiple . '>';
$output = '<select name="' . esc_attr( $args[ 'name' ] ) . '" id="' . esc_attr( sanitize_key( str_replace( '-', '_', $args[ 'id' ] ) ) ) . '" class="edd-select ' . esc_attr( $args[ 'class'] ) . '"' . $multiple . '>';

if ( ! empty( $args[ 'options' ] ) ) {
if ( $args[ 'show_option_all' ] ) {
Expand Down

0 comments on commit 9d798d7

Please sign in to comment.