Search in sources :

Example 1 with DynamicEntityFormInfo

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

the class AdminPageController method saveEntity.

@Override
@RequestMapping(value = "/{id}", method = RequestMethod.POST)
public String saveEntity(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value = "id") String id, @ModelAttribute(value = "entityForm") EntityForm entityForm, BindingResult result, RedirectAttributes ra) throws Exception {
    // Attach the dynamic form info so that the update service will know how to split up the fields
    DynamicEntityFormInfo info = new DynamicEntityFormInfo().withCeilingClassName(PageTemplate.class.getName()).withSecurityCeilingClassName(Page.class.getName()).withCriteriaName("constructForm").withPropertyName("pageTemplate");
    entityForm.putDynamicFormInfo("pageTemplate", info);
    String returnPath = super.saveEntity(request, response, model, pathVars, id, entityForm, result, ra);
    if (result.hasErrors()) {
        info = entityForm.getDynamicFormInfo("pageTemplate");
        if (entityForm.getFields().containsKey("pageTemplate")) {
            info.setPropertyValue(entityForm.findField("pageTemplate").getValue());
        }
        // grab back the dynamic form that was actually put in
        EntityForm inputDynamicForm = entityForm.getDynamicForm("pageTemplate");
        if (inputDynamicForm != null) {
            List<Field> fieldsToChange = new ArrayList<Field>();
            String prefix = "pageTemplate" + DynamicEntityFormInfo.FIELD_SEPARATOR;
            for (Entry<String, Field> entry : inputDynamicForm.getFields().entrySet()) {
                if (entry.getKey().startsWith(prefix)) {
                    fieldsToChange.add(entry.getValue());
                }
            }
            for (Field f : fieldsToChange) {
                inputDynamicForm.getFields().remove(f.getName());
                f.setName(f.getName().substring(prefix.length()));
                inputDynamicForm.getFields().put(f.getName(), f);
            }
        }
        EntityForm dynamicForm;
        if (info.getPropertyValue() != null) {
            dynamicForm = getDynamicFieldTemplateForm(info, id, inputDynamicForm);
        } else {
            dynamicForm = getEntityForm(info, inputDynamicForm);
        }
        entityForm.putDynamicForm("pageTemplate", dynamicForm);
        entityForm.removeListGrid("additionalAttributes");
    }
    return returnPath;
}
Also used : EntityForm(org.broadleafcommerce.openadmin.web.form.entity.EntityForm) Field(org.broadleafcommerce.openadmin.web.form.entity.Field) ArrayList(java.util.ArrayList) Page(org.broadleafcommerce.cms.page.domain.Page) DynamicEntityFormInfo(org.broadleafcommerce.openadmin.web.form.entity.DynamicEntityFormInfo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with DynamicEntityFormInfo

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

the class AdminStructuredContentController method saveEntity.

@Override
@RequestMapping(value = "/{id}", method = RequestMethod.POST)
public String saveEntity(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value = "id") String id, @ModelAttribute(value = "entityForm") EntityForm entityForm, BindingResult result, RedirectAttributes ra) throws Exception {
    // Attach the dynamic form info so that the update service will know how to split up the fields
    DynamicEntityFormInfo info = new DynamicEntityFormInfo().withCeilingClassName(StructuredContentType.class.getName()).withSecurityCeilingClassName(StructuredContent.class.getName()).withCriteriaName("constructForm").withPropertyName("structuredContentType");
    entityForm.putDynamicFormInfo("structuredContentType", info);
    String returnPath = super.saveEntity(request, response, model, pathVars, id, entityForm, result, ra);
    if (result.hasErrors()) {
        info = entityForm.getDynamicFormInfo("structuredContentType");
        info.setPropertyValue(entityForm.findField("structuredContentType").getValue());
        // grab back the dynamic form that was actually put in
        EntityForm inputDynamicForm = entityForm.getDynamicForm("structuredContentType");
        EntityForm dynamicForm = getDynamicFieldTemplateForm(info, id, inputDynamicForm);
        entityForm.putDynamicForm("structuredContentType", dynamicForm);
    }
    return returnPath;
}
Also used : EntityForm(org.broadleafcommerce.openadmin.web.form.entity.EntityForm) DynamicEntityFormInfo(org.broadleafcommerce.openadmin.web.form.entity.DynamicEntityFormInfo) StructuredContent(org.broadleafcommerce.cms.structure.domain.StructuredContent) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with DynamicEntityFormInfo

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

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

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

the class AdminPageController 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");
    DynamicEntityFormInfo info = getDynamicForm(ef, id);
    EntityForm dynamicForm;
    if (info.getPropertyValue() != null) {
        dynamicForm = getDynamicFieldTemplateForm(info, id, null);
    } else {
        dynamicForm = getEntityForm(info, null);
    }
    if (dynamicForm.getCeilingEntityClassname().equals(PageTemplate.class.getName())) {
        dynamicForm.setTranslationCeilingEntity(Page.class.getName());
        dynamicForm.setTranslationId(id);
    }
    ef.putDynamicFormInfo("pageTemplate", info);
    ef.putDynamicForm("pageTemplate", dynamicForm);
    // Mark the field that will drive this dynamic form
    addOnChangeTrigger(ef);
    ef.removeListGrid("additionalAttributes");
    return returnPath;
}
Also used : EntityForm(org.broadleafcommerce.openadmin.web.form.entity.EntityForm) PageTemplate(org.broadleafcommerce.cms.page.domain.PageTemplate) Page(org.broadleafcommerce.cms.page.domain.Page) DynamicEntityFormInfo(org.broadleafcommerce.openadmin.web.form.entity.DynamicEntityFormInfo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DynamicEntityFormInfo (org.broadleafcommerce.openadmin.web.form.entity.DynamicEntityFormInfo)7 EntityForm (org.broadleafcommerce.openadmin.web.form.entity.EntityForm)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 Page (org.broadleafcommerce.cms.page.domain.Page)2 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)2 Field (org.broadleafcommerce.openadmin.web.form.entity.Field)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 PageTemplate (org.broadleafcommerce.cms.page.domain.PageTemplate)1 StructuredContent (org.broadleafcommerce.cms.structure.domain.StructuredContent)1 StructuredContentType (org.broadleafcommerce.cms.structure.domain.StructuredContentType)1