Search in sources :

Example 6 with Field

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

the class AdminAbstractController method getEntityForm.

protected EntityForm getEntityForm(DynamicEntityFormInfo info, EntityForm dynamicFormOverride) throws ServiceException {
    // We need to inspect with the second custom criteria set to the id of
    // the desired structured content type
    PersistencePackageRequest ppr = PersistencePackageRequest.standard().withCeilingEntityClassname(info.getCeilingClassName()).withSecurityCeilingEntityClassname(info.getSecurityCeilingClassName()).withCustomCriteria(new String[] { info.getCriteriaName(), null, info.getPropertyName(), info.getPropertyValue() });
    ClassMetadata cmd = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
    EntityForm dynamicForm = formService.createEntityForm(cmd, null);
    dynamicForm.clearFieldsMap();
    if (dynamicFormOverride != null) {
        dynamicFormOverride.clearFieldsMap();
        Map<String, Field> fieldOverrides = dynamicFormOverride.getFields();
        for (Entry<String, Field> override : fieldOverrides.entrySet()) {
            if (dynamicForm.getFields().containsKey(override.getKey())) {
                dynamicForm.findField(override.getKey()).setValue(override.getValue().getValue());
            }
        }
    }
    return dynamicForm;
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) EntityForm(org.broadleafcommerce.openadmin.web.form.entity.EntityForm) Field(org.broadleafcommerce.openadmin.web.form.entity.Field) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)

Example 7 with Field

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

the class AdminAbstractController method getDynamicFieldTemplateForm.

/**
 * Convenience method for obtaining a dynamic field template form for a particular entity. This method differs from
 * {@link #getBlankDynamicFieldTemplateForm(DynamicEntityFormInfo)} in that it will fill out the current values for
 * the fields in this dynamic form from the database. This method is invoked when the initial view of a page containing
 * a dynamic form is triggered.
 *
 * Optionally, you can pass in a pre-existing dynamic form to this method that already has updated values. Example usage
 * would be for after validation has failed and you do not want to lookup old values from the database again.
 *
 * @param info
 * @param entityId
 * @param dynamicFormOverride optional dynamic form that already has values to fill out
 * @return the entity form
 * @throws ServiceException
 */
protected EntityForm getDynamicFieldTemplateForm(DynamicEntityFormInfo info, String entityId, EntityForm dynamicFormOverride) throws ServiceException {
    // We need to inspect with the second custom criteria set to the id of
    // the desired structured content type
    PersistencePackageRequest ppr = PersistencePackageRequest.standard().withCeilingEntityClassname(info.getCeilingClassName()).withSecurityCeilingEntityClassname(info.getSecurityCeilingClassName()).withCustomCriteria(new String[] { info.getCriteriaName(), entityId, info.getPropertyName(), info.getPropertyValue() });
    ClassMetadata cmd = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
    // However, when we fetch, the second custom criteria needs to be the id
    // of this particular structured content entity
    ppr.setCustomCriteria(new String[] { info.getCriteriaName(), entityId });
    Entity entity = service.getRecord(ppr, info.getPropertyValue(), cmd, true).getDynamicResultSet().getRecords()[0];
    List<Field> fieldsToMove = new ArrayList<>();
    // override the results of the entity with the dynamic form passed in
    if (dynamicFormOverride != null) {
        dynamicFormOverride.clearFieldsMap();
        Map<String, Field> fieldOverrides = dynamicFormOverride.getFields();
        for (Entry<String, Field> override : fieldOverrides.entrySet()) {
            if (entity.getPMap().containsKey(override.getKey())) {
                entity.getPMap().get(override.getKey()).setValue(override.getValue().getValue());
            } else {
                fieldsToMove.add(override.getValue());
            }
        }
    }
    // Assemble the dynamic form for structured content type
    EntityForm dynamicForm = formService.createEntityForm(cmd, entity, null, null);
    for (Field field : fieldsToMove) {
        FieldMetadata fmd = cmd.getPMap().get(field.getName()).getMetadata();
        if (fmd instanceof BasicFieldMetadata) {
            BasicFieldMetadata bfmd = (BasicFieldMetadata) fmd;
            field.setFieldType(bfmd.getFieldType().toString());
            field.setFriendlyName(bfmd.getFriendlyName());
            field.setRequired(bfmd.getRequired());
        }
        dynamicForm.addField(cmd, field);
    }
    setSpecializedNameForFields(info, dynamicForm);
    extensionManager.getProxy().modifyDynamicForm(dynamicForm, entityId);
    return dynamicForm;
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) Entity(org.broadleafcommerce.openadmin.dto.Entity) Field(org.broadleafcommerce.openadmin.web.form.entity.Field) EntityForm(org.broadleafcommerce.openadmin.web.form.entity.EntityForm) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) ArrayList(java.util.ArrayList) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)

Example 8 with Field

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

the class AdminTranslationController method deleteTranslation.

/**
 * Deletes the translation specified by the translation id
 *
 * @param request
 * @param response
 * @param model
 * @param id
 * @param form
 * @param result
 * @return the result of a call to {@link #viewTranslation}, which renders the list grid
 * @throws Exception
 */
@RequestMapping(value = "/delete", method = RequestMethod.POST)
public String deleteTranslation(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @ModelAttribute(value = "form") final TranslationForm form, BindingResult result) throws Exception {
    adminRemoteSecurityService.securityCheck(form.getCeilingEntity(), EntityOperationType.UPDATE);
    SectionCrumb sectionCrumb = new SectionCrumb();
    sectionCrumb.setSectionIdentifier(TranslationImpl.class.getName());
    sectionCrumb.setSectionId(String.valueOf(form.getTranslationId()));
    List<SectionCrumb> sectionCrumbs = Arrays.asList(sectionCrumb);
    String sectionKey = getSectionKey(pathVars);
    String sectionClassName = getClassNameForSection(sectionKey);
    PersistencePackageRequest ppr = getSectionPersistencePackageRequest(sectionClassName, sectionCrumbs, pathVars);
    ClassMetadata cmd = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
    EntityForm entityForm = formService.buildTranslationForm(cmd, form, TranslationFormAction.OTHER);
    entityForm.setCeilingEntityClassname(Translation.class.getName());
    entityForm.setEntityType(TranslationImpl.class.getName());
    Field id = new Field();
    id.setName("id");
    id.setValue(String.valueOf(form.getTranslationId()));
    entityForm.getFields().put("id", id);
    entityForm.setId(String.valueOf(form.getTranslationId()));
    String[] sectionCriteria = customCriteriaService.mergeSectionCustomCriteria(Translation.class.getName(), getSectionCustomCriteria());
    service.removeEntity(entityForm, sectionCriteria, sectionCrumbs);
    return viewTranslation(request, response, model, form, result);
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) EntityForm(org.broadleafcommerce.openadmin.web.form.entity.EntityForm) Field(org.broadleafcommerce.openadmin.web.form.entity.Field) Translation(org.broadleafcommerce.common.i18n.domain.Translation) TranslationImpl(org.broadleafcommerce.common.i18n.domain.TranslationImpl) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with Field

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

the class AdminTranslationController method updateTranslation.

/**
 * Updates the given translation id to the new locale code and translated value
 *
 * @param request
 * @param response
 * @param model
 * @param entityForm
 * @param result
 * @return the result of a call to {@link #viewTranslation}, which renders the list grid
 * @throws Exception
 */
@RequestMapping(value = "/update", method = RequestMethod.POST)
public String updateTranslation(HttpServletRequest request, HttpServletResponse response, Model model, @ModelAttribute(value = "entityForm") EntityForm entityForm, BindingResult result) throws Exception {
    final TranslationForm form = getTranslationForm(entityForm);
    adminRemoteSecurityService.securityCheck(form.getCeilingEntity(), EntityOperationType.UPDATE);
    SectionCrumb sectionCrumb = new SectionCrumb();
    sectionCrumb.setSectionIdentifier(TranslationImpl.class.getName());
    sectionCrumb.setSectionId(String.valueOf(form.getTranslationId()));
    List<SectionCrumb> sectionCrumbs = Arrays.asList(sectionCrumb);
    entityForm.setCeilingEntityClassname(Translation.class.getName());
    entityForm.setEntityType(TranslationImpl.class.getName());
    Field id = new Field();
    id.setName("id");
    id.setValue(String.valueOf(form.getTranslationId()));
    entityForm.getFields().put("id", id);
    entityForm.setId(String.valueOf(form.getTranslationId()));
    String[] sectionCriteria = customCriteriaService.mergeSectionCustomCriteria(Translation.class.getName(), getSectionCustomCriteria());
    service.updateEntity(entityForm, sectionCriteria, sectionCrumbs).getEntity();
    return viewTranslation(request, response, model, form, result);
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) Field(org.broadleafcommerce.openadmin.web.form.entity.Field) Translation(org.broadleafcommerce.common.i18n.domain.Translation) TranslationImpl(org.broadleafcommerce.common.i18n.domain.TranslationImpl) TranslationForm(org.broadleafcommerce.openadmin.web.form.TranslationForm) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with Field

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

the class FormBuilderServiceImpl method buildMapForm.

@Override
public EntityForm buildMapForm(MapMetadata mapMd, final MapStructure mapStructure, ClassMetadata cmd, String parentId, EntityForm ef) throws ServiceException {
    ForeignKey foreignKey = (ForeignKey) mapMd.getPersistencePerspective().getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.FOREIGNKEY);
    ef.setEntityType(foreignKey.getForeignKeyClass());
    Field keyField;
    if (!mapMd.getForceFreeFormKeys()) {
        // We will use a combo field to render the key choices
        ComboField temp = new ComboField();
        temp.withName("key").withFieldType("combo_field").withFriendlyName(mapStructure.getKeyPropertyFriendlyName());
        if (mapMd.getKeys() != null) {
            // The keys can be explicitly set in the annotation...
            temp.setOptions(mapMd.getKeys());
        } else {
            // Or they could be based on a different entity
            PersistencePackageRequest ppr = PersistencePackageRequest.standard().withCeilingEntityClassname(mapMd.getMapKeyOptionEntityClass());
            DynamicResultSet drs = adminEntityService.getRecords(ppr).getDynamicResultSet();
            for (Entity entity : drs.getRecords()) {
                String keyValue = entity.getPMap().get(mapMd.getMapKeyOptionEntityValueField()).getValue();
                String keyDisplayValue = entity.getPMap().get(mapMd.getMapKeyOptionEntityDisplayField()).getValue();
                temp.putOption(keyValue, keyDisplayValue);
            }
        }
        keyField = temp;
    } else {
        keyField = new Field().withName("key").withFieldType(SupportedFieldType.STRING.toString()).withFriendlyName(mapStructure.getKeyPropertyFriendlyName());
    }
    keyField.setRequired(true);
    ef.addMapKeyField(cmd, keyField);
    // Set the fields for this form
    List<Property> mapFormProperties;
    if (mapMd.isSimpleValue()) {
        ef.setIdProperty("key");
        mapFormProperties = new ArrayList<>();
        Property valueProp = cmd.getPMap().get("value");
        mapFormProperties.add(valueProp);
    } else {
        String valueClassName = mapStructure.getValueClassName();
        List<String> classNames = getValueClassNames(valueClassName);
        mapFormProperties = new ArrayList<>(Arrays.asList(cmd.getProperties()));
        filterMapFormProperties(mapFormProperties, classNames);
    }
    setEntityFormFields(cmd, ef, mapFormProperties);
    Field f = new Field().withName("priorKey").withFieldType(SupportedFieldType.HIDDEN.toString());
    ef.addHiddenField(cmd, f);
    ef.setParentId(parentId);
    return ef;
}
Also used : CodeField(org.broadleafcommerce.openadmin.web.form.entity.CodeField) RuleBuilderField(org.broadleafcommerce.openadmin.web.form.component.RuleBuilderField) Field(org.broadleafcommerce.openadmin.web.form.entity.Field) ComboField(org.broadleafcommerce.openadmin.web.form.entity.ComboField) MediaField(org.broadleafcommerce.openadmin.web.form.component.MediaField) ComboField(org.broadleafcommerce.openadmin.web.form.entity.ComboField) AdminMainEntity(org.broadleafcommerce.common.admin.domain.AdminMainEntity) Entity(org.broadleafcommerce.openadmin.dto.Entity) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) ForeignKey(org.broadleafcommerce.openadmin.dto.ForeignKey) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) Property(org.broadleafcommerce.openadmin.dto.Property)

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