use of org.broadleafcommerce.openadmin.web.form.entity.EntityForm in project BroadleafCommerce by BroadleafCommerce.
the class TranslationFormBuilderServiceImpl method buildTranslationForm.
@Override
public EntityForm buildTranslationForm(ClassMetadata cmd, TranslationForm formProperties, TranslationFormAction action) {
EntityForm ef = new EntityForm();
EntityFormAction saveAction = DefaultEntityFormActions.SAVE.clone();
saveAction.setButtonClass("translation-submit-button");
ef.addAction(saveAction);
ComboField comboField = getLocaleField(formProperties.getLocaleCode());
ef.addField(cmd, comboField);
Field translatedValueValueField = new Field().withName("translatedValue").withFieldType(formProperties.getIsRte() ? "html" : "string").withFriendlyName("Translation_translatedValue").withValue(formProperties.getTranslatedValue()).withOrder(10);
ef.addField(cmd, translatedValueValueField);
if (action.equals(TranslationFormAction.UPDATE)) {
comboField.setReadOnly(true);
}
ef.addHiddenField(cmd, new Field().withName("ceilingEntity").withValue(formProperties.getCeilingEntity()));
ef.addHiddenField(cmd, new Field().withName("entityId").withValue(formProperties.getEntityId()));
ef.addHiddenField(cmd, new Field().withName("propertyName").withValue(formProperties.getPropertyName()));
ef.addHiddenField(cmd, new Field().withName("isRte").withValue(String.valueOf(formProperties.getIsRte())));
return ef;
}
use of org.broadleafcommerce.openadmin.web.form.entity.EntityForm 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;
}
use of org.broadleafcommerce.openadmin.web.form.entity.EntityForm in project BroadleafCommerce by BroadleafCommerce.
the class AdminStructuredContentController 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");
// Attach the dynamic fields to the form
DynamicEntityFormInfo info = new DynamicEntityFormInfo().withCeilingClassName(StructuredContentType.class.getName()).withSecurityCeilingClassName(StructuredContent.class.getName()).withCriteriaName("constructForm").withPropertyName("structuredContentType").withPropertyValue(ef.findField("structuredContentType").getValue());
EntityForm dynamicForm = getDynamicFieldTemplateForm(info, id, null);
ef.putDynamicFormInfo("structuredContentType", info);
ef.putDynamicForm("structuredContentType", dynamicForm);
// We don't want to allow changing types once a structured content item exists
ef.findField("structuredContentType").setReadOnly(true);
return returnPath;
}
use of org.broadleafcommerce.openadmin.web.form.entity.EntityForm 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.EntityForm in project BroadleafCommerce by BroadleafCommerce.
the class AdminBasicEntityController method viewEntityForm.
/**
* Renders the main entity form for the specified entity
*
* @param request
* @param response
* @param model
* @param pathVars
* @param id
* @return the return view path
* @throws Exception
*/
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String viewEntityForm(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable("id") String id) throws Exception {
String sectionKey = getSectionKey(pathVars);
String sectionClassName = getClassNameForSection(sectionKey);
List<SectionCrumb> crumbs = getSectionCrumbs(request, sectionKey, id);
PersistencePackageRequest ppr = getSectionPersistencePackageRequest(sectionClassName, crumbs, pathVars);
ClassMetadata cmd = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
Entity entity = service.getRecord(ppr, id, cmd, false).getDynamicResultSet().getRecords()[0];
Map<String, DynamicResultSet> subRecordsMap = getViewSubRecords(request, pathVars, cmd, entity, crumbs);
EntityForm entityForm = formService.createEntityForm(cmd, entity, subRecordsMap, crumbs);
if (isAddRequest(entity)) {
modifyAddEntityForm(entityForm, pathVars);
} else {
modifyEntityForm(entityForm, pathVars);
}
if (request.getParameter("headerFlash") != null) {
model.addAttribute("headerFlash", request.getParameter("headerFlash"));
}
// Set the sectionKey again incase this is a typed entity
entityForm.setSectionKey(sectionKey);
// Build the current url in the cast that this is a typed entity
String originatingUri = new UrlPathHelper().getOriginatingRequestUri(request);
int startIndex = request.getContextPath().length();
// Remove the context path from servlet path
String currentUrl = originatingUri.substring(startIndex);
model.addAttribute("entity", entity);
model.addAttribute("entityForm", entityForm);
model.addAttribute("currentUrl", currentUrl);
setModelAttributes(model, sectionKey);
// We want to replace author ids with their names
addAuditableDisplayFields(entityForm);
if (isAjaxRequest(request)) {
entityForm.setReadOnly();
model.addAttribute("viewType", "modal/entityView");
model.addAttribute("modalHeaderType", ModalHeaderType.VIEW_ENTITY.getType());
return "modules/modalContainer";
} else {
model.addAttribute("useAjaxUpdate", true);
model.addAttribute("viewType", "entityEdit");
return "modules/defaultContainer";
}
}
Aggregations