Skip to content

Commit

Permalink
removed error state from starts and error dates if they are valid (#2303
Browse files Browse the repository at this point in the history
)

Signed-off-by: ana.albic.comtrade <Ana.Albic@comtrade.com>
  • Loading branch information
ct-anaalbic authored and Coduz committed Jan 21, 2019
1 parent 4dc180b commit de6f51e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 16 deletions.
@@ -0,0 +1,42 @@
/*******************************************************************************
* Copyright (c) 2017, 2019 Eurotech and/or its affiliates and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Eurotech - initial API and implementation
*******************************************************************************/
package org.eclipse.kapua.app.console.module.api.client.util.validator;

import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.Field;
import com.extjs.gxt.ui.client.widget.form.Validator;
import com.google.gwt.core.client.GWT;
import org.eclipse.kapua.app.console.module.api.client.messages.ValidationMessages;

public class AfterDateValidator implements Validator {

private final DateField otherDateField;
private static final ValidationMessages VAL_MSGS = GWT.create(ValidationMessages.class);

public AfterDateValidator(DateField otherDateField) {
this.otherDateField = otherDateField;
}

@Override
public String validate(Field<?> field, String s) {
if (otherDateField.getValue() != null) {
DateField thisDateField = (DateField) field;
if (thisDateField.getValue().before(otherDateField.getValue())) {
otherDateField.clearInvalid();
} else {
return VAL_MSGS.startsOnDateLaterThanEndsOn();
}
}
return null;
}
}

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017 Eurotech and/or its affiliates and others
* Copyright (c) 2017, 2019 Eurotech and/or its affiliates and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand Down Expand Up @@ -30,7 +30,11 @@ public BeforeDateValidator(DateField otherDateField) {
public String validate(Field<?> field, String s) {
if (otherDateField.getValue() != null) {
DateField thisDateField = (DateField) field;
return thisDateField.getValue().after(otherDateField.getValue()) ? null : VAL_MSGS.endsOnDateEarlierThanStartsOn();
if (thisDateField.getValue().after(otherDateField.getValue())) {
otherDateField.clearInvalid();
} else {
return VAL_MSGS.endsOnDateEarlierThanStartsOn();
}
}
return null;
}
Expand Down
Expand Up @@ -11,16 +11,9 @@
*******************************************************************************/
package org.eclipse.kapua.app.console.module.job.client.schedule;

import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.Label;
import com.extjs.gxt.ui.client.widget.form.TimeField;
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.rpc.AsyncCallback;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.eclipse.kapua.app.console.module.api.client.GwtKapuaErrorCode;
import org.eclipse.kapua.app.console.module.api.client.GwtKapuaException;
import org.eclipse.kapua.app.console.module.api.client.messages.ValidationMessages;
Expand All @@ -32,17 +25,25 @@
import org.eclipse.kapua.app.console.module.api.client.util.ConsoleInfo;
import org.eclipse.kapua.app.console.module.api.client.util.DialogUtils;
import org.eclipse.kapua.app.console.module.api.client.util.FailureHandler;
import org.eclipse.kapua.app.console.module.api.client.util.validator.AfterDateValidator;
import org.eclipse.kapua.app.console.module.api.client.util.validator.BeforeDateValidator;
import org.eclipse.kapua.app.console.module.api.shared.model.session.GwtSession;
import org.eclipse.kapua.app.console.module.job.client.messages.ConsoleJobMessages;
import org.eclipse.kapua.app.console.module.job.shared.model.scheduler.GwtTrigger;
import org.eclipse.kapua.app.console.module.job.shared.model.scheduler.GwtTriggerCreator;
import org.eclipse.kapua.app.console.module.job.shared.model.scheduler.GwtTriggerProperty;
import org.eclipse.kapua.app.console.module.job.shared.service.GwtTriggerService;
import org.eclipse.kapua.app.console.module.job.shared.service.GwtTriggerServiceAsync;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.Label;
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
import com.extjs.gxt.ui.client.widget.form.TimeField;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class JobScheduleAddDialog extends EntityAddEditDialog {

Expand Down Expand Up @@ -113,6 +114,8 @@ public void handleEvent(BaseEvent be) {
startsOn.setEmptyText(JOB_MSGS.dialogAddScheduleDatePlaceholder());
startsOn.getPropertyEditor().setFormat(DateTimeFormat.getFormat("dd/MM/yyyy"));
startsOn.setToolTip(JOB_MSGS.dialogAddScheduleStartsOnTooltip());
startsOn.setValidator(new AfterDateValidator(endsOn));

startsOn.getDatePicker().addListener(Events.Select, listener);
startsOnLabel.setText("* " + JOB_MSGS.dialogAddScheduleStartsOnLabel());
startsOnLabel.setWidth(FORM_LABEL_WIDTH);
Expand Down Expand Up @@ -140,6 +143,8 @@ public void handleEvent(BaseEvent be) {
endsOn.setToolTip(JOB_MSGS.dialogAddScheduleEndsOnTooltip());
endsOnLabel.setText(JOB_MSGS.dialogAddScheduleEndsOnLabel());
endsOnLabel.setStyleAttribute("margin-left", "10px");
endsOn.setValidator(new BeforeDateValidator(startsOn));

endsOnLabel.setWidth(FORM_LABEL_WIDTH);
endsOnLabel.setStyleAttribute("padding", "0px 96px 0px 0px");
endsOn.getDatePicker().addListener(Events.Select, listener);
Expand Down Expand Up @@ -224,6 +229,7 @@ protected void preSubmit() {
} else {
endsOn.clearInvalid();
endsOnTime.clearInvalid();
startsOn.clearInvalid();
}
}
} else {
Expand Down

0 comments on commit de6f51e

Please sign in to comment.