Search in sources :

Example 41 with SectionCrumb

use of org.broadleafcommerce.openadmin.dto.SectionCrumb in project BroadleafCommerce by BroadleafCommerce.

the class AdminBasicEntityController method viewCollectionItemDetails.

/**
 * Shows the modal popup for the current selected "to-one" field. For instance, if you are viewing a list of products
 * then this method is invoked when a user clicks on the name of the default category field.
 *
 * @param request
 * @param response
 * @param model
 * @param pathVars
 * @param collectionField
 * @param id
 * @return
 * @throws Exception
 */
@RequestMapping(value = "/{collectionField:.*}/{id}/view", method = RequestMethod.GET)
public String viewCollectionItemDetails(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value = "collectionField") String collectionField, @PathVariable(value = "id") String id) 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);
    BasicFieldMetadata md = (BasicFieldMetadata) collectionProperty.getMetadata();
    AdminSection section = adminNavigationService.findAdminSectionByClassAndSectionId(md.getForeignKeyClass(), sectionKey);
    String sectionUrlKey = (section.getUrl().startsWith("/")) ? section.getUrl().substring(1) : section.getUrl();
    Map<String, String> varsForField = new HashMap<>();
    varsForField.put("sectionKey", sectionUrlKey);
    return viewEntityForm(request, response, model, varsForField, id);
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) HashMap(java.util.HashMap) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) AdminSection(org.broadleafcommerce.openadmin.server.security.domain.AdminSection) Property(org.broadleafcommerce.openadmin.dto.Property) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 42 with SectionCrumb

use of org.broadleafcommerce.openadmin.dto.SectionCrumb in project BroadleafCommerce by BroadleafCommerce.

the class AdminTranslationController method addTranslation.

/**
 * Saves a new translation to the database.
 *
 * Note that if the ceiling entity, entity id, property name, and locale code match a previously existing translation,
 * this method will update that translation.
 *
 * @param request
 * @param response
 * @param model
 * @param entityForm
 * @param result
 * @return the result of a call to {@link #viewTranslation}, which renders the list grid
 * @throws Exception
 */
@RequestMapping(value = "/add", method = RequestMethod.POST)
public String addTranslation(HttpServletRequest request, HttpServletResponse response, Model model, @ModelAttribute(value = "entityForm") EntityForm entityForm, BindingResult result) throws Exception {
    final TranslationForm form = getTranslationForm(entityForm);
    adminRemoteSecurityService.securityCheck(form.getCeilingEntity(), EntityOperationType.UPDATE);
    SectionCrumb sectionCrumb = new SectionCrumb();
    sectionCrumb.setSectionIdentifier(TranslationImpl.class.getName());
    List<SectionCrumb> sectionCrumbs = Arrays.asList(sectionCrumb);
    entityForm.setCeilingEntityClassname(Translation.class.getName());
    entityForm.setEntityType(TranslationImpl.class.getName());
    Field entityType = new Field();
    entityType.setName("entityType");
    String ceilingEntity = form.getCeilingEntity();
    TranslatedEntity translatedEntity = TranslatedEntity.getInstance(ceilingEntity);
    if (translatedEntity == null && ceilingEntity.endsWith("Impl")) {
        int pos = ceilingEntity.lastIndexOf("Impl");
        ceilingEntity = ceilingEntity.substring(0, pos);
        translatedEntity = TranslatedEntity.getInstance(ceilingEntity);
    }
    entityType.setValue(translatedEntity.getFriendlyType());
    Field fieldName = new Field();
    fieldName.setName("fieldName");
    fieldName.setValue(form.getPropertyName());
    entityForm.getFields().put("entityType", entityType);
    entityForm.getFields().put("fieldName", fieldName);
    String[] sectionCriteria = customCriteriaService.mergeSectionCustomCriteria(ceilingEntity, getSectionCustomCriteria());
    Entity entity = service.addEntity(entityForm, sectionCriteria, sectionCrumbs).getEntity();
    entityFormValidator.validate(entityForm, entity, result);
    if (result.hasErrors()) {
        entityForm.setPreventSubmit();
        String jsErrorMap = resultToJS(result);
        entityForm.setJsErrorMap(jsErrorMap);
        model.addAttribute("entity", entity);
        model.addAttribute("entityForm", entityForm);
        model.addAttribute("viewType", "modal/translationAdd");
        model.addAttribute("currentUrl", request.getRequestURL().toString());
        model.addAttribute("modalHeaderType", ModalHeaderType.ADD_TRANSLATION.getType());
        return "modules/modalContainer";
    } else {
        return viewTranslation(request, response, model, form, result);
    }
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) Field(org.broadleafcommerce.openadmin.web.form.entity.Field) Entity(org.broadleafcommerce.openadmin.dto.Entity) TranslatedEntity(org.broadleafcommerce.common.i18n.domain.TranslatedEntity) Translation(org.broadleafcommerce.common.i18n.domain.Translation) TranslationImpl(org.broadleafcommerce.common.i18n.domain.TranslationImpl) TranslationForm(org.broadleafcommerce.openadmin.web.form.TranslationForm) TranslatedEntity(org.broadleafcommerce.common.i18n.domain.TranslatedEntity) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)42 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)32 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)29 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)28 Entity (org.broadleafcommerce.openadmin.dto.Entity)19 Property (org.broadleafcommerce.openadmin.dto.Property)19 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)15 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)13 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)12 ListGrid (org.broadleafcommerce.openadmin.web.form.component.ListGrid)9 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)9 BasicCollectionMetadata (org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata)8 EntityForm (org.broadleafcommerce.openadmin.web.form.entity.EntityForm)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 PersistenceResponse (org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse)6 AdornedTargetCollectionMetadata (org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)5 Field (org.broadleafcommerce.openadmin.web.form.entity.Field)5 Map (java.util.Map)4 Translation (org.broadleafcommerce.common.i18n.domain.Translation)4