Search in sources :

Example 6 with EntityForm

use of org.broadleafcommerce.openadmin.web.form.entity.EntityForm in project BroadleafCommerce by BroadleafCommerce.

the class AdminOfferController method modifyModelAttributes.

/**
 * Offer field visibility is dependent on other fields in the entity. Mark the form with the appropriate class
 * so that the Javascript will know to handle this form.
 *
 * We also want to tell the UI to make item target criteria required. We cannot manage this at the entity level via an
 * @AdminPresentation annotation as it is only required when the offer type has a type of {@link OfferType#ORDER_ITEM}.
 */
protected void modifyModelAttributes(Model model) {
    model.addAttribute("additionalControllerClasses", "offer-form");
    EntityForm form = (EntityForm) model.asMap().get("entityForm");
    if (form != null && form.findField("targetItemCriteria") != null) {
        form.findField("targetItemCriteria").setRequired(true);
    }
}
Also used : EntityForm(org.broadleafcommerce.openadmin.web.form.entity.EntityForm)

Example 7 with EntityForm

use of org.broadleafcommerce.openadmin.web.form.entity.EntityForm in project BroadleafCommerce by BroadleafCommerce.

the class AdminEntityServiceImpl method addEntity.

@Override
public PersistenceResponse addEntity(EntityForm entityForm, String[] customCriteria, List<SectionCrumb> sectionCrumb) throws ServiceException {
    PersistencePackageRequest ppr = getRequestForEntityForm(entityForm, customCriteria, sectionCrumb);
    // based on the criteria specific in the PersistencePackage.
    for (Entry<String, EntityForm> entry : entityForm.getDynamicForms().entrySet()) {
        DynamicEntityFormInfo info = entityForm.getDynamicFormInfo(entry.getKey());
        if (info.getCustomCriteriaOverride() != null) {
            customCriteria = info.getCustomCriteriaOverride();
        } else {
            String propertyName = info.getPropertyName();
            String propertyValue;
            if (entityForm.getFields().containsKey(propertyName)) {
                propertyValue = entityForm.findField(propertyName).getValue();
            } else {
                propertyValue = info.getPropertyValue();
            }
            customCriteria = new String[] { info.getCriteriaName(), entityForm.getId(), propertyName, propertyValue };
        }
        PersistencePackageRequest subRequest = getRequestForEntityForm(entry.getValue(), customCriteria, sectionCrumb);
        ppr.addSubRequest(info.getPropertyName(), subRequest);
    }
    return add(ppr);
}
Also used : EntityForm(org.broadleafcommerce.openadmin.web.form.entity.EntityForm) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) DynamicEntityFormInfo(org.broadleafcommerce.openadmin.web.form.entity.DynamicEntityFormInfo)

Example 8 with EntityForm

use of org.broadleafcommerce.openadmin.web.form.entity.EntityForm in project BroadleafCommerce by BroadleafCommerce.

the class AdminEntityServiceImpl method updateEntity.

@Override
public PersistenceResponse updateEntity(EntityForm entityForm, String[] customCriteria, List<SectionCrumb> sectionCrumb) throws ServiceException {
    PersistencePackageRequest ppr = getRequestForEntityForm(entityForm, customCriteria, sectionCrumb);
    ppr.setRequestingEntityName(entityForm.getMainEntityName());
    // based on the criteria specific in the PersistencePackage.
    for (Entry<String, EntityForm> entry : entityForm.getDynamicForms().entrySet()) {
        DynamicEntityFormInfo info = entityForm.getDynamicFormInfo(entry.getKey());
        if (info.getCustomCriteriaOverride() != null) {
            customCriteria = info.getCustomCriteriaOverride();
        } else {
            String propertyName = info.getPropertyName();
            String propertyValue = entityForm.findField(propertyName).getValue();
            customCriteria = new String[] { info.getCriteriaName(), entityForm.getId(), propertyName, propertyValue };
        }
        PersistencePackageRequest subRequest = getRequestForEntityForm(entry.getValue(), customCriteria, sectionCrumb);
        subRequest.withSecurityCeilingEntityClassname(info.getSecurityCeilingClassName());
        ppr.addSubRequest(info.getPropertyName(), subRequest);
    }
    return update(ppr);
}
Also used : EntityForm(org.broadleafcommerce.openadmin.web.form.entity.EntityForm) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) DynamicEntityFormInfo(org.broadleafcommerce.openadmin.web.form.entity.DynamicEntityFormInfo)

Example 9 with EntityForm

use of org.broadleafcommerce.openadmin.web.form.entity.EntityForm in project BroadleafCommerce by BroadleafCommerce.

the class AdminUserManagementController method viewEntityForm.

@Override
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String viewEntityForm(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value = "id") String id) throws Exception {
    // Get the normal entity form for this item
    String returnPath = super.viewEntityForm(request, response, model, pathVars, id);
    EntityForm ef = (EntityForm) model.asMap().get("entityForm");
    // Remove List Grid for Additional Fields
    ef.removeListGrid("additionalFields");
    return returnPath;
}
Also used : EntityForm(org.broadleafcommerce.openadmin.web.form.entity.EntityForm) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with EntityForm

use of org.broadleafcommerce.openadmin.web.form.entity.EntityForm in project BroadleafCommerce by BroadleafCommerce.

the class AdminBasicEntityController method viewAddEntityForm.

/**
 * Renders the modal form that is used to add a new parent level entity. Note that this form cannot render any
 * subcollections as operations on those collections require the parent level entity to first be saved and have
 * and id. Once the entity is initially saved, we will redirect the user to the normal manage entity screen where
 * they can then perform operations on sub collections.
 *
 * @param request
 * @param response
 * @param model
 * @param pathVars
 * @param entityType
 * @return the return view path
 * @throws Exception
 */
@RequestMapping(value = "/add", method = RequestMethod.GET)
public String viewAddEntityForm(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @RequestParam(defaultValue = "") String entityType) throws Exception {
    String sectionKey = getSectionKey(pathVars);
    String sectionClassName = getClassNameForSection(sectionKey);
    List<SectionCrumb> sectionCrumbs = getSectionCrumbs(request, null, null);
    PersistencePackageRequest ppr = getSectionPersistencePackageRequest(sectionClassName, sectionCrumbs, pathVars);
    ppr.setAddOperationInspect(true);
    ClassMetadata cmd = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
    // If the entity type isn't specified, we need to determine if there are various polymorphic types for this entity.
    if (StringUtils.isBlank(entityType)) {
        if (cmd.getPolymorphicEntities().getChildren().length == 0) {
            entityType = cmd.getPolymorphicEntities().getFullyQualifiedClassname();
        } else {
            entityType = getDefaultEntityType();
        }
    } else {
        entityType = URLDecoder.decode(entityType, "UTF-8");
    }
    EntityForm entityForm = formService.createEntityForm(cmd, sectionCrumbs);
    // We need to make sure that the ceiling entity is set to the interface and the specific entity type
    // is set to the type we're going to be creating.
    entityForm.setCeilingEntityClassname(cmd.getCeilingType());
    entityForm.setEntityType(entityType);
    // When we initially build the class metadata (and thus, the entity form), we had all of the possible
    // polymorphic fields built out. Now that we have a concrete entity type to render, we can remove the
    // fields that are not applicable for this given entity type.
    formService.removeNonApplicableFields(cmd, entityForm, entityType);
    modifyAddEntityForm(entityForm, pathVars);
    model.addAttribute("entityForm", entityForm);
    model.addAttribute("viewType", "modal/entityAdd");
    model.addAttribute("entityFriendlyName", cmd.getPolymorphicEntities().getFriendlyName());
    model.addAttribute("currentUrl", request.getRequestURL().toString());
    model.addAttribute("modalHeaderType", ModalHeaderType.ADD_ENTITY.getType());
    setModelAttributes(model, sectionKey);
    return "modules/modalContainer";
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) EntityForm(org.broadleafcommerce.openadmin.web.form.entity.EntityForm) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

EntityForm (org.broadleafcommerce.openadmin.web.form.entity.EntityForm)33 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)12 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)10 Field (org.broadleafcommerce.openadmin.web.form.entity.Field)10 SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)8 DynamicEntityFormInfo (org.broadleafcommerce.openadmin.web.form.entity.DynamicEntityFormInfo)7 ArrayList (java.util.ArrayList)6 Entity (org.broadleafcommerce.openadmin.dto.Entity)5 HashMap (java.util.HashMap)3 Map (java.util.Map)3 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)3 Property (org.broadleafcommerce.openadmin.dto.Property)3 Page (org.broadleafcommerce.cms.page.domain.Page)2 Translation (org.broadleafcommerce.common.i18n.domain.Translation)2 BasicCollectionMetadata (org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata)2 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)2 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)2 ListGrid (org.broadleafcommerce.openadmin.web.form.component.ListGrid)2 EntityFormAction (org.broadleafcommerce.openadmin.web.form.entity.EntityFormAction)2