-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(registrar): add list and map application form items
* Added support for new applicatoin form items. * Both items have default input and add button. With this button, user can add new values to the list or map. Each new value in the list or map has also a remove button, so user can also remove the previously added value. * ListBox and MapBox have new own validators, ListBox has one more validator for ssh keys.
- Loading branch information
1 parent
2f85624
commit 6e48ade
Showing
16 changed files
with
750 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 168 additions & 0 deletions
168
...wui-registrar/src/main/java/cz/metacentrum/perun/wui/registrar/widgets/items/ListBox.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
package cz.metacentrum.perun.wui.registrar.widgets.items; | ||
|
||
import com.google.gwt.event.dom.client.BlurEvent; | ||
import com.google.gwt.event.dom.client.BlurHandler; | ||
import com.google.gwt.event.dom.client.ClickEvent; | ||
import com.google.gwt.event.dom.client.ClickHandler; | ||
import com.google.gwt.user.client.ui.HasVerticalAlignment; | ||
import com.google.gwt.user.client.ui.HorizontalPanel; | ||
import com.google.gwt.user.client.ui.Widget; | ||
import com.google.gwt.user.client.ui.VerticalPanel; | ||
import cz.metacentrum.perun.wui.json.Events; | ||
import cz.metacentrum.perun.wui.registrar.client.resources.PerunRegistrarResources; | ||
import cz.metacentrum.perun.wui.registrar.widgets.items.validators.ListBoxValidator; | ||
import cz.metacentrum.perun.wui.registrar.widgets.items.validators.SshKeysListBoxValidator; | ||
import cz.metacentrum.perun.wui.widgets.boxes.ExtendedTextBox; | ||
import cz.metacentrum.perun.wui.widgets.PerunButton; | ||
import cz.metacentrum.perun.wui.model.beans.ApplicationFormItemData; | ||
import cz.metacentrum.perun.wui.registrar.widgets.PerunForm; | ||
import org.gwtbootstrap3.client.ui.html.Paragraph; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Represents ListBox form item. | ||
* | ||
* @author Jakub Hejda <Jakub.Hejda@cesnet.cz> | ||
*/ | ||
public class ListBox extends WidgetBox { | ||
|
||
private final ListBoxValidator validator; | ||
List<ExtendedTextBox> inputList; | ||
|
||
public ListBox(PerunForm form, ApplicationFormItemData item, String lang) { | ||
super(form, item, lang); | ||
if ("urn:perun:user:attribute-def:def:sshPublicKey".equals(item.getFormItem().getPerunDestinationAttribute())) { | ||
this.validator = new SshKeysListBoxValidator(); | ||
} else { | ||
this.validator = new ListBoxValidator(); | ||
} | ||
} | ||
|
||
@Override | ||
public String getValue() { | ||
StringBuilder value = new StringBuilder(); | ||
if (isOnlyPreview()) { | ||
for(int i = 0; i < getPreview().getWidgetCount(); i++) { | ||
Paragraph p = (Paragraph) getPreview().getWidget(i); | ||
value.append((p.getText() == null || p.getText().isEmpty()) | ||
? "" | ||
: p.getText().replace(",", "\\,") + ","); | ||
} | ||
} else { | ||
for (ExtendedTextBox input : inputList) { | ||
value.append((input.getValue() == null || input.getValue().isEmpty()) | ||
? "" | ||
: input.getValue().replace(",", "\\,") + ","); | ||
} | ||
} | ||
|
||
return value.toString(); | ||
} | ||
|
||
public List<ExtendedTextBox> getListValue() { | ||
return inputList; | ||
} | ||
|
||
@Override | ||
public void validate(Events<Boolean> events) { | ||
validator.validate(this, events); | ||
} | ||
|
||
@Override | ||
public boolean validateLocal() { | ||
return validator.validateLocal(this); | ||
} | ||
|
||
@Override | ||
protected Widget initWidget() { | ||
inputList = new ArrayList<>(); | ||
return super.initWidget(); | ||
} | ||
|
||
@Override | ||
protected Widget initWidgetOnlyPreview() { | ||
widget = new Paragraph(); | ||
Paragraph p = new Paragraph(); | ||
p.addStyleName("form-control"); | ||
getPreview().add(p); | ||
return widget; | ||
} | ||
|
||
@Override | ||
protected void setValidationTriggers() { | ||
if (isOnlyPreview()) { | ||
return; | ||
} | ||
for (ExtendedTextBox input : inputList) { | ||
input.addBlurHandler(new BlurHandler() { | ||
@Override | ||
public void onBlur(BlurEvent event) { | ||
validateLocal(); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
@Override | ||
protected void setValueImpl(String value) { | ||
int counter = 0; | ||
if (isOnlyPreview()) { | ||
// delete default empty widget if there is some value | ||
getPreview().getWidget(0).removeFromParent(); | ||
} | ||
for (String val : value.split("(?<!\\\\),+?")) { | ||
if (isOnlyPreview()) { | ||
Paragraph p = new Paragraph(); | ||
p.setText(val.trim().replace("\\,", ",")); | ||
p.addStyleName("form-control"); | ||
p.addStyleName(PerunRegistrarResources.INSTANCE.gss().overflow()); | ||
p.setHeight("auto"); | ||
getPreview().add(p); | ||
} else { | ||
if (counter != 0) { | ||
generateItemWithRemoveButton((VerticalPanel) widget); | ||
} | ||
inputList.get(counter).setValue(val.trim().replace("\\,", ",")); | ||
} | ||
counter++; | ||
} | ||
} | ||
|
||
@Override | ||
protected PerunButton generateAddButton(VerticalPanel vp) { | ||
return new PerunButton("", new ClickHandler() { | ||
public void onClick(ClickEvent event) { | ||
generateItemWithRemoveButton(vp); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
protected void generateItemWithRemoveButton(VerticalPanel vp) { | ||
HorizontalPanel hp = new HorizontalPanel(); | ||
hp.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); | ||
hp.setWidth("100%"); | ||
ExtendedTextBox input = new ExtendedTextBox(); | ||
|
||
if (getItemData().getFormItem().getRegex() != null) { | ||
input.setRegex(getItemData().getFormItem().getRegex()); | ||
} | ||
|
||
inputList.add(input); | ||
PerunButton removeButton = new PerunButton("", new ClickHandler() { | ||
public void onClick(ClickEvent event) { | ||
inputList.remove(input); | ||
vp.remove(hp); | ||
validateLocal(); | ||
} | ||
}); | ||
setupRemoveButton(removeButton); | ||
hp.add(input); | ||
hp.add(removeButton); | ||
setValidationTriggers(); | ||
setupHPandAddToVP(hp, vp, removeButton); | ||
} | ||
|
||
} |
Oops, something went wrong.