Search in sources :

Example 6 with ListGrid

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";
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) Entity(org.broadleafcommerce.openadmin.dto.Entity) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) PersistenceResponse(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse) Property(org.broadleafcommerce.openadmin.dto.Property) ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid) JsonResponse(org.broadleafcommerce.common.web.JsonResponse) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with ListGrid

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";
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) Field(org.broadleafcommerce.openadmin.web.form.entity.Field) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with ListGrid

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";
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) Property(org.broadleafcommerce.openadmin.dto.Property) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with ListGrid

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;
}
Also used : FetchPageRequest(org.broadleafcommerce.openadmin.server.domain.FetchPageRequest) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid)

Example 10 with 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";
}
Also used : Translation(org.broadleafcommerce.common.i18n.domain.Translation) ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ListGrid (org.broadleafcommerce.openadmin.web.form.component.ListGrid)23 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)11 Property (org.broadleafcommerce.openadmin.dto.Property)11 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)10 SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)7 Entity (org.broadleafcommerce.openadmin.dto.Entity)7 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)6 Field (org.broadleafcommerce.openadmin.web.form.entity.Field)6 BasicCollectionMetadata (org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata)5 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)5 AdornedTargetCollectionMetadata (org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)4 ComboField (org.broadleafcommerce.openadmin.web.form.entity.ComboField)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 PersistenceResponse (org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse)3 ListGridAction (org.broadleafcommerce.openadmin.web.form.component.ListGridAction)3 MediaField (org.broadleafcommerce.openadmin.web.form.component.MediaField)3