Search in sources :

Example 1 with TranslationForm

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

the class AdminTranslationController method getTranslationForm.

/**
 * Converts an EntityForm into a TranslationForm
 *
 * @param entityForm
 * @return the converted translation form
 */
protected TranslationForm getTranslationForm(EntityForm entityForm) {
    TranslationForm form = new TranslationForm();
    form.setCeilingEntity(entityForm.findField("ceilingEntity").getValue());
    form.setEntityId(entityForm.findField("entityId").getValue());
    form.setLocaleCode(entityForm.findField("localeCode").getValue());
    form.setPropertyName(entityForm.findField("propertyName").getValue());
    form.setTranslatedValue(entityForm.findField("translatedValue").getValue());
    form.setIsRte(Boolean.valueOf(entityForm.findField("isRte").getValue()));
    if (StringUtils.isNotBlank(entityForm.getId())) {
        form.setTranslationId(Long.parseLong(entityForm.getId()));
    }
    return form;
}
Also used : TranslationForm(org.broadleafcommerce.openadmin.web.form.TranslationForm)

Example 2 with TranslationForm

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

the class AdminTranslationController method updateTranslation.

/**
 * Updates the given translation id to the new locale code and translated value
 *
 * @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 = "/update", method = RequestMethod.POST)
public String updateTranslation(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());
    sectionCrumb.setSectionId(String.valueOf(form.getTranslationId()));
    List<SectionCrumb> sectionCrumbs = Arrays.asList(sectionCrumb);
    entityForm.setCeilingEntityClassname(Translation.class.getName());
    entityForm.setEntityType(TranslationImpl.class.getName());
    Field id = new Field();
    id.setName("id");
    id.setValue(String.valueOf(form.getTranslationId()));
    entityForm.getFields().put("id", id);
    entityForm.setId(String.valueOf(form.getTranslationId()));
    String[] sectionCriteria = customCriteriaService.mergeSectionCustomCriteria(Translation.class.getName(), getSectionCustomCriteria());
    service.updateEntity(entityForm, sectionCriteria, sectionCrumbs).getEntity();
    return viewTranslation(request, response, model, form, result);
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) Field(org.broadleafcommerce.openadmin.web.form.entity.Field) Translation(org.broadleafcommerce.common.i18n.domain.Translation) TranslationImpl(org.broadleafcommerce.common.i18n.domain.TranslationImpl) TranslationForm(org.broadleafcommerce.openadmin.web.form.TranslationForm) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with TranslationForm

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

TranslationForm (org.broadleafcommerce.openadmin.web.form.TranslationForm)3 Translation (org.broadleafcommerce.common.i18n.domain.Translation)2 TranslationImpl (org.broadleafcommerce.common.i18n.domain.TranslationImpl)2 SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)2 Field (org.broadleafcommerce.openadmin.web.form.entity.Field)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 TranslatedEntity (org.broadleafcommerce.common.i18n.domain.TranslatedEntity)1 Entity (org.broadleafcommerce.openadmin.dto.Entity)1