Search in sources :

Example 31 with EntityForm

use of org.broadleafcommerce.openadmin.web.form.entity.EntityForm 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 32 with EntityForm

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

the class AdminAbstractController method getDynamicForm.

/**
 * Returns a partial representing a dynamic form. An example of this is the dynamic fields that render
 * on structured content, which are determined by the currently selected structured content type. This
 * method is typically only invoked through Javascript and used to replace the current dynamic form with
 * the one for the newly selected type.
 *
 * @param request
 * @param response
 * @param model
 * @param pathVars
 * @param info
 * @return the return view path
 * @throws Exception
 */
protected String getDynamicForm(HttpServletRequest request, HttpServletResponse response, Model model, Map<String, String> pathVars, DynamicEntityFormInfo info) throws Exception {
    String sectionKey = getSectionKey(pathVars);
    EntityForm blankFormContainer = new EntityForm();
    EntityForm dynamicForm = getEntityForm(info);
    // Set the specialized name for these fields - we need to handle them separately
    setSpecializedNameForFields(info, dynamicForm);
    blankFormContainer.putDynamicForm(info.getPropertyName(), dynamicForm);
    model.addAttribute("dynamicForm", dynamicForm);
    model.addAttribute("entityForm", blankFormContainer);
    model.addAttribute("dynamicPropertyName", info.getPropertyName());
    String reqUrl = request.getRequestURL().toString();
    reqUrl = reqUrl.substring(0, reqUrl.indexOf("/dynamicForm"));
    model.addAttribute("currentUrl", reqUrl);
    setModelAttributes(model, sectionKey);
    return "views/dynamicFormPartial";
}
Also used : EntityForm(org.broadleafcommerce.openadmin.web.form.entity.EntityForm)

Example 33 with EntityForm

use of org.broadleafcommerce.openadmin.web.form.entity.EntityForm 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

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