Search in sources :

Example 16 with ListGrid

use of org.broadleafcommerce.openadmin.web.form.component.ListGrid in project BroadleafCommerce by BroadleafCommerce.

the class AdminOrderController method showViewUpdateCollection.

@Override
protected String showViewUpdateCollection(HttpServletRequest request, Model model, Map<String, String> pathVars, String id, String collectionField, String collectionItemId, String modalHeaderType) throws ServiceException {
    String returnPath = super.showViewUpdateCollection(request, model, pathVars, id, collectionField, collectionItemId, modalHeaderType);
    if ("orderItems".equals(collectionField)) {
        EntityForm ef = (EntityForm) model.asMap().get("entityForm");
        ListGrid adjustmentsGrid = ef.findListGrid("orderItemAdjustments");
        if (adjustmentsGrid != null && CollectionUtils.isEmpty(adjustmentsGrid.getRecords())) {
            ef.removeListGrid("orderItemAdjustments");
        }
        ListGrid priceDetailsGrid = ef.findListGrid("orderItemPriceDetails");
        if (priceDetailsGrid != null && CollectionUtils.isEmpty(priceDetailsGrid.getRecords())) {
            ef.removeListGrid("orderItemPriceDetails");
        }
    }
    return returnPath;
}
Also used : EntityForm(org.broadleafcommerce.openadmin.web.form.entity.EntityForm) ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid)

Example 17 with ListGrid

use of org.broadleafcommerce.openadmin.web.form.component.ListGrid in project BroadleafCommerce by BroadleafCommerce.

the class AdminBasicEntityController method buildAddCollectionItemModel.

/**
 * Builds out all of the model information needed for showing the add modal for collection items on both the initial GET
 * as well as after a POST with validation errors
 *
 * @param request
 * @param model
 * @param id
 * @param collectionField
 * @param sectionKey
 * @param collectionProperty
 * @param md
 * @param ppr
 * @return the appropriate view to display for the modal
 * @see {@link #addCollectionItem(HttpServletRequest, HttpServletResponse, Model, Map, String, String, EntityForm, BindingResult)}
 * @see {@link #showAddCollectionItem(HttpServletRequest, HttpServletResponse, Model, Map, String, String, MultiValueMap)}
 * @throws ServiceException
 */
protected String buildAddCollectionItemModel(HttpServletRequest request, HttpServletResponse response, Model model, String id, String collectionField, String sectionKey, Property collectionProperty, FieldMetadata md, PersistencePackageRequest ppr, EntityForm entityForm, Entity entity) throws ServiceException {
    // For requests to add a new collection item include the main class that the subsequent request comes from.
    // For instance, with basic collections we know the main associated class for a fetch through the ForeignKey
    // persistence item but map and adorned target lookups make a standard persistence request. This solution
    // fixes all cases.
    String mainClassName = getClassNameForSection(sectionKey);
    ppr.addCustomCriteria("owningClass=" + mainClassName);
    ppr.setAddOperationInspect(true);
    if (entityForm != null) {
        entityForm.clearFieldsMap();
    }
    List<SectionCrumb> sectionCrumbs = getSectionCrumbs(request, sectionKey, id);
    if (md instanceof BasicCollectionMetadata) {
        BasicCollectionMetadata fmd = (BasicCollectionMetadata) md;
        // and sometimes show a list grid to allow the user to associate an existing record.
        if (fmd.getAddMethodType().equals(AddMethodType.PERSIST)) {
            ClassMetadata collectionMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
            if (entityForm == null) {
                entityForm = formService.createEntityForm(collectionMetadata, sectionCrumbs);
                entityForm.setCeilingEntityClassname(ppr.getCeilingEntityClassname());
                entityForm.setEntityType(ppr.getCeilingEntityClassname());
            } else {
                formService.populateEntityForm(collectionMetadata, entityForm, sectionCrumbs);
                formService.populateEntityFormFieldValues(collectionMetadata, entity, entityForm);
            }
            formService.removeNonApplicableFields(collectionMetadata, entityForm, ppr.getCeilingEntityClassname());
            entityForm.getTabs().iterator().next().getIsVisible();
            model.addAttribute("entityForm", entityForm);
            model.addAttribute("viewType", "modal/simpleAddEntity");
        } else {
            DynamicResultSet drs = service.getRecords(ppr).getDynamicResultSet();
            ListGrid listGrid = formService.buildCollectionListGrid(id, drs, collectionProperty, sectionKey, sectionCrumbs);
            listGrid.setPathOverride(request.getRequestURL().toString());
            if (AddMethodType.LOOKUP.equals(fmd.getAddMethodType()) || AddMethodType.SELECTIZE_LOOKUP.equals(fmd.getAddMethodType())) {
                listGrid.removeAllRowActions();
            }
            model.addAttribute("listGrid", listGrid);
            model.addAttribute("viewType", "modal/simpleSelectEntity");
        }
    } else if (md instanceof AdornedTargetCollectionMetadata) {
        AdornedTargetCollectionMetadata fmd = (AdornedTargetCollectionMetadata) md;
        // Even though this field represents an adorned target collection, the list we want to show in the modal
        // is the standard list grid for the target entity of this field
        ppr.setOperationTypesOverride(null);
        ppr.setType(PersistencePackageRequest.Type.STANDARD);
        ppr.setSectionEntityField(collectionField);
        ClassMetadata collectionMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
        DynamicResultSet drs = service.getRecords(ppr).getDynamicResultSet();
        ListGrid listGrid = formService.buildCollectionListGrid(id, drs, collectionProperty, sectionKey, sectionCrumbs);
        listGrid.setSubCollectionFieldName(collectionField);
        listGrid.setPathOverride(request.getRequestURL().toString());
        listGrid.setFriendlyName(collectionMetadata.getPolymorphicEntities().getFriendlyName());
        if (entityForm == null) {
            entityForm = formService.buildAdornedListForm(fmd, ppr.getAdornedList(), id, false, sectionCrumbs, true);
            entityForm.setCeilingEntityClassname(ppr.getAdornedList().getAdornedTargetEntityClassname());
        } else {
            formService.buildAdornedListForm(fmd, ppr.getAdornedList(), id, false, entityForm, sectionCrumbs, true);
            formService.populateEntityFormFieldValues(collectionMetadata, entity, entityForm);
        }
        listGrid.setListGridType(ListGrid.Type.ADORNED);
        for (Entry<String, Field> entry : entityForm.getFields().entrySet()) {
            if (entry.getValue().getIsVisible()) {
                listGrid.setListGridType(ListGrid.Type.ADORNED_WITH_FORM);
                break;
            }
        }
        // This is part of an add, so we want to be able to filter/sort the listgrid
        listGrid.setIsSortable(false);
        listGrid.setCanFilterAndSort(true);
        listGrid.removeAllRowActions();
        model.addAttribute("listGrid", listGrid);
        model.addAttribute("entityForm", entityForm);
        model.addAttribute("viewType", "modal/adornedSelectEntity");
    } else if (md instanceof MapMetadata) {
        MapMetadata fmd = (MapMetadata) md;
        ClassMetadata collectionMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
        if (entityForm == null) {
            entityForm = formService.buildMapForm(fmd, ppr.getMapStructure(), collectionMetadata, id);
        } else {
            formService.buildMapForm(fmd, ppr.getMapStructure(), collectionMetadata, id, entityForm);
            formService.populateEntityFormFieldValues(collectionMetadata, entity, entityForm);
        }
        model.addAttribute("entityForm", entityForm);
        model.addAttribute("viewType", "modal/mapAddEntity");
    }
    // Set the parent id on the entity form
    if (entityForm != null) {
        entityForm.setParentId(id);
    }
    model.addAttribute("currentUrl", request.getRequestURL().toString());
    model.addAttribute("modalHeaderType", ModalHeaderType.ADD_COLLECTION_ITEM.getType());
    model.addAttribute("collectionProperty", collectionProperty);
    setModelAttributes(model, sectionKey);
    return "modules/modalContainer";
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) Entry(java.util.Map.Entry) BasicCollectionMetadata(org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid) MapMetadata(org.broadleafcommerce.openadmin.dto.MapMetadata) AdornedTargetCollectionMetadata(org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)

Example 18 with ListGrid

use of org.broadleafcommerce.openadmin.web.form.component.ListGrid 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 19 with ListGrid

use of org.broadleafcommerce.openadmin.web.form.component.ListGrid in project BroadleafCommerce by BroadleafCommerce.

the class EntityForm method removeListGrid.

public ListGrid removeListGrid(String subCollectionFieldName) {
    ListGrid lgToRemove = null;
    Tab containingTab = null;
    FieldGroup containingGroup = null;
    findLg: {
        for (Tab tab : tabs) {
            for (ListGrid lg : tab.getListGrids()) {
                if (subCollectionFieldName.equals(lg.getSubCollectionFieldName())) {
                    lgToRemove = lg;
                    containingTab = tab;
                    break findLg;
                }
            }
            for (FieldGroup group : tab.getFieldGroups()) {
                for (ListGrid lg : group.getListGrids()) {
                    if (subCollectionFieldName.equals(lg.getSubCollectionFieldName())) {
                        lgToRemove = lg;
                        containingTab = tab;
                        containingGroup = group;
                        break findLg;
                    }
                }
            }
        }
    }
    if (lgToRemove != null && containingGroup != null) {
        containingGroup.removeListGrid(lgToRemove);
    } else if (lgToRemove != null && containingGroup == null) {
        containingTab.removeListGrid(lgToRemove);
    }
    if (containingGroup != null && containingGroup.getGroupItems().isEmpty()) {
        removeGroup(containingGroup);
    } else if (containingTab != null && containingTab.getListGrids().isEmpty() && containingTab.getFields().isEmpty()) {
        removeTab(containingTab);
    }
    return lgToRemove;
}
Also used : ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid)

Example 20 with ListGrid

use of org.broadleafcommerce.openadmin.web.form.component.ListGrid 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)

Aggregations

ListGrid (org.broadleafcommerce.openadmin.web.form.component.ListGrid)23 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)11 Property (org.broadleafcommerce.openadmin.dto.Property)11 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)10 SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)7 Entity (org.broadleafcommerce.openadmin.dto.Entity)7 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)6 Field (org.broadleafcommerce.openadmin.web.form.entity.Field)6 BasicCollectionMetadata (org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata)5 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)5 AdornedTargetCollectionMetadata (org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)4 ComboField (org.broadleafcommerce.openadmin.web.form.entity.ComboField)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 PersistenceResponse (org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse)3 ListGridAction (org.broadleafcommerce.openadmin.web.form.component.ListGridAction)3 MediaField (org.broadleafcommerce.openadmin.web.form.component.MediaField)3