- Some more enhancments for the CategoryFilter
- Added jQuery UI to the assets included, can be used to enhance the user interface, used by the CategoryFilter git-svn-id: https://svn.libreccm.org/ccm/trunk@2327 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
23f468b359
commit
ff5dbab75c
File diff suppressed because one or more lines are too long
|
|
@ -34,6 +34,7 @@ public class CategoryFilter {
|
||||||
if (collection.next()) {
|
if (collection.next()) {
|
||||||
final Category category = (Category) DomainObjectFactory.newInstance(
|
final Category category = (Category) DomainObjectFactory.newInstance(
|
||||||
collection.getDataObject());
|
collection.getDataObject());
|
||||||
|
collection.close();
|
||||||
return new CategoryFilter(label, category);
|
return new CategoryFilter(label, category);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException(String.format(
|
throw new IllegalArgumentException(String.format(
|
||||||
|
|
@ -75,9 +76,13 @@ public class CategoryFilter {
|
||||||
|
|
||||||
public Element getXml() {
|
public Element getXml() {
|
||||||
final Element filter = new Element("filter");
|
final Element filter = new Element("filter");
|
||||||
|
final Element categoriesElem = new Element("categories");
|
||||||
final Element invalid = new Element("invalid");
|
final Element invalid = new Element("invalid");
|
||||||
filter.addAttribute("name", "categoryFilter");
|
boolean invalidFound = false;
|
||||||
|
final StringBuffer searchString = new StringBuffer();
|
||||||
|
final StringBuffer categoriesStr = new StringBuffer();
|
||||||
|
|
||||||
|
filter.addAttribute("type", "categoryFilter");
|
||||||
filter.addAttribute("label", label);
|
filter.addAttribute("label", label);
|
||||||
|
|
||||||
final CategoryCollection categories = filterRootCat.getChildren();
|
final CategoryCollection categories = filterRootCat.getChildren();
|
||||||
|
|
@ -86,32 +91,53 @@ public class CategoryFilter {
|
||||||
Category category;
|
Category category;
|
||||||
while (categories.next()) {
|
while (categories.next()) {
|
||||||
category = categories.getCategory();
|
category = categories.getCategory();
|
||||||
addCategoryToFilter(filter, category);
|
addCategoryToFilter(categoriesElem, category, searchString);
|
||||||
|
if (categoriesStr.length() > 0) {
|
||||||
|
categoriesStr.append(", ");
|
||||||
}
|
}
|
||||||
|
categoriesStr.append('"').append(category.getName()).append('"');
|
||||||
|
}
|
||||||
|
|
||||||
|
filter.newChildElement("searchString").setText(searchString.toString());
|
||||||
|
filter.newChildElement("categoriesStr").setText(categoriesStr.toString());
|
||||||
|
filter.newChildElement("separator").setText(separator);
|
||||||
|
|
||||||
for (String value : values) {
|
for (String value : values) {
|
||||||
if (!catNameToCatId.containsKey(value)) {
|
if (!catNameToCatId.containsKey(value)) {
|
||||||
invalid.newChildElement("value").setText(value);
|
invalid.newChildElement("value").setText(value);
|
||||||
|
invalidFound = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
filter.addContent(categoriesElem);
|
||||||
|
if (invalidFound) {
|
||||||
filter.addContent(invalid);
|
filter.addContent(invalid);
|
||||||
|
}
|
||||||
|
|
||||||
return filter;
|
return filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addCategoryToFilter(final Element parent,
|
private void addCategoryToFilter(final Element parent,
|
||||||
final Category category) {
|
final Category category,
|
||||||
|
final StringBuffer searchString) {
|
||||||
final Element elem = new Element("category");
|
final Element elem = new Element("category");
|
||||||
elem.addAttribute("id", category.getID().toString());
|
elem.addAttribute("id", category.getID().toString());
|
||||||
//if ((values != null) && !values.isEmpty() && values.contains(category.getID().toString())) {
|
//if ((values != null) && !values.isEmpty() && values.contains(category.getID().toString())) {
|
||||||
if ((values != null) && !values.isEmpty() && values.contains(category.getName())) {
|
if ((values != null) && !values.isEmpty() && values.contains(category.getName())) {
|
||||||
elem.addAttribute("selected", "selected");
|
elem.addAttribute("selected", "selected");
|
||||||
|
if (searchString.length() > 0) {
|
||||||
|
searchString.append(' ');
|
||||||
|
}
|
||||||
|
searchString.append(category.getName());
|
||||||
}
|
}
|
||||||
elem.setText(category.getName());
|
elem.setText(category.getName());
|
||||||
parent.addContent(elem);
|
parent.addContent(elem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getLabel() {
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
public String getSeparator() {
|
public String getSeparator() {
|
||||||
return separator;
|
return separator;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -329,7 +329,7 @@ public class CustomizableObjectList extends ComplexObjectList {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (categoryFilter != null) {
|
if (categoryFilter != null) {
|
||||||
final String value = Globalization.decodeParameter(request, "categoryFilter");
|
final String value = Globalization.decodeParameter(request, categoryFilter.getLabel());
|
||||||
|
|
||||||
if ((value != null) && !value.isEmpty()) {
|
if ((value != null) && !value.isEmpty()) {
|
||||||
categoryFilter.setValue(value);
|
categoryFilter.setValue(value);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue