Search in sources :

Example 26 with Field

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;
}
Also used : ListGridAction(org.broadleafcommerce.openadmin.web.form.component.ListGridAction) Locale(org.broadleafcommerce.common.locale.domain.Locale) ComboField(org.broadleafcommerce.openadmin.web.form.entity.ComboField) Field(org.broadleafcommerce.openadmin.web.form.entity.Field) Translation(org.broadleafcommerce.common.i18n.domain.Translation) ListGridRecord(org.broadleafcommerce.openadmin.web.form.component.ListGridRecord) ArrayList(java.util.ArrayList) ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid)

Example 27 with Field

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;
}
Also used : Field(org.broadleafcommerce.openadmin.web.form.entity.Field) ArrayList(java.util.ArrayList) BLCSystemProperty(org.broadleafcommerce.common.util.BLCSystemProperty) Property(org.broadleafcommerce.openadmin.dto.Property)

Example 28 with Field

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;
}
Also used : Field(org.broadleafcommerce.openadmin.web.form.entity.Field) AdminMainEntity(org.broadleafcommerce.common.admin.domain.AdminMainEntity) Entity(org.broadleafcommerce.openadmin.dto.Entity) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) BLCSystemProperty(org.broadleafcommerce.common.util.BLCSystemProperty) Property(org.broadleafcommerce.openadmin.dto.Property)

Example 29 with Field

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);
}
Also used : Field(org.broadleafcommerce.openadmin.web.form.entity.Field) HashMap(java.util.HashMap) ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid) BroadleafAttributeModifier(org.broadleafcommerce.presentation.model.BroadleafAttributeModifier)

Example 30 with Field

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();
    }
}
Also used : MediaField(org.broadleafcommerce.openadmin.web.form.component.MediaField) Field(org.broadleafcommerce.openadmin.web.form.entity.Field) ListGridRecord(org.broadleafcommerce.openadmin.web.form.component.ListGridRecord) MediaField(org.broadleafcommerce.openadmin.web.form.component.MediaField)

Aggregations

Field (org.broadleafcommerce.openadmin.web.form.entity.Field)36 Property (org.broadleafcommerce.openadmin.dto.Property)15 ComboField (org.broadleafcommerce.openadmin.web.form.entity.ComboField)15 MediaField (org.broadleafcommerce.openadmin.web.form.component.MediaField)14 RuleBuilderField (org.broadleafcommerce.openadmin.web.form.component.RuleBuilderField)14 CodeField (org.broadleafcommerce.openadmin.web.form.entity.CodeField)13 ArrayList (java.util.ArrayList)10 EntityForm (org.broadleafcommerce.openadmin.web.form.entity.EntityForm)10 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)9 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)8 Entity (org.broadleafcommerce.openadmin.dto.Entity)8 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)7 ListGrid (org.broadleafcommerce.openadmin.web.form.component.ListGrid)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 HashMap (java.util.HashMap)5 SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)5 Map (java.util.Map)4 AdminMainEntity (org.broadleafcommerce.common.admin.domain.AdminMainEntity)4 Translation (org.broadleafcommerce.common.i18n.domain.Translation)4 DataWrapper (org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper)4