errors are now highlighted to help the user to understand which is the mistake he is making

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@131460 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-09-16 15:40:32 +00:00
parent 6468bd1a12
commit 2f791c50a6
5 changed files with 45 additions and 8 deletions

View File

@ -40,6 +40,7 @@ import com.github.gwtbootstrap.client.ui.TextBox;
import com.github.gwtbootstrap.client.ui.base.ListItem;
import com.github.gwtbootstrap.client.ui.constants.AlertType;
import com.github.gwtbootstrap.client.ui.constants.ButtonType;
import com.github.gwtbootstrap.client.ui.constants.ControlGroupType;
import com.github.gwtbootstrap.client.ui.resources.Bootstrap.Tabs;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
@ -159,6 +160,10 @@ public class CreateDatasetForm extends Composite{
@UiField FocusPanel focusPanelResources;
@UiField Popover popoverResources;
@UiField ControlGroup metadataProfilesControlGroup;
@UiField ControlGroup productTitleGroup;
@UiField ControlGroup maintainerControlGroup;
@UiField ControlGroup versionControlGroup;
@UiField ControlGroup organizationsGroup;
// error message
protected static final String ERROR_PRODUCT_CREATION = "There was an error while trying to publish your product, sorry.. Retry later";
@ -966,9 +971,12 @@ public class CreateDatasetForm extends Composite{
private String areProfileDataValid() {
for (MetaDataFieldSkeleton field : listOfMetadataFields) {
field.removeError();
String error = field.isFieldValueValid();
if(error != null){
field.showError();
return field.getFieldName() + " is not valid. Suggestion: " + error;
}
}
@ -1037,9 +1045,17 @@ public class CreateDatasetForm extends Composite{
private String validateDataOnContinue() {
String errorMessage = null;
// remove errors
productTitleGroup.setType(ControlGroupType.NONE);
maintainerControlGroup.setType(ControlGroupType.NONE);
versionControlGroup.setType(ControlGroupType.NONE);
metadataProfilesControlGroup.setType(ControlGroupType.NONE);
organizationsGroup.setType(ControlGroupType.NONE);
if(titleTextBox.getText().isEmpty()){
errorMessage = "Missing title";
productTitleGroup.setType(ControlGroupType.ERROR);
return errorMessage;
}
@ -1049,8 +1065,10 @@ public class CreateDatasetForm extends Composite{
for (String word : splittedTitle) {
if(!word.matches(regexTitleSubWord))
if(!word.matches(regexTitleSubWord)){
productTitleGroup.setType(ControlGroupType.ERROR);
return "Please note that only alphanumeric characters are allowed for the title";
}
}
@ -1058,6 +1076,7 @@ public class CreateDatasetForm extends Composite{
String regexMail = "\\b[\\w.%-]+@[-.\\w]+\\.[A-Za-z]{2,4}\\b";
if(!validateByRegExpression(maintainerEmailTextbox.getText(), regexMail)){
errorMessage = "Not valid maintainer email";
maintainerControlGroup.setType(ControlGroupType.ERROR);
return errorMessage;
}
@ -1065,15 +1084,18 @@ public class CreateDatasetForm extends Composite{
try{
Integer.valueOf(versionTextbox.getText());
}catch(Exception e){
versionControlGroup.setType(ControlGroupType.ERROR);
return errorMessage = "Version must be a natural number";
}
// check if metadata profile is different from none and its mandatory fields have been fulfilled
if(checkSelectedMetaDataProfile()){
errorMessage = "You must select a metadata profile different frome none";
metadataProfilesControlGroup.setType(ControlGroupType.ERROR);
}
if(organizationsListbox.getSelectedItemText() == null){
organizationsGroup.setType(ControlGroupType.ERROR);
errorMessage = "You must select an organization in which you want to publish";
}

View File

@ -55,7 +55,7 @@
<b:AlertBlock type="INFO" close="false" animation="true"
visible="false" ui:field="infoBlock" styleName="{style.block-alert-style}"></b:AlertBlock>
<b:ControlGroup>
<b:ControlGroup ui:field="productTitleGroup" >
<b:ControlLabel for="title" title="Product title">
<font color="red">*</font>
Title :
@ -151,7 +151,7 @@
</b:Controls>
</b:ControlGroup>
<b:ControlGroup>
<b:ControlGroup ui:field="organizationsGroup">
<b:ControlLabel for="organization"
title="Select the organizations in which you want
to publish the product">Publish in:</b:ControlLabel>
@ -162,7 +162,7 @@
</b:Controls>
</b:ControlGroup>
<b:ControlGroup>
<b:ControlGroup ui:field="versionControlGroup">
<b:ControlLabel for="version"
title="Product version expressed as positive integer number">
Version:
@ -193,7 +193,7 @@
</b:Controls>
</b:ControlGroup>
<b:ControlGroup>
<b:ControlGroup ui:field="authorEmailControlGroup">
<b:ControlLabel for="email" title="Product author's email">
<font color="red">*</font>
Author Email:
@ -232,7 +232,7 @@
</b:Controls>
</b:ControlGroup>
<b:ControlGroup>
<b:ControlGroup ui:field="maintainerControlGroup">
<b:ControlLabel for="emailMaintaner" title="Product author's email">
Maintainer Email:
</b:ControlLabel>

View File

@ -10,6 +10,7 @@ import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetadataFieldWr
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.CheckBox;
import com.github.gwtbootstrap.client.ui.ControlGroup;
import com.github.gwtbootstrap.client.ui.ControlLabel;
import com.github.gwtbootstrap.client.ui.Controls;
import com.github.gwtbootstrap.client.ui.Icon;
@ -17,6 +18,7 @@ import com.github.gwtbootstrap.client.ui.ListBox;
import com.github.gwtbootstrap.client.ui.Popover;
import com.github.gwtbootstrap.client.ui.TextArea;
import com.github.gwtbootstrap.client.ui.TextBox;
import com.github.gwtbootstrap.client.ui.constants.ControlGroupType;
import com.github.gwtbootstrap.client.ui.constants.IconType;
import com.github.gwtbootstrap.datetimepicker.client.ui.DateTimeBox;
import com.google.gwt.core.client.GWT;
@ -61,6 +63,7 @@ public class MetaDataFieldSkeleton extends Composite{
@UiField Controls controls;
@UiField Icon infoIcon;
@UiField FocusPanel focusPanelIconContainer;
@UiField ControlGroup metafieldControlGroup;
private static final String REGEX_IS_NUMBER = "[0-9]+[.]?[0-9]+";
@ -848,4 +851,16 @@ public class MetaDataFieldSkeleton extends Composite{
return field;
}
public void removeError() {
metafieldControlGroup.setType(ControlGroupType.NONE);
}
public void showError() {
metafieldControlGroup.setType(ControlGroupType.ERROR);
}
}

View File

@ -23,7 +23,7 @@
}
</ui:style>
<g:HTMLPanel width="100%">
<b:ControlGroup>
<b:ControlGroup ui:field="metafieldControlGroup">
<b:ControlLabel ui:field="controlLabel">
<font color="red" ui:field="mandatorySymbol">*</font>
<span ui:field="name"></span>

View File

@ -348,7 +348,7 @@ public class Utils {
for(MetadataField metadataField: toWrap){
MetadataFieldWrapper wrapperObj = new MetadataFieldWrapper();
wrapperObj.setDefaultValue(metadataField.getDefaulValue());
wrapperObj.setDefaultValue(metadataField.getDefaultValue());
wrapperObj.setFieldName(metadataField.getFieldName());
wrapperObj.setType(DataType.valueOf(metadataField.getDataType().toString()));
wrapperObj.setMandatory(metadataField.getMandatory());