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;
}
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);
}
}
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);
}
}
}
}
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);
}
}
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);
}
}
Aggregations