Page 1 of 1

How to Include "Select / Upload Image" Button?

Posted: Sat Mar 15, 2014 2:05 am
by pokemon007
I have a new Entity that has an image property. The property is defined as

Code: Select all

   @ManyToOne(targetEntity = Media.class)
    @JoinColumn(name = "MEDIA_ID")
    @AdminPresentation(friendlyName = "Image", order = Presentation.FieldOrder.Image, fieldType = SupportedFieldType.MEDIA,
          group = Presentation.Group.Name.General, groupOrder = Presentation.Group.Order.General)
    @AdminPresentationToOneLookup()
    private Media image;


It does have a lookup button shown on the UI and the image list comes up when click on this button, but it doesn't show the thumnail image, and the popup image selection dialog doesn't show the thumnail images either. It looks very different than that primary image on product entity page. I compare SkuImpl and my entity and AdminProductController and MyEntityController, I couldn't figure out what goes wrong or what I missed.

Can anyone point me to the direction where it went wrong?

Thanks.

-Charlie

Re: How to Include "Select / Upload Image" Button?

Posted: Fri Mar 21, 2014 5:55 am
by phillipuniverse
What drives the image fields on something like Sku is really an asset lookup, not a Media relationship. If you wanted the equivalent functionality of the other image lookups your property would just be this:

Code: Select all

@Column("IMAGE")
@
AdminPresentation(friendlyName "Image"fieldType SupportedFieldType.ASSET_LOOKUP)
private 
String image;
 

Re: How to Include "Select / Upload Image" Button?

Posted: Sat Mar 22, 2014 2:14 am
by pokemon007
Wow! This does work if Its type changed from Media type to String type and the property is the media's url. However, I can't get it to work if the property type is Media, that is, if an object has a single Media property, not like a list of Media items stored in a map like skuMedia.

A slightly separate question,
1) How can I control where the uploaded image to save. I saw the files are saved to generated temp folder. I'm building a B2B commerce. Each merchant has their own root folder, and their assets will be stored under their root folder. Should I extends AdminAssetUploadController?
2) I have a class MerchantMedia extended from Media that has an merchant property. How to return media item list of only a specific merchant instead of all media items? Where to set the criteria and what's the syntax.
Thank you very much!

-Charlie

Re: How to Include "Select / Upload Image" Button?

Posted: Sun Mar 23, 2014 8:06 pm
by phillipuniverse
1) How can I control where the uploaded image to save. I saw the files are saved to generated temp folder. I'm building a B2B commerce. Each merchant has their own root folder, and their assets will be stored under their root folder. Should I extends AdminAssetUploadController?


In 3.1 the component that actually writes those files to disk is the BroadleafFileService. There is an interface that this uses called a FileServiceProvider which is a nice abstraction to figure out where/how it should save those files. If you interact with something like S3 or Rackspace Cloud Files they use a class that corresponds to that interface (see https://github.com/BroadleafCommerce/blc-amazon and https://github.com/BroadleafCommerce/blc-rackspace for the implementations). This would be the appropriate extension point to deal with all file operations which is probably what you really want.

2) I have a class MerchantMedia extended from Media that has an merchant property. How to return media item list of only a specific merchant instead of all media items? Where to set the criteria and what's the syntax.


I think that has been answered in some of your other posts; let me know if it's still unclear.