use of org.broadleafcommerce.openadmin.web.form.entity.Field in project BroadleafCommerce by BroadleafCommerce.
the class TranslationFormBuilderServiceImpl method buildListGrid.
@Override
public ListGrid buildListGrid(List<Translation> translations, boolean isRte) {
// Set up the two header fields we're interested in for the translations list grid
List<Field> headerFields = new ArrayList<Field>();
headerFields.add(new Field().withName("localeCode").withFriendlyName("Translation_localeCode").withOrder(0));
headerFields.add(new Field().withName("translatedValue").withFriendlyName("Translation_translatedValue").withOrder(10));
// Create the list grid and set its basic properties
ListGrid listGrid = new ListGrid();
listGrid.getHeaderFields().addAll(headerFields);
listGrid.setListGridType(ListGrid.Type.TRANSLATION);
listGrid.setSelectType(ListGrid.SelectType.SINGLE_SELECT);
listGrid.setCanFilterAndSort(false);
// Allow add/update/remove actions, but provisioned especially for translation. Because of this, we will clone
// the default actions so that we may change the class
ListGridAction addAction = DefaultListGridActions.ADD.clone();
ListGridAction removeAction = DefaultListGridActions.REMOVE.clone();
ListGridAction updateAction = DefaultListGridActions.UPDATE.clone();
addAction.setButtonClass("translation-grid-add");
removeAction.setButtonClass("translation-grid-remove");
updateAction.setButtonClass("translation-grid-update");
listGrid.addToolbarAction(addAction);
listGrid.addRowAction(updateAction);
listGrid.addRowAction(removeAction);
// TODO rework code elsewhere so these don't have to be added
listGrid.setSectionKey(Translation.class.getCanonicalName());
listGrid.setSubCollectionFieldName("translation");
// Create records for each of the entries in the translations list
for (Translation t : translations) {
ListGridRecord record = new ListGridRecord();
record.setListGrid(listGrid);
record.setId(String.valueOf(t.getId()));
Locale locale = localeService.findLocaleByCode(t.getLocaleCode());
record.getFields().add(new Field().withName("localeCode").withFriendlyName("Translation_localeCode").withOrder(0).withValue(locale.getLocaleCode()).withDisplayValue(locale.getFriendlyName()));
record.getFields().add(new Field().withName("translatedValue").withFriendlyName("Translation_translatedValue").withOrder(10).withValue(t.getTranslatedValue()).withDisplayValue(isRte ? getLocalizedEditToViewMessage() : t.getTranslatedValue()));
listGrid.getRecords().add(record);
}
listGrid.setTotalRecords(listGrid.getRecords().size());
return listGrid;
}
use of org.broadleafcommerce.openadmin.web.form.entity.Field in project BroadleafCommerce by BroadleafCommerce.
the class AdminEntityServiceImpl method getPropertiesFromEntityForm.
protected List<Property> getPropertiesFromEntityForm(EntityForm entityForm) {
List<Property> properties = new ArrayList<Property>(entityForm.getFields().size());
for (Entry<String, Field> entry : entityForm.getFields().entrySet()) {
Property p = new Property();
p.setName(entry.getKey());
p.setValue(entry.getValue().getValue());
p.setDisplayValue(entry.getValue().getDisplayValue());
p.setIsDirty(entry.getValue().getIsDirty());
properties.add(p);
}
return properties;
}
use of org.broadleafcommerce.openadmin.web.form.entity.Field in project BroadleafCommerce by BroadleafCommerce.
the class AdminEntityServiceImpl method getRequestForEntityForm.
public PersistencePackageRequest getRequestForEntityForm(EntityForm entityForm, String[] customCriteria, List<SectionCrumb> sectionCrumbs) {
// Ensure the ID property is on the form
Field idField = entityForm.findField(entityForm.getIdProperty());
if (idField == null) {
idField = new Field();
idField.setName(entityForm.getIdProperty());
idField.setValue(entityForm.getId());
entityForm.getFields().put(entityForm.getIdProperty(), idField);
} else {
idField.setValue(entityForm.getId());
}
List<Property> propList = getPropertiesFromEntityForm(entityForm);
Property[] properties = new Property[propList.size()];
properties = propList.toArray(properties);
Entity entity = new Entity();
entity.setProperties(properties);
String entityType = entityForm.getEntityType();
if (StringUtils.isEmpty(entityType)) {
entityType = entityForm.getCeilingEntityClassname();
}
entity.setType(new String[] { entityType });
PersistencePackageRequest ppr = PersistencePackageRequest.standard().withEntity(entity).withCustomCriteria(customCriteria).withCeilingEntityClassname(entityForm.getCeilingEntityClassname()).withSectionCrumbs(sectionCrumbs).withRequestingEntityName(entityForm.getMainEntityName());
return ppr;
}
use of org.broadleafcommerce.openadmin.web.form.entity.Field in project BroadleafCommerce by BroadleafCommerce.
the class AdminComponentIdProcessor method getModifiedAttributes.
@Override
public BroadleafAttributeModifier getModifiedAttributes(String tagName, Map<String, String> tagAttributes, String attributeName, String attributeValue, BroadleafTemplateContext context) {
Object component = context.parseExpression(attributeValue);
String fieldName = "";
String id = "";
if (component instanceof ListGrid) {
ListGrid lg = (ListGrid) component;
fieldName = "listGrid-" + lg.getListGridType();
if (StringUtils.isNotBlank(lg.getSubCollectionFieldName())) {
fieldName += "-" + lg.getSubCollectionFieldName();
}
} else if (component instanceof Field) {
Field field = (Field) component;
fieldName = "field-" + field.getName();
}
if (StringUtils.isNotBlank(fieldName)) {
id = cleanCssIdString(fieldName);
}
Map<String, String> attrs = new HashMap<>();
attrs.put("id", id);
return new BroadleafAttributeModifier(attrs);
}
use of org.broadleafcommerce.openadmin.web.form.entity.Field in project BroadleafCommerce by BroadleafCommerce.
the class AssetFormBuilderServiceImpl method addImageThumbnailField.
@Override
public void addImageThumbnailField(ListGrid listGrid, String urlField) {
listGrid.getHeaderFields().add(new Field().withName("thumbnail").withFriendlyName("Asset_thumbnail").withFieldType(SupportedFieldType.STRING.toString()).withOrder(Integer.MIN_VALUE).withColumnWidth("50px").withFilterSortDisabled(true));
for (ListGridRecord record : listGrid.getRecords()) {
// Get the value of the URL
String imageUrl = record.getField(urlField).getValue();
// Prepend the static asset url prefix if necessary
String staticAssetUrlPrefix = staticAssetService.getStaticAssetUrlPrefix();
if (staticAssetUrlPrefix != null && !staticAssetUrlPrefix.startsWith("/")) {
staticAssetUrlPrefix = "/" + staticAssetUrlPrefix;
}
if (staticAssetUrlPrefix == null) {
staticAssetUrlPrefix = "";
} else {
imageUrl = staticAssetUrlPrefix + imageUrl;
}
MediaField mf = (MediaField) new MediaField().withName("thumbnail").withFriendlyName("Asset_thumbnail").withFieldType(SupportedFieldType.IMAGE.toString()).withOrder(Integer.MIN_VALUE).withValue(imageUrl);
// Add a hidden field for the large thumbnail path
record.getHiddenFields().add(new Field().withName("cmsUrlPrefix").withValue(staticAssetUrlPrefix));
record.getHiddenFields().add(new Field().withName("thumbnailKey").withValue("?smallAdminThumbnail"));
record.getHiddenFields().add(new Field().withName("servletContext").withValue(BroadleafRequestContext.getBroadleafRequestContext().getRequest().getContextPath()));
// Set the height value on this field
mf.setHeight(operationMap.getNamedOperations().get("smallAdminThumbnail").get("resize-height-amount"));
record.getFields().add(mf);
// Since we've added a new field, we need to clear the cached map to ensure it will display
record.clearFieldMap();
}
}
Aggregations