Search in sources :

Example 1 with BroadleafAttributeModifier

use of org.broadleafcommerce.presentation.model.BroadleafAttributeModifier in project BroadleafCommerce by BroadleafCommerce.

the class PaginationPageLinkProcessor method getModifiedAttributes.

@Override
public BroadleafAttributeModifier getModifiedAttributes(String tagName, Map<String, String> tagAttributes, String attributeName, String attributeValue, BroadleafTemplateContext context) {
    BroadleafRequestContext blcContext = BroadleafRequestContext.getBroadleafRequestContext();
    HttpServletRequest request = blcContext.getRequest();
    String baseUrl = request.getRequestURL().toString();
    Map<String, String[]> params = new HashMap<>(request.getParameterMap());
    Integer page = (Integer) context.parseExpression(attributeValue);
    if (page != null && page > 1) {
        params.put(SearchCriteria.PAGE_NUMBER, new String[] { page.toString() });
    } else {
        params.remove(SearchCriteria.PAGE_NUMBER);
    }
    String url = ProcessorUtils.getUrl(baseUrl, params);
    Map<String, String> newAttributes = new HashMap<>();
    newAttributes.put("href", url);
    return new BroadleafAttributeModifier(newAttributes);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HashMap(java.util.HashMap) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) BroadleafAttributeModifier(org.broadleafcommerce.presentation.model.BroadleafAttributeModifier)

Example 2 with BroadleafAttributeModifier

use of org.broadleafcommerce.presentation.model.BroadleafAttributeModifier in project BroadleafCommerce by BroadleafCommerce.

the class ProductOptionValueProcessor method getModifiedAttributes.

@Override
public BroadleafAttributeModifier getModifiedAttributes(String tagName, Map<String, String> tagAttributes, String attributeName, String attributeValue, BroadleafTemplateContext context) {
    Map<String, String> newAttributes = new HashMap<>();
    ProductOptionValue productOptionValue = (ProductOptionValue) context.parseExpression(attributeValue);
    ProductOptionValueDTO dto = new ProductOptionValueDTO();
    dto.setOptionId(productOptionValue.getProductOption().getId());
    dto.setValueId(productOptionValue.getId());
    dto.setValueName(productOptionValue.getAttributeValue());
    dto.setRawValue(productOptionValue.getRawAttributeValue());
    if (productOptionValue.getPriceAdjustment() != null) {
        dto.setPriceAdjustment(productOptionValue.getPriceAdjustment().getAmount());
    }
    try {
        ObjectMapper mapper = new ObjectMapper();
        Writer strWriter = new StringWriter();
        mapper.writeValue(strWriter, dto);
        newAttributes.put("data-product-option-value", strWriter.toString());
    } catch (Exception ex) {
        LOG.error("There was a problem writing the product option value to JSON", ex);
    }
    return new BroadleafAttributeModifier(newAttributes);
}
Also used : ProductOptionValue(org.broadleafcommerce.core.catalog.domain.ProductOptionValue) StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) BroadleafAttributeModifier(org.broadleafcommerce.presentation.model.BroadleafAttributeModifier) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 3 with BroadleafAttributeModifier

use of org.broadleafcommerce.presentation.model.BroadleafAttributeModifier in project BroadleafCommerce by BroadleafCommerce.

the class RemoveFacetValuesLinkProcessor method getModifiedAttributes.

@Override
public BroadleafAttributeModifier getModifiedAttributes(String tagName, Map<String, String> tagAttributes, String attributeName, String attributeValue, BroadleafTemplateContext context) {
    BroadleafRequestContext blcContext = BroadleafRequestContext.getBroadleafRequestContext();
    HttpServletRequest request = blcContext.getRequest();
    String baseUrl = request.getRequestURL().toString();
    Map<String, String[]> params = new HashMap<>(request.getParameterMap());
    SearchFacetDTO facet = (SearchFacetDTO) context.parseExpression(attributeValue);
    String key = searchFacetDTOService.getUrlKey(facet);
    params.remove(key);
    params.remove(SearchCriteria.PAGE_NUMBER);
    String url = ProcessorUtils.getUrl(baseUrl, params);
    Map<String, String> newAttributes = new HashMap<>();
    newAttributes.put("href", url);
    return new BroadleafAttributeModifier(newAttributes);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HashMap(java.util.HashMap) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) SearchFacetDTO(org.broadleafcommerce.core.search.domain.SearchFacetDTO) BroadleafAttributeModifier(org.broadleafcommerce.presentation.model.BroadleafAttributeModifier)

Example 4 with BroadleafAttributeModifier

use of org.broadleafcommerce.presentation.model.BroadleafAttributeModifier in project BroadleafCommerce by BroadleafCommerce.

the class ToggleFacetLinkProcessor method getModifiedAttributes.

@Override
public BroadleafAttributeModifier getModifiedAttributes(String tagName, Map<String, String> tagAttributes, String attributeName, String attributeValue, BroadleafTemplateContext context) {
    BroadleafRequestContext blcContext = BroadleafRequestContext.getBroadleafRequestContext();
    HttpServletRequest request = blcContext.getRequest();
    String baseUrl = request.getRequestURL().toString();
    Map<String, String[]> params = new HashMap<>(request.getParameterMap());
    SearchFacetResultDTO result = (SearchFacetResultDTO) context.parseExpression(attributeValue);
    String key = facetService.getUrlKey(result);
    String value = facetService.getValue(result);
    String[] paramValues = params.get(key);
    if (ArrayUtils.contains(paramValues, facetService.getValue(result))) {
        paramValues = (String[]) ArrayUtils.removeElement(paramValues, facetService.getValue(result));
    } else {
        paramValues = (String[]) ArrayUtils.add(paramValues, value);
    }
    params.remove(SearchCriteria.PAGE_NUMBER);
    params.put(key, paramValues);
    String url = ProcessorUtils.getUrl(baseUrl, params);
    Map<String, String> newAttributes = new HashMap<>();
    newAttributes.put("href", url);
    return new BroadleafAttributeModifier(newAttributes);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HashMap(java.util.HashMap) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) SearchFacetResultDTO(org.broadleafcommerce.core.search.domain.SearchFacetResultDTO) BroadleafAttributeModifier(org.broadleafcommerce.presentation.model.BroadleafAttributeModifier)

Example 5 with BroadleafAttributeModifier

use of org.broadleafcommerce.presentation.model.BroadleafAttributeModifier in project BroadleafCommerce by BroadleafCommerce.

the class AdminComponentIdProcessor method getModifiedAttributes.

@Override
public BroadleafAttributeModifier getModifiedAttributes(String tagName, Map<String, String> tagAttributes, String attributeName, String attributeValue, BroadleafTemplateContext context) {
    Object component = context.parseExpression(attributeValue);
    String fieldName = "";
    String id = "";
    if (component instanceof ListGrid) {
        ListGrid lg = (ListGrid) component;
        fieldName = "listGrid-" + lg.getListGridType();
        if (StringUtils.isNotBlank(lg.getSubCollectionFieldName())) {
            fieldName += "-" + lg.getSubCollectionFieldName();
        }
    } else if (component instanceof Field) {
        Field field = (Field) component;
        fieldName = "field-" + field.getName();
    }
    if (StringUtils.isNotBlank(fieldName)) {
        id = cleanCssIdString(fieldName);
    }
    Map<String, String> attrs = new HashMap<>();
    attrs.put("id", id);
    return new BroadleafAttributeModifier(attrs);
}
Also used : Field(org.broadleafcommerce.openadmin.web.form.entity.Field) HashMap(java.util.HashMap) ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid) BroadleafAttributeModifier(org.broadleafcommerce.presentation.model.BroadleafAttributeModifier)

Aggregations

HashMap (java.util.HashMap)9 BroadleafAttributeModifier (org.broadleafcommerce.presentation.model.BroadleafAttributeModifier)9 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 BroadleafRequestContext (org.broadleafcommerce.common.web.BroadleafRequestContext)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 ArrayList (java.util.ArrayList)1 ProductOptionValue (org.broadleafcommerce.core.catalog.domain.ProductOptionValue)1 SearchFacetDTO (org.broadleafcommerce.core.search.domain.SearchFacetDTO)1 SearchFacetResultDTO (org.broadleafcommerce.core.search.domain.SearchFacetResultDTO)1 AdminSection (org.broadleafcommerce.openadmin.server.security.domain.AdminSection)1 ListGrid (org.broadleafcommerce.openadmin.web.form.component.ListGrid)1 Field (org.broadleafcommerce.openadmin.web.form.entity.Field)1