[2.3] Fixed product category media upload modal and some coding standards, closes #8227

This commit is contained in:
Claudio Sanches 2015-05-26 10:24:49 -03:00
parent 702163a782
commit d53d21781b
1 changed files with 39 additions and 34 deletions

View File

@ -2,11 +2,11 @@
/**
* Handles taxonomies in admin
*
* @class WC_Admin_Taxonomies
* @version 2.1.0
* @package WooCommerce/Admin
* @category Class
* @author WooThemes
* @class WC_Admin_Taxonomies
* @version 2.3.10
* @package WooCommerce/Admin
* @category Class
* @author WooThemes
*/
if ( ! defined( 'ABSPATH' ) ) {
@ -58,7 +58,7 @@ class WC_Admin_Taxonomies {
* @param mixed $taxonomy
*/
public function create_term( $term_id, $tt_id = '', $taxonomy = '' ) {
if ( $taxonomy != 'product_cat' && ! taxonomy_is_product_attribute( $taxonomy ) ) {
if ( 'product_cat' != $taxonomy && ! taxonomy_is_product_attribute( $taxonomy ) ) {
return;
}
@ -98,8 +98,8 @@ class WC_Admin_Taxonomies {
</div>
<div class="form-field">
<label><?php _e( 'Thumbnail', 'woocommerce' ); ?></label>
<div id="product_cat_thumbnail" style="float:left;margin-right:10px;"><img src="<?php echo wc_placeholder_img_src(); ?>" width="60px" height="60px" /></div>
<div style="line-height:60px;">
<div id="product_cat_thumbnail" style="float: left; margin-right: 10px;"><img src="<?php echo esc_url( wc_placeholder_img_src() ); ?>" width="60px" height="60px" /></div>
<div style="line-height: 60px;">
<input type="hidden" id="product_cat_thumbnail_id" name="product_cat_thumbnail_id" />
<button type="button" class="upload_image_button button"><?php _e( 'Upload/Add image', 'woocommerce' ); ?></button>
<button type="button" class="remove_image_button button"><?php _e( 'Remove image', 'woocommerce' ); ?></button>
@ -107,8 +107,8 @@ class WC_Admin_Taxonomies {
<script type="text/javascript">
// Only show the "remove image" button when needed
if ( ! jQuery('#product_cat_thumbnail_id').val() ) {
jQuery('.remove_image_button').hide();
if ( ! jQuery( '#product_cat_thumbnail_id' ).val() ) {
jQuery( '.remove_image_button' ).hide();
}
// Uploading files
@ -126,30 +126,30 @@ class WC_Admin_Taxonomies {
// Create the media frame.
file_frame = wp.media.frames.downloadable_file = wp.media({
title: '<?php _e( 'Choose an image', 'woocommerce' ); ?>',
title: '<?php _e( "Choose an image", "woocommerce" ); ?>',
button: {
text: '<?php _e( 'Use image', 'woocommerce' ); ?>',
text: '<?php _e( "Use image", "woocommerce" ); ?>'
},
multiple: false
});
// When an image is selected, run a callback.
file_frame.on( 'select', function() {
attachment = file_frame.state().get('selection').first().toJSON();
var attachment = file_frame.state().get( 'selection' ).first().toJSON();
jQuery('#product_cat_thumbnail_id').val( attachment.id );
jQuery('#product_cat_thumbnail img').attr('src', attachment.sizes.thumbnail.url );
jQuery('.remove_image_button').show();
jQuery( '#product_cat_thumbnail_id' ).val( attachment.id );
jQuery( '#product_cat_thumbnail img' ).attr( 'src', attachment.sizes.thumbnail.url );
jQuery( '.remove_image_button' ).show();
});
// Finally, open the modal.
file_frame.open();
});
jQuery( document ).on( 'click', '.remove_image_button', function( event ) {
jQuery('#product_cat_thumbnail img').attr('src', '<?php echo wc_placeholder_img_src(); ?>');
jQuery('#product_cat_thumbnail_id').val('');
jQuery('.remove_image_button').hide();
jQuery( document ).on( 'click', '.remove_image_button', function() {
jQuery( '#product_cat_thumbnail img' ).attr( 'src', '<?php echo esc_js( wc_placeholder_img_src() ); ?>' );
jQuery( '#product_cat_thumbnail_id' ).val( '' );
jQuery( '.remove_image_button' ).hide();
return false;
});
@ -189,14 +189,19 @@ class WC_Admin_Taxonomies {
<tr class="form-field">
<th scope="row" valign="top"><label><?php _e( 'Thumbnail', 'woocommerce' ); ?></label></th>
<td>
<div id="product_cat_thumbnail" style="float:left;margin-right:10px;"><img src="<?php echo $image; ?>" width="60px" height="60px" /></div>
<div style="line-height:60px;">
<div id="product_cat_thumbnail" style="float: left; margin-right: 10px;"><img src="<?php echo esc_url( $image ); ?>" width="60px" height="60px" /></div>
<div style="line-height: 60px;">
<input type="hidden" id="product_cat_thumbnail_id" name="product_cat_thumbnail_id" value="<?php echo $thumbnail_id; ?>" />
<button type="submit" class="upload_image_button button"><?php _e( 'Upload/Add image', 'woocommerce' ); ?></button>
<button type="submit" class="remove_image_button button"><?php _e( 'Remove image', 'woocommerce' ); ?></button>
<button type="button" class="upload_image_button button"><?php _e( 'Upload/Add image', 'woocommerce' ); ?></button>
<button type="button" class="remove_image_button button"><?php _e( 'Remove image', 'woocommerce' ); ?></button>
</div>
<script type="text/javascript">
// Only show the "remove image" button when needed
if ( '0' === jQuery( '#product_cat_thumbnail_id' ).val() ) {
jQuery( '.remove_image_button' ).hide();
}
// Uploading files
var file_frame;
@ -212,30 +217,30 @@ class WC_Admin_Taxonomies {
// Create the media frame.
file_frame = wp.media.frames.downloadable_file = wp.media({
title: '<?php _e( 'Choose an image', 'woocommerce' ); ?>',
title: '<?php _e( "Choose an image", "woocommerce" ); ?>',
button: {
text: '<?php _e( 'Use image', 'woocommerce' ); ?>',
text: '<?php _e( "Use image", "woocommerce" ); ?>'
},
multiple: false
});
// When an image is selected, run a callback.
file_frame.on( 'select', function() {
attachment = file_frame.state().get('selection').first().toJSON();
var attachment = file_frame.state().get( 'selection' ).first().toJSON();
jQuery('#product_cat_thumbnail_id').val( attachment.id );
jQuery('#product_cat_thumbnail img').attr('src', attachment.sizes.thumbnail.url );
jQuery('.remove_image_button').show();
jQuery( '#product_cat_thumbnail_id' ).val( attachment.id );
jQuery( '#product_cat_thumbnail img' ).attr( 'src', attachment.sizes.thumbnail.url );
jQuery( '.remove_image_button' ).show();
});
// Finally, open the modal.
file_frame.open();
});
jQuery( document ).on( 'click', '.remove_image_button', function( event ) {
jQuery('#product_cat_thumbnail img').attr('src', '<?php echo wc_placeholder_img_src(); ?>');
jQuery('#product_cat_thumbnail_id').val('');
jQuery('.remove_image_button').hide();
jQuery( document ).on( 'click', '.remove_image_button', function() {
jQuery( '#product_cat_thumbnail img' ).attr( 'src', '<?php echo esc_js( wc_placeholder_img_src() ); ?>' );
jQuery( '#product_cat_thumbnail_id' ).val( '' );
jQuery( '.remove_image_button' ).hide();
return false;
});