use of org.broadleafcommerce.openadmin.web.form.component.ListGrid in project BroadleafCommerce by BroadleafCommerce.
the class AdminBasicEntityController method removeCollectionItem.
/**
* Removes the requested collection item
*
* Note that the request must contain a parameter called "key" when attempting to remove a collection item from a
* map collection.
*
* @param request
* @param response
* @param model
* @param pathVars
* @param id
* @param collectionField
* @param collectionItemId
* @return the return view path
* @throws Exception
*/
@RequestMapping(value = "/{id}/{collectionField:.*}/{collectionItemId}/{alternateId}/delete", method = RequestMethod.POST)
public String removeCollectionItem(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value = "id") String id, @PathVariable(value = "collectionField") String collectionField, @PathVariable(value = "collectionItemId") String collectionItemId, @PathVariable(value = "alternateId") String alternateId) throws Exception {
String sectionKey = getSectionKey(pathVars);
String mainClassName = getClassNameForSection(sectionKey);
List<SectionCrumb> sectionCrumbs = getSectionCrumbs(request, sectionKey, id);
ClassMetadata mainMetadata = service.getClassMetadata(getSectionPersistencePackageRequest(mainClassName, sectionCrumbs, pathVars)).getDynamicResultSet().getClassMetaData();
Property collectionProperty = mainMetadata.getPMap().get(collectionField);
String priorKey = request.getParameter("key");
PersistencePackageRequest ppr = getSectionPersistencePackageRequest(mainClassName, sectionCrumbs, pathVars);
declareShouldIgnoreAdditionStatusFilter();
Entity entity = service.getRecord(ppr, id, mainMetadata, false).getDynamicResultSet().getRecords()[0];
// First, we must remove the collection entity
PersistenceResponse persistenceResponse = service.removeSubCollectionEntity(mainMetadata, collectionProperty, entity, collectionItemId, alternateId, priorKey, sectionCrumbs);
if (persistenceResponse.getEntity() != null && persistenceResponse.getEntity().isValidationFailure()) {
String error = "There was an error removing the whatever";
if (MapUtils.isNotEmpty(persistenceResponse.getEntity().getPropertyValidationErrors())) {
// If we failed, we'll return some JSON with the first error
error = persistenceResponse.getEntity().getPropertyValidationErrors().values().iterator().next().get(0);
} else if (CollectionUtils.isNotEmpty(persistenceResponse.getEntity().getGlobalValidationErrors())) {
error = persistenceResponse.getEntity().getGlobalValidationErrors().get(0);
}
return new JsonResponse(response).with("status", "error").with("message", BLCMessageUtils.getMessage(error)).done();
}
// Next, we must get the new list grid that represents this collection
// We return the new list grid so that it can replace the currently visible one
ListGrid listGrid = getCollectionListGrid(mainMetadata, entity, collectionProperty, null, sectionKey, persistenceResponse, sectionCrumbs);
model.addAttribute("listGrid", listGrid);
model.addAttribute("currentUrl", request.getRequestURL().toString());
setModelAttributes(model, sectionKey);
return "views/standaloneListGrid";
}
use of org.broadleafcommerce.openadmin.web.form.component.ListGrid in project BroadleafCommerce by BroadleafCommerce.
the class AdminBasicEntityController method viewEntityList.
// ******************************************
// REQUEST-MAPPING BOUND CONTROLLER METHODS *
// ******************************************
/**
* Renders the main entity listing for the specified class, which is based on the current sectionKey with some optional
* criteria.
*
* @param request
* @param response
* @param model
* @param pathVars
* @param requestParams a Map of property name -> list critiera values
* @return the return view path
* @throws Exception
*/
@RequestMapping(value = "", method = RequestMethod.GET)
public String viewEntityList(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @RequestParam MultiValueMap<String, String> requestParams) throws Exception {
String sectionKey = getSectionKey(pathVars);
String sectionClassName = getClassNameForSection(sectionKey);
List<SectionCrumb> crumbs = getSectionCrumbs(request, null, null);
PersistencePackageRequest ppr = getSectionPersistencePackageRequest(sectionClassName, requestParams, crumbs, pathVars);
ClassMetadata cmd = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
DynamicResultSet drs = service.getRecords(ppr).getDynamicResultSet();
ListGrid listGrid = formService.buildMainListGrid(drs, cmd, sectionKey, crumbs);
listGrid.setSelectType(ListGrid.SelectType.NONE);
Set<Field> headerFields = listGrid.getHeaderFields();
if (CollectionUtils.isNotEmpty(headerFields)) {
Field firstField = headerFields.iterator().next();
if (requestParams.containsKey(firstField.getName())) {
model.addAttribute("mainSearchTerm", requestParams.get(firstField.getName()).get(0));
}
}
model.addAttribute("viewType", "entityList");
setupViewEntityListBasicModel(request, cmd, sectionKey, sectionClassName, model, requestParams);
model.addAttribute("listGrid", listGrid);
return "modules/defaultContainer";
}
use of org.broadleafcommerce.openadmin.web.form.component.ListGrid in project BroadleafCommerce by BroadleafCommerce.
the class AdminBasicOperationsController method showSelectCollectionItem.
/**
* Shows the modal dialog that is used to select a "to-one" collection item. For example, this could be used to show
* a list of categories for the ManyToOne field "defaultCategory" in Product.
*
* @param request
* @param response
* @param model
* @param pathVars
* @param owningClass
* @param collectionField
* @return the return view path
* @throws Exception
*/
@RequestMapping(value = "/{owningClass:.*}/{collectionField:.*}/select", method = RequestMethod.GET)
public String showSelectCollectionItem(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value = "owningClass") String owningClass, @PathVariable(value = "collectionField") String collectionField, @RequestParam(required = false) String requestingEntityId, @RequestParam(defaultValue = "false") boolean dynamicField, @RequestParam MultiValueMap<String, String> requestParams) throws Exception {
List<SectionCrumb> sectionCrumbs = getSectionCrumbs(request, null, null);
String validatedClass = getClassNameForSection(owningClass);
PersistencePackageRequest ppr = getSectionPersistencePackageRequest(validatedClass, requestParams, sectionCrumbs, pathVars);
// We might need these fields in the initial inspect.
ppr.addCustomCriteria("requestingEntityId=" + requestingEntityId);
ppr.addCustomCriteria("owningClass=" + owningClass);
ppr.addCustomCriteria("requestingField=" + collectionField);
ClassMetadata mainMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
// Only get collection property metadata when there is a non-structured content field that I am looking for
Property collectionProperty = null;
FieldMetadata md = null;
if (!collectionField.contains("|") && !dynamicField) {
collectionProperty = mainMetadata.getPMap().get(collectionField);
md = collectionProperty.getMetadata();
ppr = PersistencePackageRequest.fromMetadata(md, sectionCrumbs);
} else {
md = new BasicFieldMetadata();
md.setFriendlyName(mainMetadata.getPolymorphicEntities().getFriendlyName());
collectionProperty = new Property();
collectionProperty.setMetadata(md);
}
ppr.addFilterAndSortCriteria(getCriteria(requestParams));
ppr.setStartIndex(getStartIndex(requestParams));
ppr.setMaxIndex(getMaxIndex(requestParams));
ppr.removeFilterAndSortCriteria("requestingEntityId");
ppr.addCustomCriteria("requestingEntityId=" + requestingEntityId);
ppr.addCustomCriteria("owningClass=" + owningClass);
ppr.addCustomCriteria("requestingField=" + collectionField);
modifyFetchPersistencePackageRequest(ppr, pathVars);
ClassMetadata targetClassMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
ExtensionResultStatusType extensionResultStatusType = extensionManager.getProxy().buildLookupListGrid(ppr, targetClassMetadata, ppr.getCeilingEntityClassname(), sectionCrumbs, model, requestParams);
if (extensionResultStatusType.equals(ExtensionResultStatusType.NOT_HANDLED)) {
DynamicResultSet drs = service.getRecords(ppr).getDynamicResultSet();
ListGrid listGrid = null;
if (collectionField.contains("|") || dynamicField) {
// If we're dealing with a lookup from a dynamic field, we need to build the list grid differently
listGrid = formService.buildMainListGrid(drs, mainMetadata, "/" + owningClass, sectionCrumbs);
listGrid.setListGridType(ListGrid.Type.TO_ONE);
listGrid.setSubCollectionFieldName(collectionField);
listGrid.setPathOverride("/" + owningClass + "/" + collectionField + "/select");
} else if (md instanceof BasicFieldMetadata) {
listGrid = formService.buildCollectionListGrid(null, drs, collectionProperty, owningClass, sectionCrumbs);
listGrid.removeAllRowActions();
}
model.addAttribute("listGrid", listGrid);
}
model.addAttribute("viewType", "modal/simpleSelectEntity");
model.addAttribute("currentUrl", request.getRequestURL().toString());
model.addAttribute("modalHeaderType", ModalHeaderType.SELECT_COLLECTION_ITEM.getType());
model.addAttribute("collectionProperty", collectionProperty);
model.addAttribute("sectionCrumbs", request.getParameter("sectionCrumbs"));
setModelAttributes(model, owningClass);
return "modules/modalContainer";
}
use of org.broadleafcommerce.openadmin.web.form.component.ListGrid in project BroadleafCommerce by BroadleafCommerce.
the class AdminAbstractController method getCollectionListGrid.
// **********************************
// HELPER METHODS FOR BUILDING DTOS *
// **********************************
/**
* Convenience method for obtaining a ListGrid DTO object for a collection. Note that if no <b>criteria</b> is
* available, then this should be null (or empty)
*
* @param mainMetadata class metadata for the root entity that this <b>collectionProperty</b> relates to
* @param entity
* @param collectionProperty property that this collection should be based on from the root entity
* @param requestParams
* @param sectionKey the current main section key
* @param persistenceResponse
* @param sectionCrumbs
* @return the list grid
* @throws ServiceException
*/
protected ListGrid getCollectionListGrid(ClassMetadata mainMetadata, Entity entity, Property collectionProperty, MultiValueMap<String, String> requestParams, String sectionKey, PersistenceResponse persistenceResponse, List<SectionCrumb> sectionCrumbs) throws ServiceException {
String idProperty = service.getIdProperty(mainMetadata);
if (persistenceResponse != null && persistenceResponse.getAdditionalData().containsKey(PersistenceResponse.AdditionalData.CLONEID)) {
entity.findProperty(idProperty).setValue((String) persistenceResponse.getAdditionalData().get(PersistenceResponse.AdditionalData.CLONEID));
}
FetchPageRequest pageRequest = new FetchPageRequest().withLastId(getLastId(requestParams)).withFirstId(getFirstId(requestParams)).withStartIndex(getStartIndex(requestParams)).withMaxIndex(getMaxIndex(requestParams)).withUpperCount(getUpperCount(requestParams)).withLowerCount(getLowerCount(requestParams)).withPageSize(getPageSize(requestParams));
DynamicResultSet drs = service.getPagedRecordsForCollection(mainMetadata, entity, collectionProperty, getCriteria(requestParams), pageRequest, null, sectionCrumbs).getDynamicResultSet();
ListGrid listGrid = formService.buildCollectionListGrid(entity.findProperty(idProperty).getValue(), drs, collectionProperty, sectionKey, sectionCrumbs);
return listGrid;
}
use of org.broadleafcommerce.openadmin.web.form.component.ListGrid in project BroadleafCommerce by BroadleafCommerce.
the class AdminTranslationController method viewTranslation.
/**
* Invoked when the translation button is clicked on a given translatable field
*
* @param request
* @param response
* @param model
* @param form
* @param result
* @return the return view path
* @throws Exception
*/
@RequestMapping(value = "", method = RequestMethod.GET)
public String viewTranslation(HttpServletRequest request, HttpServletResponse response, Model model, @ModelAttribute(value = "form") TranslationForm form, BindingResult result) throws Exception {
if (extensionManager != null) {
extensionManager.getProxy().applyTransformation(form);
}
adminRemoteSecurityService.securityCheck(form.getCeilingEntity(), EntityOperationType.FETCH);
List<Translation> translations = translationService.getTranslations(form.getCeilingEntity(), form.getEntityId(), form.getPropertyName());
ListGrid lg = formService.buildListGrid(translations, form.getIsRte());
model.addAttribute("currentUrl", request.getRequestURL().toString());
model.addAttribute("form", form);
model.addAttribute("listGrid", lg);
model.addAttribute("viewType", "modal/translationListGrid");
model.addAttribute("modalHeaderType", ModalHeaderType.TRANSLATION.getType());
return "modules/modalContainer";
}
Aggregations