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);
}
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);
}
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);
}
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);
}
Aggregations