|
|
|
@ -51,7 +51,7 @@ public class ManageProductWidget extends Composite{
|
|
|
|
|
AlertBlock infoBlock;
|
|
|
|
|
|
|
|
|
|
@UiField
|
|
|
|
|
TextBox nameTextBox;
|
|
|
|
|
TextArea nameTextArea;
|
|
|
|
|
|
|
|
|
|
@UiField
|
|
|
|
|
TextBox currentStatus;
|
|
|
|
@ -85,75 +85,111 @@ public class ManageProductWidget extends Composite{
|
|
|
|
|
|
|
|
|
|
public static final String LOADING_IMAGE_URL = GWT.getModuleBaseURL() + "../images/loader.gif";
|
|
|
|
|
private final static List<GRSFStatus> STATUS = new ArrayList<GRSFStatus>(Arrays.asList(GRSFStatus.values()));
|
|
|
|
|
private final static String STATUS_UPDATE_SUCCESS = "The product was correctly updated. Thanks for your collaboration!";
|
|
|
|
|
private final static String STATUS_UPDATE_ERROR = "Sorry, there was a problem while trying to update the status of this product";
|
|
|
|
|
private final static String STATUS_UPDATE_SUCCESS = "The item has been correctly updated. Thanks for your collaboration!";
|
|
|
|
|
private final static String STATUS_UPDATE_ERROR = "Sorry, there was a problem while trying to update the status of this item";
|
|
|
|
|
protected static final String ERROR_ON_RETRIEVING_BEAN = "It seems there was a problem while contacting the service...";
|
|
|
|
|
protected static final String NO_GRSF_RECORD_BEAN = "This record is not a GRSF record, thus it cannot be managed";
|
|
|
|
|
protected static final String NO_GRSF_RECORD_BEAN = "This item is not a GRSF record, thus it cannot be managed";
|
|
|
|
|
|
|
|
|
|
protected static final String ERROR_ON_ROLE_CHECK = "Sorry but the service was not able to check if you have the rights to manage an item."
|
|
|
|
|
+ " You are suggested to contact the VRE Manager.";
|
|
|
|
|
private ManageProductBean bean;
|
|
|
|
|
|
|
|
|
|
public ManageProductWidget(String productIdentifier) {
|
|
|
|
|
initWidget(uiBinder.createAndBindUi(this));
|
|
|
|
|
|
|
|
|
|
if(productIdentifier == null || productIdentifier.isEmpty()){
|
|
|
|
|
GWT.log("The received product identifier is null..");
|
|
|
|
|
GWT.log("The received item identifier is null..");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GWT.log("Product identifier is " + productIdentifier);
|
|
|
|
|
GWT.log("item identifier is " + productIdentifier);
|
|
|
|
|
|
|
|
|
|
// start loader service
|
|
|
|
|
loadingImage.setUrl(LOADING_IMAGE_URL);
|
|
|
|
|
loadingImage.setVisible(true);
|
|
|
|
|
|
|
|
|
|
manageProductModal.show();
|
|
|
|
|
|
|
|
|
|
// async request to fetch the product
|
|
|
|
|
retrieveProductBean(productIdentifier);
|
|
|
|
|
manageProductModal.show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void retrieveProductBean(String productIdentifier) {
|
|
|
|
|
private void retrieveProductBean(final String productIdentifier) {
|
|
|
|
|
|
|
|
|
|
service.getProductBeanById(productIdentifier, new AsyncCallback<ManageProductBean>() {
|
|
|
|
|
// check if it is an administrator
|
|
|
|
|
service.isAdminUser(new AsyncCallback<Boolean>() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onSuccess(ManageProductBean result) {
|
|
|
|
|
|
|
|
|
|
if(result != null){
|
|
|
|
|
bean = result;
|
|
|
|
|
annotationArea.setText("");
|
|
|
|
|
infoBlock.setVisible(false);
|
|
|
|
|
nameTextBox.setText(bean.getProductName());
|
|
|
|
|
currentStatus.setText(bean.getCurrentStatus().toString());
|
|
|
|
|
productType.setText(bean.getProductType());
|
|
|
|
|
List<GRSFStatus> statusToShow = new ArrayList<GRSFStatus>(STATUS);
|
|
|
|
|
statusToShow.remove(bean.getCurrentStatus());
|
|
|
|
|
listBoxStatus.addItem("Select the new status");
|
|
|
|
|
listBoxStatus.getElement().<SelectElement>cast().getOptions().getItem(0).setDisabled(true);
|
|
|
|
|
for (GRSFStatus availableStatus : statusToShow) {
|
|
|
|
|
listBoxStatus.addItem(availableStatus.toString());
|
|
|
|
|
}
|
|
|
|
|
listBoxStatus.setSelectedIndex(0);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
showInfo(ERROR_ON_RETRIEVING_BEAN, AlertType.ERROR);
|
|
|
|
|
public void onSuccess(Boolean result) {
|
|
|
|
|
|
|
|
|
|
if(!result){
|
|
|
|
|
|
|
|
|
|
showInfo(ERROR_ON_ROLE_CHECK, AlertType.ERROR);
|
|
|
|
|
|
|
|
|
|
// hide the form and disable the send button
|
|
|
|
|
formUpdate.setVisible(false);
|
|
|
|
|
confirmButton.setEnabled(false);
|
|
|
|
|
loadingImage.setVisible(false);
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
service.getProductBeanById(productIdentifier, new AsyncCallback<ManageProductBean>() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onSuccess(ManageProductBean result) {
|
|
|
|
|
|
|
|
|
|
if(result != null){
|
|
|
|
|
bean = result;
|
|
|
|
|
annotationArea.setText("");
|
|
|
|
|
infoBlock.setVisible(false);
|
|
|
|
|
nameTextArea.setText(bean.getProductName());
|
|
|
|
|
currentStatus.setText(bean.getCurrentStatus().toString());
|
|
|
|
|
productType.setText(bean.getProductType());
|
|
|
|
|
List<GRSFStatus> statusToShow = new ArrayList<GRSFStatus>(STATUS);
|
|
|
|
|
statusToShow.remove(bean.getCurrentStatus());
|
|
|
|
|
listBoxStatus.addItem("Select the new status");
|
|
|
|
|
listBoxStatus.getElement().<SelectElement>cast().getOptions().getItem(0).setDisabled(true);
|
|
|
|
|
for (GRSFStatus availableStatus : statusToShow) {
|
|
|
|
|
listBoxStatus.addItem(availableStatus.toString());
|
|
|
|
|
}
|
|
|
|
|
listBoxStatus.setSelectedIndex(0);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
showInfo(ERROR_ON_RETRIEVING_BEAN, AlertType.ERROR);
|
|
|
|
|
formUpdate.setVisible(false);
|
|
|
|
|
confirmButton.setEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadingImage.setVisible(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
|
|
|
|
|
|
if(caught instanceof NoGRSFRecordException)
|
|
|
|
|
showInfo(NO_GRSF_RECORD_BEAN, AlertType.WARNING);
|
|
|
|
|
else
|
|
|
|
|
showInfo(caught.getMessage(), AlertType.ERROR);
|
|
|
|
|
|
|
|
|
|
// hide the form and disable the send button
|
|
|
|
|
formUpdate.setVisible(false);
|
|
|
|
|
confirmButton.setEnabled(false);
|
|
|
|
|
loadingImage.setVisible(false);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadingImage.setVisible(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
|
|
|
|
|
|
if(caught instanceof NoGRSFRecordException)
|
|
|
|
|
showInfo(NO_GRSF_RECORD_BEAN, AlertType.WARNING);
|
|
|
|
|
else
|
|
|
|
|
showInfo(caught.getMessage(), AlertType.ERROR);
|
|
|
|
|
|
|
|
|
|
showInfo(ERROR_ON_ROLE_CHECK, AlertType.ERROR);
|
|
|
|
|
|
|
|
|
|
// hide the form and disable the send button
|
|
|
|
|
formUpdate.setVisible(false);
|
|
|
|
|
confirmButton.setEnabled(false);
|
|
|
|
|
loadingImage.setVisible(false);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|