Search in sources :

Example 31 with Field

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

the class AdminUserManagementController method modifyEntityForm.

@Override
protected void modifyEntityForm(EntityForm ef, Map<String, String> pathVars) {
    // Remove password/confirm password field for EntityForm edit pages if it has been previously set.
    // Password changes should be done through the "Forgot Password" flow before the user has logged in,
    // or "Change Password" flow after the user is logged in.
    Field password = ef.findField("password");
    Field passwordConfirm = ef.findField("passwordConfirm");
    if (password != null && password.getValue() != null && !password.getValue().isEmpty()) {
        password.setIsVisible(false);
        passwordConfirm.setIsVisible(false);
    }
}
Also used : Field(org.broadleafcommerce.openadmin.web.form.entity.Field)

Example 32 with Field

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

the class AdminBasicEntityController method addAuditableDisplayFields.

public void addAuditableDisplayFields(EntityForm entityForm) {
    Field createdBy = entityForm.findField("auditable.createdBy");
    if (createdBy != null && createdBy.getValue() != null) {
        addAuditableDisplayField(entityForm, createdBy);
        createdBy.setIsVisible(false);
    }
    Field updatedBy = entityForm.findField("auditable.updatedBy");
    if (updatedBy != null && updatedBy.getValue() != null) {
        addAuditableDisplayField(entityForm, updatedBy);
        updatedBy.setIsVisible(false);
    }
}
Also used : Field(org.broadleafcommerce.openadmin.web.form.entity.Field)

Example 33 with Field

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

the class AdminBasicEntityController method updateCollectionItemSequence.

/**
 * Updates the given collection item's sequence. This should only be triggered for adorned target collections
 * where a sort field is specified -- any other invocation is incorrect and will result in an exception.
 *
 * @param request
 * @param response
 * @param model
 * @param pathVars
 * @param id
 * @param collectionField
 * @param collectionItemId
 * @return an object explaining the state of the operation
 * @throws Exception
 */
@RequestMapping(value = "/{id}/{collectionField:.*}/{collectionItemId}/{alternateId}/sequence", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> updateCollectionItemSequence(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, @RequestParam(value = "newSequence") String newSequence, @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);
    FieldMetadata md = collectionProperty.getMetadata();
    PersistencePackageRequest ppr = getSectionPersistencePackageRequest(mainClassName, sectionCrumbs, pathVars);
    ppr.addCustomCriteria("reorderParentEntityFetch");
    Entity parentEntity = service.getRecord(ppr, id, mainMetadata, false).getDynamicResultSet().getRecords()[0];
    ppr = PersistencePackageRequest.fromMetadata(md, sectionCrumbs);
    if (md instanceof AdornedTargetCollectionMetadata) {
        AdornedTargetCollectionMetadata fmd = (AdornedTargetCollectionMetadata) md;
        AdornedTargetList atl = ppr.getAdornedList();
        // Get an entity form for the entity
        EntityForm entityForm = formService.buildAdornedListForm(fmd, ppr.getAdornedList(), id, false, sectionCrumbs, false);
        Entity entity = service.getAdvancedCollectionRecord(mainMetadata, parentEntity, collectionProperty, collectionItemId, sectionCrumbs, alternateId, new String[] { "reorderChildEntityFetch" }).getDynamicResultSet().getRecords()[0];
        formService.populateEntityFormFields(entityForm, entity);
        formService.populateAdornedEntityFormFields(entityForm, entity, ppr.getAdornedList());
        // Set the new sequence (note that it will come in 0-indexed but the persistence module expects 1-indexed)
        int sequenceValue = Integer.parseInt(newSequence) + 1;
        Field field = entityForm.findField(atl.getSortField());
        field.setValue(String.valueOf(sequenceValue));
        Map<String, Object> responseMap = new HashMap<>();
        PersistenceResponse persistenceResponse = service.updateSubCollectionEntity(entityForm, mainMetadata, collectionProperty, parentEntity, collectionItemId, alternateId, sectionCrumbs);
        Property displayOrder = persistenceResponse.getEntity().findProperty(atl.getSortField());
        responseMap.put("status", "ok");
        responseMap.put("field", collectionField);
        responseMap.put("newDisplayOrder", displayOrder == null ? null : displayOrder.getValue());
        return responseMap;
    } else if (md instanceof BasicCollectionMetadata) {
        BasicCollectionMetadata cd = (BasicCollectionMetadata) md;
        Map<String, Object> responseMap = new HashMap<>();
        Entity entity = service.getRecord(ppr, collectionItemId, mainMetadata, false).getDynamicResultSet().getRecords()[0];
        ClassMetadata collectionMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
        EntityForm entityForm = formService.createEntityForm(collectionMetadata, sectionCrumbs);
        if (!StringUtils.isEmpty(cd.getSortProperty())) {
            Field f = new Field().withName(cd.getSortProperty()).withFieldType(SupportedFieldType.HIDDEN.toString());
            entityForm.addHiddenField(mainMetadata, f);
        }
        formService.populateEntityFormFields(entityForm, entity);
        if (!StringUtils.isEmpty(cd.getSortProperty())) {
            int sequenceValue = Integer.parseInt(newSequence) + 1;
            Field field = entityForm.findField(cd.getSortProperty());
            field.setValue(String.valueOf(sequenceValue));
        }
        PersistenceResponse persistenceResponse = service.updateSubCollectionEntity(entityForm, mainMetadata, collectionProperty, parentEntity, collectionItemId, sectionCrumbs);
        Property displayOrder = persistenceResponse.getEntity().findProperty(cd.getSortProperty());
        responseMap.put("status", "ok");
        responseMap.put("field", collectionField);
        responseMap.put("newDisplayOrder", displayOrder == null ? null : displayOrder.getValue());
        return responseMap;
    } else {
        throw new UnsupportedOperationException("Cannot handle sequencing for non adorned target collection fields.");
    }
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) Entity(org.broadleafcommerce.openadmin.dto.Entity) EntityForm(org.broadleafcommerce.openadmin.web.form.entity.EntityForm) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) HashMap(java.util.HashMap) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) PersistenceResponse(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse) SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) Field(org.broadleafcommerce.openadmin.web.form.entity.Field) BasicCollectionMetadata(org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata) Property(org.broadleafcommerce.openadmin.dto.Property) AdornedTargetList(org.broadleafcommerce.openadmin.dto.AdornedTargetList) Map(java.util.Map) HashMap(java.util.HashMap) FlashMap(org.springframework.web.servlet.FlashMap) MultiValueMap(org.springframework.util.MultiValueMap) AdornedTargetCollectionMetadata(org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 34 with Field

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

the class JSFieldNameCompatibilityInterceptor method postHandle.

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
    if (modelAndView != null) {
        Entity entity = (Entity) modelAndView.getModelMap().get("entity");
        EntityForm entityForm = (EntityForm) modelAndView.getModelMap().get("entityForm");
        if (entity != null) {
            if (entity.getProperties() != null) {
                for (Property property : entity.getProperties()) {
                    if (property.getName().contains(".")) {
                        property.setName(JSCompatibilityHelper.encode(property.getName()));
                    }
                }
            }
        }
        if (entityForm != null) {
            entityForm.clearFieldsMap();
            for (Map.Entry<String, Field> field : entityForm.getFields().entrySet()) {
                if (field.getKey().contains(".")) {
                    field.getValue().setName(JSCompatibilityHelper.encode(field.getValue().getName()));
                    field.getValue().setAssociatedFieldName(JSCompatibilityHelper.encode(field.getValue().getAssociatedFieldName()));
                    if (field.getValue() instanceof RuleBuilderField) {
                        ((RuleBuilderField) field.getValue()).setJsonFieldName(JSCompatibilityHelper.encode(((RuleBuilderField) field.getValue()).getJsonFieldName()));
                    }
                }
            }
            entityForm.clearFieldsMap();
        }
    }
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) EntityForm(org.broadleafcommerce.openadmin.web.form.entity.EntityForm) RuleBuilderField(org.broadleafcommerce.openadmin.web.form.component.RuleBuilderField) Field(org.broadleafcommerce.openadmin.web.form.entity.Field) RuleBuilderField(org.broadleafcommerce.openadmin.web.form.component.RuleBuilderField) Property(org.broadleafcommerce.openadmin.dto.Property) Map(java.util.Map)

Example 35 with Field

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

the class AdminAbstractController method extractDynamicFormFields.

/**
 * This method will scan the entityForm for all dynamic form fields and pull them out
 * as appropriate.
 *
 * @param cmd
 * @param entityForm
 */
protected void extractDynamicFormFields(ClassMetadata cmd, EntityForm entityForm) {
    Map<String, Field> dynamicFields = new HashMap<>();
    // Find all of the dynamic form fields
    for (Entry<String, Field> entry : entityForm.getFields().entrySet()) {
        if (entry.getKey().contains(DynamicEntityFormInfo.FIELD_SEPARATOR)) {
            dynamicFields.put(entry.getKey(), entry.getValue());
        }
    }
    // Remove the dynamic form fields from the main entity - they are persisted separately
    for (Entry<String, Field> entry : dynamicFields.entrySet()) {
        entityForm.removeField(entry.getKey());
    }
    // Create the entity form for the dynamic form, as it needs to be persisted separately
    for (Entry<String, Field> entry : dynamicFields.entrySet()) {
        String[] fieldName = entry.getKey().split("\\" + DynamicEntityFormInfo.FIELD_SEPARATOR);
        DynamicEntityFormInfo info = entityForm.getDynamicFormInfo(fieldName[0]);
        EntityForm dynamicForm = entityForm.getDynamicForm(fieldName[0]);
        if (dynamicForm == null) {
            dynamicForm = new EntityForm();
            dynamicForm.setCeilingEntityClassname(info.getCeilingClassName());
            entityForm.putDynamicForm(fieldName[0], dynamicForm);
        }
        entry.getValue().setName(fieldName[1]);
        dynamicForm.addField(cmd, entry.getValue());
    }
}
Also used : Field(org.broadleafcommerce.openadmin.web.form.entity.Field) EntityForm(org.broadleafcommerce.openadmin.web.form.entity.EntityForm) HashMap(java.util.HashMap) DynamicEntityFormInfo(org.broadleafcommerce.openadmin.web.form.entity.DynamicEntityFormInfo)

Aggregations

Field (org.broadleafcommerce.openadmin.web.form.entity.Field)36 Property (org.broadleafcommerce.openadmin.dto.Property)15 ComboField (org.broadleafcommerce.openadmin.web.form.entity.ComboField)15 MediaField (org.broadleafcommerce.openadmin.web.form.component.MediaField)14 RuleBuilderField (org.broadleafcommerce.openadmin.web.form.component.RuleBuilderField)14 CodeField (org.broadleafcommerce.openadmin.web.form.entity.CodeField)13 ArrayList (java.util.ArrayList)10 EntityForm (org.broadleafcommerce.openadmin.web.form.entity.EntityForm)10 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)9 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)8 Entity (org.broadleafcommerce.openadmin.dto.Entity)8 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)7 ListGrid (org.broadleafcommerce.openadmin.web.form.component.ListGrid)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 HashMap (java.util.HashMap)5 SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)5 Map (java.util.Map)4 AdminMainEntity (org.broadleafcommerce.common.admin.domain.AdminMainEntity)4 Translation (org.broadleafcommerce.common.i18n.domain.Translation)4 DataWrapper (org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper)4