Search in sources :

Example 1 with FormComponent

use of com.qcadoo.view.api.components.FormComponent in project qcadoo by qcadoo.

the class NumberGeneratorService method checkIfShouldInsertNumber.

/**
 * Checks if new entity number should be generated and inserted
 *
 * @param state
 *            main view state definition
 * @param formFieldReferenceName
 *            reference name of form
 * @param numberFieldReferenceName
 *            reference name of field into which generated number should be inserted
 * @return true if new entity number should be generated and inserted
 */
public boolean checkIfShouldInsertNumber(final ViewDefinitionState state, final String formFieldReferenceName, final String numberFieldReferenceName) {
    FormComponent form = (FormComponent) state.getComponentByReference(formFieldReferenceName);
    FieldComponent number = (FieldComponent) state.getComponentByReference(numberFieldReferenceName);
    if (form.getEntityId() != null) {
        // form is already saved
        return false;
    }
    if (StringUtils.isNotBlank((String) number.getFieldValue())) {
        // number is already chosen
        return false;
    }
    if (number.isHasError()) {
        // there is a validation message for that field
        return false;
    }
    return true;
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) FieldComponent(com.qcadoo.view.api.components.FieldComponent)

Example 2 with FormComponent

use of com.qcadoo.view.api.components.FormComponent in project qcadoo by qcadoo.

the class UserService method disableFormForSuperadmin.

public void disableFormForSuperadmin(final ViewDefinitionState state) {
    FormComponent form = (FormComponent) state.getComponentByReference(QcadooViewConstants.L_FORM);
    Long viewedUserId = form.getEntityId();
    Entity viewedUser = dataDefinitionService.get(QcadooSecurityConstants.PLUGIN_IDENTIFIER, QcadooSecurityConstants.MODEL_USER).get(viewedUserId);
    Entity loggedUser = dataDefinitionService.get(QcadooSecurityConstants.PLUGIN_IDENTIFIER, QcadooSecurityConstants.MODEL_USER).get(securityService.getCurrentUserId());
    if (!securityService.hasRole(loggedUser, "ROLE_SUPERADMIN") && securityService.hasRole(viewedUser, "ROLE_SUPERADMIN")) {
        form.setFormEnabled(false);
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity)

Example 3 with FormComponent

use of com.qcadoo.view.api.components.FormComponent in project qcadoo by qcadoo.

the class ReplaceCustomTranslationsListeners method replaceCustomTranslations.

public void replaceCustomTranslations(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    FormComponent replaceCustomTranslationsFrom = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    FieldComponent localeField = (FieldComponent) view.getComponentByReference(LOCALE);
    FieldComponent replaceFromField = (FieldComponent) view.getComponentByReference(L_REPLACE_FROM);
    FieldComponent replaceToField = (FieldComponent) view.getComponentByReference(L_REPLACE_TO);
    String locale = (String) localeField.getFieldValue();
    String replaceFrom = (String) replaceFromField.getFieldValue();
    String replaceTo = (String) replaceToField.getFieldValue();
    if (StringUtils.isEmpty(replaceFrom) || StringUtils.isEmpty(replaceTo)) {
        replaceCustomTranslationsFrom.addMessage("qcadooCustomTranslations.replaceCustomTranslations.message.replaceCustomTranslationsFailure", MessageType.FAILURE);
    } else {
        List<Entity> customTranslations = customTranslationManagementService.getCustomTranslations(locale);
        if (customTranslations.isEmpty()) {
            replaceCustomTranslationsFrom.addMessage("qcadooCustomTranslations.replaceCustomTranslations.message.replaceCustomTranslationsEmpty", MessageType.INFO);
        } else {
            int count = 0;
            for (Entity customTranslation : customTranslations) {
                String translation = customTranslation.getStringField(PROPERTIES_TRANSLATION);
                if (translation.contains(replaceFrom)) {
                    count++;
                    translation = translation.replace(replaceFrom, replaceTo);
                    customTranslation.setField(CUSTOM_TRANSLATION, translation);
                    customTranslation.getDataDefinition().save(customTranslation);
                }
            }
            if (count > 0) {
                replaceCustomTranslationsFrom.addMessage("qcadooCustomTranslations.replaceCustomTranslations.message.replaceCustomTranslationsSuccess", MessageType.SUCCESS);
            } else {
                replaceCustomTranslationsFrom.addMessage("qcadooCustomTranslations.replaceCustomTranslations.message.replaceCustomTranslationsInfo", MessageType.INFO);
            }
        }
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) FieldComponent(com.qcadoo.view.api.components.FieldComponent)

Example 4 with FormComponent

use of com.qcadoo.view.api.components.FormComponent in project qcadoo by qcadoo.

the class DictionaryItemDetailsHooks method disableNameEdit.

public void disableNameEdit(final ViewDefinitionState view) {
    FormComponent dictionaryItemForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    FieldComponent nameFieldComponent = (FieldComponent) view.getComponentByReference(DictionaryItemFields.NAME);
    if (dictionaryItemForm.getEntityId() == null) {
        return;
    } else {
        nameFieldComponent.setEnabled(false);
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) FieldComponent(com.qcadoo.view.api.components.FieldComponent)

Example 5 with FormComponent

use of com.qcadoo.view.api.components.FormComponent in project mes by qcadoo.

the class TOCDetailsHooksPFTD method setViewDisable.

private void setViewDisable(final ViewDefinitionState view) {
    FormComponent tocForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    if (tocForm.getEntityId() == null) {
        return;
    }
    Entity technology = tocForm.getPersistedEntityWithIncludedFormValues().getBelongsToField(TechnologyOperationComponentFields.TECHNOLOGY);
    LookupComponent divisionookupComponent = (LookupComponent) view.getComponentByReference("division");
    LookupComponent plLookupComponent = (LookupComponent) view.getComponentByReference("productionLine");
    if (Range.ONE_DIVISION.getStringValue().equals(technology.getStringField(TechnologyFieldsPFTD.RANGE))) {
        divisionookupComponent.setEnabled(false);
        if (technology.getBelongsToField("productionLine") == null) {
            plLookupComponent.setEnabled(true);
        } else {
            plLookupComponent.setEnabled(false);
        }
    } else {
        divisionookupComponent.setEnabled(true);
        plLookupComponent.setEnabled(true);
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) LookupComponent(com.qcadoo.view.api.components.LookupComponent)

Aggregations

FormComponent (com.qcadoo.view.api.components.FormComponent)644 Entity (com.qcadoo.model.api.Entity)501 FieldComponent (com.qcadoo.view.api.components.FieldComponent)183 LookupComponent (com.qcadoo.view.api.components.LookupComponent)104 GridComponent (com.qcadoo.view.api.components.GridComponent)83 BigDecimal (java.math.BigDecimal)55 WindowComponent (com.qcadoo.view.api.components.WindowComponent)52 FilterValueHolder (com.qcadoo.view.api.components.lookup.FilterValueHolder)45 RibbonActionItem (com.qcadoo.view.api.ribbon.RibbonActionItem)42 CheckBoxComponent (com.qcadoo.view.api.components.CheckBoxComponent)39 RibbonGroup (com.qcadoo.view.api.ribbon.RibbonGroup)36 Date (java.util.Date)33 DataDefinition (com.qcadoo.model.api.DataDefinition)29 AwesomeDynamicListComponent (com.qcadoo.view.api.components.AwesomeDynamicListComponent)28 JSONObject (org.json.JSONObject)28 ComponentState (com.qcadoo.view.api.ComponentState)27 Transactional (org.springframework.transaction.annotation.Transactional)20 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)17 Optional (com.google.common.base.Optional)16 Ribbon (com.qcadoo.view.api.ribbon.Ribbon)16