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