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);
}
}
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);
}
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);
}
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;
}
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";
}
Aggregations