From 9d798d77bcd1c7a445dbf55b61e19d392e663fe6 Mon Sep 17 00:00:00 2001 From: Pippin Williamson Date: Sun, 22 Dec 2013 21:31:05 -0600 Subject: [PATCH] Add full support for Chosen to the Bundled Products UI. #965 --- assets/css/edd-admin.css | 4 +- includes/admin/discounts/add-discount.php | 15 ++++-- includes/admin/discounts/edit-discount.php | 14 ++++- includes/admin/downloads/metabox.php | 60 +++++----------------- includes/class-edd-html-elements.php | 39 +++++++++----- 5 files changed, 66 insertions(+), 66 deletions(-) diff --git a/assets/css/edd-admin.css b/assets/css/edd-admin.css index e1bfebf4273..dc8525e51d7 100755 --- a/assets/css/edd-admin.css +++ b/assets/css/edd-admin.css @@ -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; } diff --git a/includes/admin/discounts/add-discount.php b/includes/admin/discounts/add-discount.php index c9481d21cb0..2dfad9507f6 100755 --- a/includes/admin/discounts/add-discount.php +++ b/includes/admin/discounts/add-discount.php @@ -70,8 +70,12 @@

- html->product_dropdown( 'products[]', array(), true, true ); ?>
- + html->product_dropdown( array( + 'name' => 'products[]', + 'selected' => array(), + 'multiple' => true, + 'chosen' => true + ) ); ?>

@@ -87,7 +91,12 @@ - html->product_dropdown( 'excluded-products[]', array(), true, true ); ?>
+ html->product_dropdown( array( + 'name' => 'excluded-products[]', + 'selected' => array(), + 'multiple' => true, + 'chosen' => true + ) ); ?>

diff --git a/includes/admin/discounts/edit-discount.php b/includes/admin/discounts/edit-discount.php index b3e7dc27d9a..53adf237d8b 100755 --- a/includes/admin/discounts/edit-discount.php +++ b/includes/admin/discounts/edit-discount.php @@ -79,7 +79,12 @@

- html->product_dropdown( 'products[]', $product_reqs, true, true ); ?>
+ html->product_dropdown( array( + 'name' => 'products[]', + 'selected' => $excluded_products, + 'multiple' => true, + 'chosen' => true + ) ); ?>

diff --git a/includes/admin/downloads/metabox.php b/includes/admin/downloads/metabox.php index 0b5357889eb..93542b67056 100755 --- a/includes/admin/downloads/metabox.php +++ b/includes/admin/downloads/metabox.php @@ -468,6 +468,7 @@ function edd_render_product_type_field( $post_id = 0 ) { html->select( array( 'options' => $types, 'name' => '_edd_product_type', + 'id' => '_edd_product_type', 'selected' => $type, 'show_option_all' => false, 'show_option_none' => false @@ -490,39 +491,28 @@ function edd_render_products_field( $post_id ) { $products = edd_get_bundled_products( $post_id ); ?>
> -

- -

-
- + - - - - - - - - - - - +
- + + html->product_dropdown( array( + 'name' => '_edd_bundled_products[]', + 'id' => 'edd_bundled_products', + 'selected' => $products, + 'multiple' => true, + 'chosen' => true + ) ); + ?>
@@ -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 ) { - -?> - - html->product_dropdown( '_edd_bundled_products[]', $product_id, false, true ); ?> - - - - - - × - - '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', @@ -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' ) ) ); @@ -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 ); @@ -226,7 +239,7 @@ public function select( $args = array() ) { $multiple = ''; } - $output = ''; if ( ! empty( $args[ 'options' ] ) ) { if ( $args[ 'show_option_all' ] ) {