Search in sources :

Example 6 with BroadleafAttributeModifier

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

the class AdminSectionHrefProcessor method getModifiedAttributes.

@Override
public BroadleafAttributeModifier getModifiedAttributes(String tagName, Map<String, String> tagAttributes, String attributeName, String attributeValue, BroadleafTemplateContext context) {
    String href = "#";
    AdminSection section = (AdminSection) context.parseExpression(attributeValue);
    if (section != null) {
        HttpServletRequest request = BroadleafRequestContext.getBroadleafRequestContext().getRequest();
        href = request.getContextPath() + section.getUrl();
    }
    Map<String, String> attrs = new HashMap<>();
    attrs.put("href", href);
    return new BroadleafAttributeModifier(attrs);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HashMap(java.util.HashMap) AdminSection(org.broadleafcommerce.openadmin.server.security.domain.AdminSection) BroadleafAttributeModifier(org.broadleafcommerce.presentation.model.BroadleafAttributeModifier)

Example 7 with BroadleafAttributeModifier

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

the class AddSortLinkProcessor 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());
    String key = SearchCriteria.SORT_STRING;
    List<String[]> sortedFields = new ArrayList<>();
    String[] paramValues = params.get(key);
    if (ArrayUtils.isNotEmpty(paramValues)) {
        String sortQueries = paramValues[0];
        for (String sortQuery : sortQueries.split(",")) {
            String[] sort = sortQuery.split(" ");
            if (sort.length == 2) {
                sortedFields.add(new String[] { sort[0], sort[1] });
            }
        }
    }
    boolean currentlySortingOnThisField = false;
    boolean currentlyAscendingOnThisField = false;
    for (String[] sortedField : sortedFields) {
        if (attributeValue.equals(sortedField[0])) {
            currentlySortingOnThisField = true;
            currentlyAscendingOnThisField = sortedField[1].equals("asc");
            sortedField[1] = currentlyAscendingOnThisField ? "desc" : "asc";
        }
    }
    String sortString = attributeValue;
    String classString = "";
    if (currentlySortingOnThisField) {
        classString += "active ";
        if (currentlyAscendingOnThisField) {
            sortString += " desc";
            classString += "asc ";
        } else {
            sortString += " asc";
            classString += "desc ";
        }
    } else {
        sortString += " asc";
        classString += "asc ";
        params.remove(SearchCriteria.PAGE_NUMBER);
    }
    if (allowMultipleSorts) {
        StringBuilder sortSb = new StringBuilder();
        for (String[] sortedField : sortedFields) {
            sortSb.append(sortedField[0]).append(" ").append(sortedField[1]).append(",");
        }
        sortString = sortSb.toString();
        if (sortString.charAt(sortString.length() - 1) == ',') {
            sortString = sortString.substring(0, sortString.length() - 1);
        }
    }
    params.put(key, new String[] { sortString });
    String url = ProcessorUtils.getUrl(baseUrl, params);
    Map<String, String> newAttributes = new HashMap<>();
    newAttributes.put("class", classString);
    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) ArrayList(java.util.ArrayList) BroadleafAttributeModifier(org.broadleafcommerce.presentation.model.BroadleafAttributeModifier)

Example 8 with BroadleafAttributeModifier

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

the class PaginationSizeLinkProcessor method getModifiedAttributes.

@Override
public BroadleafAttributeModifier getModifiedAttributes(String tagName, Map<String, String> tagAttributes, String attributeName, String attributeValue, BroadleafTemplateContext context) {
    HttpServletRequest request = BroadleafRequestContext.getBroadleafRequestContext().getRequest();
    String baseUrl = request.getRequestURL().toString();
    Map<String, String[]> params = new HashMap<>(request.getParameterMap());
    Integer pageSize = Integer.parseInt(attributeValue);
    if (pageSize != null && pageSize > 1) {
        params.put(SearchCriteria.PAGE_SIZE_STRING, new String[] { pageSize.toString() });
    } else {
        params.remove(SearchCriteria.PAGE_SIZE_STRING);
    }
    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) BroadleafAttributeModifier(org.broadleafcommerce.presentation.model.BroadleafAttributeModifier)

Example 9 with BroadleafAttributeModifier

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

the class PaginationSortLinkProcessor method getModifiedAttributes.

@Override
public BroadleafAttributeModifier getModifiedAttributes(String tagName, Map<String, String> tagAttributes, String attributeName, String attributeValue, BroadleafTemplateContext context) {
    HttpServletRequest request = BroadleafRequestContext.getBroadleafRequestContext().getRequest();
    String baseUrl = request.getRequestURL().toString();
    Map<String, String[]> params = new HashMap<>(request.getParameterMap());
    String sort = attributeValue;
    if (StringUtils.isNotBlank(sort)) {
        params.put(SearchCriteria.SORT_STRING, new String[] { sort });
    } else {
        params.remove(SearchCriteria.SORT_STRING);
    }
    // If there is a page number parameter, remove it. This ensures that when the search results refresh the
    // first page of results will be displayed.
    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) 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