Search in sources :

Example 1 with ListGrid

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

the class AdminAssetUploadController method chooseMediaForMapKey.

@RequestMapping(value = "/{id}/chooseAsset", method = RequestMethod.GET)
public String chooseMediaForMapKey(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable(value = "sectionKey") String sectionKey, @PathVariable(value = "id") String id, @RequestParam MultiValueMap<String, String> requestParams) throws Exception {
    Map<String, String> pathVars = new HashMap<String, String>();
    pathVars.put("sectionKey", AdminAssetController.SECTION_KEY);
    assetController.viewEntityList(request, response, model, pathVars, requestParams);
    ListGrid listGrid = (ListGrid) model.asMap().get("listGrid");
    listGrid.setPathOverride("/" + sectionKey + "/" + id + "/chooseAsset");
    listGrid.setListGridType(Type.ASSET);
    listGrid.setSelectType(ListGrid.SelectType.SINGLE_SELECT);
    String userAgent = request.getHeader("User-Agent");
    model.addAttribute("isIE", userAgent.contains("MSIE"));
    model.addAttribute("viewType", "modal/selectAsset");
    model.addAttribute("currentUrl", request.getRequestURL().toString());
    model.addAttribute("modalHeaderType", ModalHeaderType.SELECT_ASSET.getType());
    model.addAttribute("currentParams", new ObjectMapper().writeValueAsString(requestParams));
    // We need these attributes to be set appropriately here
    model.addAttribute("entityId", id);
    model.addAttribute("sectionKey", sectionKey);
    return "modules/modalContainer";
}
Also used : HashMap(java.util.HashMap) ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ListGrid

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

the class AdminProductController method showUpdateAdditionalSku.

protected String showUpdateAdditionalSku(HttpServletRequest request, Model model, String id, String collectionItemId, Map<String, String> pathVars, EntityForm entityForm) throws Exception {
    String collectionField = "additionalSkus";
    // Find out metadata for the additionalSkus property
    String mainClassName = getClassNameForSection(SECTION_KEY);
    List<SectionCrumb> sectionCrumbs = getSectionCrumbs(request, SECTION_KEY, id);
    ClassMetadata mainMetadata = service.getClassMetadata(getSectionPersistencePackageRequest(mainClassName, sectionCrumbs, pathVars)).getDynamicResultSet().getClassMetaData();
    Property collectionProperty = mainMetadata.getPMap().get(collectionField);
    FieldMetadata md = collectionProperty.getMetadata();
    // Find the metadata and the entity for the selected sku
    PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(md, sectionCrumbs).withCustomCriteria(new String[] { id });
    ClassMetadata collectionMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
    if (collectionMetadata.getCeilingType().equals(SkuImpl.class.getName())) {
        collectionMetadata.setCeilingType(Sku.class.getName());
    }
    Entity entity = service.getRecord(ppr, collectionItemId, collectionMetadata, true).getDynamicResultSet().getRecords()[0];
    String currentTabName = getCurrentTabName(pathVars, collectionMetadata);
    Map<String, DynamicResultSet> subRecordsMap = service.getRecordsForSelectedTab(collectionMetadata, entity, sectionCrumbs, currentTabName);
    if (entityForm == null) {
        entityForm = formService.createEntityForm(collectionMetadata, entity, subRecordsMap, sectionCrumbs);
    } else {
        entityForm.clearFieldsMap();
        formService.populateEntityForm(collectionMetadata, entity, subRecordsMap, entityForm, sectionCrumbs);
        // remove all the actions since we're not trying to redisplay them on the form
        entityForm.removeAllActions();
    }
    entityForm.removeAction(DefaultEntityFormActions.DELETE);
    // Ensure that operations on the Sku subcollections go to the proper URL
    for (ListGrid lg : entityForm.getAllListGrids()) {
        lg.setSectionKey("org.broadleafcommerce.core.catalog.domain.Sku");
        lg.setSectionCrumbs(sectionCrumbs);
    }
    model.addAttribute("entityForm", entityForm);
    model.addAttribute("viewType", "modal/simpleEditEntity");
    model.addAttribute("currentUrl", request.getRequestURL().toString());
    model.addAttribute("modalHeaderType", ModalHeaderType.UPDATE_COLLECTION_ITEM.getType());
    model.addAttribute("collectionProperty", collectionProperty);
    setModelAttributes(model, SECTION_KEY);
    return "modules/modalContainer";
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid) SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) Sku(org.broadleafcommerce.core.catalog.domain.Sku) Property(org.broadleafcommerce.openadmin.dto.Property) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet)

Example 3 with ListGrid

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

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

the class AdminBasicEntityController method getCollectionFieldRecords.

/**
 * Returns the records for a given collectionField filtered by a particular criteria
 *
 * @param request
 * @param response
 * @param model
 * @param pathVars
 * @param collectionField
 * @param requestParams
 * @return the return view path
 * @throws Exception
 */
@RequestMapping(value = "/{id}/{collectionField:.*}", method = RequestMethod.GET)
public String getCollectionFieldRecords(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value = "id") String id, @PathVariable(value = "collectionField") String collectionField, @RequestParam MultiValueMap<String, String> requestParams) throws Exception {
    String sectionKey = getSectionKey(pathVars);
    String mainClassName = getClassNameForSection(sectionKey);
    List<SectionCrumb> sectionCrumbs = getSectionCrumbs(request, sectionKey, id);
    PersistencePackageRequest ppr = getSectionPersistencePackageRequest(mainClassName, requestParams, sectionCrumbs, pathVars);
    ClassMetadata mainMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
    Property collectionProperty = mainMetadata.getPMap().get(collectionField);
    ppr = getSectionPersistencePackageRequest(mainClassName, sectionCrumbs, pathVars);
    Entity entity = service.getRecord(ppr, id, mainMetadata, false).getDynamicResultSet().getRecords()[0];
    // Next, we must get the new list grid that represents this collection
    ListGrid listGrid = getCollectionListGrid(mainMetadata, entity, collectionProperty, requestParams, sectionKey, sectionCrumbs);
    model.addAttribute("listGrid", listGrid);
    model.addAttribute("currentParams", new ObjectMapper().writeValueAsString(requestParams));
    // We return the new list grid so that it can replace the currently visible one
    setModelAttributes(model, sectionKey);
    return "views/standaloneListGrid";
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) Entity(org.broadleafcommerce.openadmin.dto.Entity) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) Property(org.broadleafcommerce.openadmin.dto.Property) ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with ListGrid

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

the class AdminBasicEntityController method updateCollectionItem.

/**
 * Updates the specified collection item
 *
 * @param request
 * @param response
 * @param model
 * @param pathVars
 * @param id
 * @param collectionField
 * @param collectionItemId the collection primary key value (in the case of adorned target collection, this is the primary key value of the target entity)
 * @param entityForm
 * @param alternateId in the case of adorned target collections, this is the primary key value of the collection member
 * @param result
 * @return the return view path
 * @throws Exception
 */
@RequestMapping(value = "/{id}/{collectionField:.*}/{collectionItemId}/{alternateId}", method = RequestMethod.POST)
public String updateCollectionItem(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, @ModelAttribute(value = "entityForm") EntityForm entityForm, @PathVariable(value = "alternateId") String alternateId, BindingResult result) 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);
    PersistencePackageRequest ppr = getSectionPersistencePackageRequest(mainClassName, sectionCrumbs, pathVars);
    Entity entity = service.getRecord(ppr, id, mainMetadata, false).getDynamicResultSet().getRecords()[0];
    // First, we must save the collection entity
    PersistenceResponse persistenceResponse = service.updateSubCollectionEntity(entityForm, mainMetadata, collectionProperty, entity, collectionItemId, alternateId, sectionCrumbs);
    Entity savedEntity = persistenceResponse.getEntity();
    entityFormValidator.validate(entityForm, savedEntity, result);
    if (result.hasErrors()) {
        return showViewUpdateCollection(request, model, pathVars, id, collectionField, collectionItemId, alternateId, ModalHeaderType.UPDATE_COLLECTION_ITEM.getType(), entityForm, savedEntity);
    }
    // Next, we must get the new list grid that represents this collection
    // We return the new list grid so that it can replace the currently visible one
    ListGrid listGrid = getCollectionListGrid(mainMetadata, entity, collectionProperty, null, sectionKey, persistenceResponse, sectionCrumbs);
    model.addAttribute("listGrid", listGrid);
    model.addAttribute("currentUrl", request.getRequestURL().toString());
    setModelAttributes(model, sectionKey);
    return "views/standaloneListGrid";
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) Entity(org.broadleafcommerce.openadmin.dto.Entity) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) PersistenceResponse(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse) Property(org.broadleafcommerce.openadmin.dto.Property) ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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