Search in sources :

Example 1 with ListGridAction

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

the class AdminProductController 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 {
    String view = super.viewEntityForm(request, response, model, pathVars, id);
    // Skus have a specific toolbar action to generate Skus based on permutations
    EntityForm form = (EntityForm) model.asMap().get("entityForm");
    ListGridAction generateSkusAction = new ListGridAction(ListGridAction.GEN_SKUS).withDisplayText("Generate_Skus").withIconClass("icon-fighter-jet").withButtonClass("generate-skus").withUrlPostfix("/generate-skus").withActionUrlOverride("/product/" + id + "/additionalSkus/generate-skus");
    ListGrid skusGrid = form.findListGrid("additionalSkus");
    if (skusGrid != null) {
        skusGrid.setCanFilterAndSort(false);
    }
    ListGrid productOptionsGrid = form.findListGrid("productOptions");
    if (productOptionsGrid != null) {
        productOptionsGrid.addToolbarAction(generateSkusAction);
    }
    // list grids. Remove them from the form.
    if (ProductBundle.class.isAssignableFrom(Class.forName(form.getEntityType()))) {
        form.removeListGrid("additionalSkus");
        form.removeListGrid("productOptions");
        form.removeField("canSellWithoutOptions");
    }
    form.removeListGrid("defaultSku.skuAttributes");
    return view;
}
Also used : ListGridAction(org.broadleafcommerce.openadmin.web.form.component.ListGridAction) EntityForm(org.broadleafcommerce.openadmin.web.form.entity.EntityForm) ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ListGridAction

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

the class FormBuilderServiceImpl method populateEntityForm.

@Override
public void populateEntityForm(ClassMetadata cmd, Entity entity, Map<String, DynamicResultSet> collectionRecords, EntityForm ef, List<SectionCrumb> sectionCrumbs) throws ServiceException {
    // Get the form with values for this entity
    populateEntityForm(cmd, entity, ef, sectionCrumbs);
    // Attach the sub-collection list grids and specialty UI support
    for (Property p : cmd.getProperties()) {
        if (p.getMetadata() instanceof BasicFieldMetadata) {
            continue;
        }
        if (!ArrayUtils.contains(p.getMetadata().getAvailableToTypes(), entity.getType()[0])) {
            continue;
        }
        if (collectionRecords != null) {
            DynamicResultSet subCollectionEntities = collectionRecords.get(p.getName());
            String containingEntityId = entity.getPMap().get(ef.getIdProperty()).getValue();
            ListGrid listGrid = buildCollectionListGrid(containingEntityId, subCollectionEntities, p, ef.getSectionKey(), sectionCrumbs);
            CollectionMetadata md = ((CollectionMetadata) p.getMetadata());
            if (md instanceof BasicCollectionMetadata) {
                PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(md, sectionCrumbs);
                ClassMetadata collectionCmd = adminEntityService.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
                if (collectionCmd.getPolymorphicEntities().getChildren().length != 0) {
                    List<ClassTree> entityTypes = collectionCmd.getPolymorphicEntities().getCollapsedClassTrees();
                    ListGridActionGroup actionGroup = new ListGridActionGroup().withName("Add");
                    for (ClassTree entityType : entityTypes) {
                        ListGridAction ADD = new ListGridAction(ListGridAction.ADD).withButtonClass(AddMethodType.PERSIST_EMPTY == ((BasicCollectionMetadata) md).getAddMethodType() ? "sub-list-grid-add-empty" : "sub-list-grid-add").withActionTargetEntity(entityType.getFullyQualifiedClassname()).withUrlPostfix("/add").withIconClass("fa fa-plus").withDisplayText(BLCMessageUtils.getMessage(entityType.getFriendlyName()));
                        actionGroup.getListGridActions().add(0, ADD);
                    }
                    listGrid.addToolbarActionGroup(actionGroup);
                } else {
                    listGrid.getToolbarActions().add(0, AddMethodType.PERSIST_EMPTY == ((BasicCollectionMetadata) md).getAddMethodType() ? DefaultListGridActions.ADD_EMPTY : DefaultListGridActions.ADD);
                }
            } else {
                listGrid.getToolbarActions().add(0, DefaultListGridActions.ADD);
            }
            if (subCollectionEntities.getUnselectedTabMetadata().get(md.getTab()) != null) {
                ef.addListGrid(cmd, listGrid, md.getTab(), md.getTabOrder(), md.getGroup(), true);
            } else {
                ef.addListGrid(cmd, listGrid, md.getTab(), md.getTabOrder(), md.getGroup(), false);
            }
        }
    }
    if (CollectionUtils.isEmpty(ef.getActions())) {
        ef.addAction(DefaultEntityFormActions.SAVE);
    }
    addDeleteActionIfAllowed(ef, cmd, entity);
    setReadOnlyState(ef, cmd, entity);
    // check for fields that should be hidden based on annotations
    setVisibilityBasedOnShowIfFieldEquals(cmd, entity, ef);
    extensionManager.getProxy().modifyDetailEntityForm(ef);
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) ListGridAction(org.broadleafcommerce.openadmin.web.form.component.ListGridAction) BasicCollectionMetadata(org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata) AdornedTargetCollectionMetadata(org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata) CollectionMetadata(org.broadleafcommerce.openadmin.dto.CollectionMetadata) ClassTree(org.broadleafcommerce.openadmin.dto.ClassTree) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) ListGridActionGroup(org.broadleafcommerce.openadmin.web.form.component.ListGridActionGroup) ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) BasicCollectionMetadata(org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata) Property(org.broadleafcommerce.openadmin.dto.Property) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet)

Example 3 with ListGridAction

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

Aggregations

ListGrid (org.broadleafcommerce.openadmin.web.form.component.ListGrid)3 ListGridAction (org.broadleafcommerce.openadmin.web.form.component.ListGridAction)3 ArrayList (java.util.ArrayList)1 Translation (org.broadleafcommerce.common.i18n.domain.Translation)1 Locale (org.broadleafcommerce.common.locale.domain.Locale)1 AdornedTargetCollectionMetadata (org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)1 BasicCollectionMetadata (org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata)1 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)1 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)1 ClassTree (org.broadleafcommerce.openadmin.dto.ClassTree)1 CollectionMetadata (org.broadleafcommerce.openadmin.dto.CollectionMetadata)1 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)1 Property (org.broadleafcommerce.openadmin.dto.Property)1 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)1 ListGridActionGroup (org.broadleafcommerce.openadmin.web.form.component.ListGridActionGroup)1 ListGridRecord (org.broadleafcommerce.openadmin.web.form.component.ListGridRecord)1 ComboField (org.broadleafcommerce.openadmin.web.form.entity.ComboField)1 EntityForm (org.broadleafcommerce.openadmin.web.form.entity.EntityForm)1 Field (org.broadleafcommerce.openadmin.web.form.entity.Field)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1