Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Jun 5, 2020
2 parents 157fcf7 + ba3f9cb commit c5b32ed
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 115 deletions.
Expand Up @@ -3103,6 +3103,21 @@ public static ObjectFilter getAssignableRolesFilter(PrismObject<? extends FocusT
return filter;
}

public static Behavior getSubmitOnEnterKeyDownBehavior(String submitButtonAboutAttribute){
return new Behavior() {

private static final long serialVersionUID = 1L;

@Override
public void bind(Component component) {
super.bind( component );

component.add( AttributeModifier.replace( "onkeydown",
Model.of("if(event.keyCode == 13) {$('[about=\"" + submitButtonAboutAttribute +"\"]').click();}") ) );
}
};
}

public static List<QName> getAssignableRelationsList(PrismObject<? extends FocusType> focusObject, Class<? extends AbstractRoleType> type,
AssignmentOrder assignmentOrder,
OperationResult result, Task task, PageBase pageBase){
Expand Down
Expand Up @@ -18,10 +18,14 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

import org.apache.commons.lang.StringUtils;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxEventBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.behavior.Behavior;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.IChoiceRenderer;
Expand Down Expand Up @@ -238,15 +242,6 @@ protected void onUpdate(AjaxRequestTarget ajaxRequestTarget) {
editPerformed(ajaxRequestTarget);
}
});
// searchItemField = new ValueChoosePanel<Referencable>(ID_SEARCH_ITEM_FIELD, new PropertyModel<>(getModel(), "value.value")){
//
// private static final long serialVersionUID = 1L;
//
// @Override
// public List<QName> getSupportedTypes() {
// return WebComponentUtil.createSupportedTargetTypeList(((PrismReferenceDefinition) item.getDefinition()).getTargetTypeName());
// }
// };
break;
case BOOLEAN:
choices = (IModel) createBooleanChoices();
Expand Down Expand Up @@ -277,21 +272,51 @@ public DisplayableValue getObject(String id, IModel<? extends List<? extends Dis
break;
case TEXT:
if (lookupTable != null){
searchItemField = (SearchPopupPanel<T>) new TextPopupPanel<T>(ID_SEARCH_ITEM_FIELD, new PropertyModel<>(getModel(), "value"), lookupTable);
searchItemField = new AutoCompleteTextPanel<String>(ID_SEARCH_ITEM_FIELD, new PropertyModel<>(getModel(), "value.value"), String.class,
true, lookupTable.asObjectable()) {

private static final long serialVersionUID = 1L;

@Override
public Iterator<String> getIterator(String input) {
return WebComponentUtil.prepareAutoCompleteList(lookupTable.asObjectable(), input,
((PageBase)getPage()).getLocalizationService()).iterator();
}
};

((AutoCompleteTextPanel) searchItemField).getBaseFormComponent().add(new Behavior() {

private static final long serialVersionUID = 1L;

@Override
public void bind(Component component) {
super.bind( component );

component.add( AttributeModifier.replace( "onkeydown",
Model.of(
"if (event.keyCode == 13){"
+ "var autocompletePopup = document.getElementsByClassName(\"wicket-aa-container\");"
+ "if(autocompletePopup != null && autocompletePopup[0].style.display == \"none\"){"
+ "$('[about=\"searchSimple\"]').click();}}"
)));
}
});
} else {
searchItemField = new TextPanel<String>(ID_SEARCH_ITEM_FIELD, new PropertyModel<>(getModel(), "value.value"));
}
break;
default:
searchItemField = (SearchPopupPanel<T>) new TextPopupPanel<T>(ID_SEARCH_ITEM_FIELD, new PropertyModel<>(getModel(), "value"), lookupTable);
searchItemField = new TextPanel<String>(ID_SEARCH_ITEM_FIELD, new PropertyModel<>(getModel(), "value"));
}
if (searchItemField == null){
searchItemField = new WebMarkupContainer(ID_SEARCH_ITEM_FIELD);
}
searchItemField.setOutputMarkupId(true);
if (searchItemField instanceof InputPanel){
if (searchItemField instanceof InputPanel && !(searchItemField instanceof AutoCompleteTextPanel)){
((InputPanel)searchItemField).getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
((InputPanel)searchItemField).getBaseFormComponent().add(WebComponentUtil.getSubmitOnEnterKeyDownBehavior("searchSimple"));
((InputPanel)searchItemField).getBaseFormComponent().add(AttributeAppender.append("style", "width: 200px; max-width: 400px !important;"));

}
searchItemContainer.add(searchItemField);
}
Expand Down Expand Up @@ -376,76 +401,8 @@ protected void confirmPerformed(AjaxRequestTarget target) {
WebMarkupContainer value = new WebMarkupContainer(ID_VALUE);
popoverBody.add(value);
}
//
// AjaxSubmitButton update = new AjaxSubmitButton(ID_UPDATE, createStringResource("SearchItemPanel.update")) {
//
// private static final long serialVersionUID = 1L;
//
// @Override
// protected void onSubmit(AjaxRequestTarget target) {
// updateItemPerformed(target);
// }
// };
// popoverBody.add(update);
//
// AjaxButton close = new AjaxButton(ID_CLOSE, createStringResource("SearchItemPanel.close")) {
//
// private static final long serialVersionUID = 1L;
//
// @Override
// public void onClick(AjaxRequestTarget target) {
// closeEditPopoverPerformed(target);
// }
// };
// popoverBody.add(close);
}
//
// private SearchPopupPanel<T> createPopoverFragment(IModel<DisplayableValue<T>> data) {
//// SearchPopupPanel<T> popup;
// SearchItem<T> item = getModelObject();
//
// IModel<List<DisplayableValue<T>>> choices = null;
//
// switch (item.getType()) {
// case REFERENCE:
// return (SearchPopupPanel) new ReferencePopupPanel(ID_VALUE, (IModel) data) {
//
// private static final long serialVersionUID = 1L;
//
// @Override
// protected List<QName> getAllowedRelations() {
// if (item.getAllowedRelations() != null) {
// return item.getAllowedRelations();
// }
// return super.getAllowedRelations();
// }
//
// @Override
// protected List<QName> getSupportedTargetList() {
// return WebComponentUtil.createSupportedTargetTypeList(((PrismReferenceDefinition) item.getDefinition()).getTargetTypeName());
// }
// };
//// break;
//// case BROWSER:
//// popup = new BrowserPopupPanel(ID_VALUE, data);
//// break;
// case BOOLEAN:
// choices = (IModel) createBooleanChoices();
// case ENUM:
// if (choices == null) {
// choices = new ListModel<>(item.getAllowedValues());
// }
// return (SearchPopupPanel<T>) new ComboPopupPanel<T>(ID_VALUE, data, choices);
//// break;
// case TEXT:
// default:
// PrismObject<LookupTableType> lookupTable = findLookupTable(item.getDefinition());
// return (SearchPopupPanel<T>) new TextPopupPanel<T>(ID_VALUE, data, lookupTable);
// }
//
//// return popup;
// }
//

private <I extends Item> PrismObject<LookupTableType> findLookupTable(ItemDefinition<I> definition) {
PrismReferenceValue valueEnumerationRef = definition.getValueEnumerationRef();
if (valueEnumerationRef == null) {
Expand Down
Expand Up @@ -10,6 +10,7 @@
import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.query.ObjectQuery;
Expand Down Expand Up @@ -37,16 +38,21 @@
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.behavior.Behavior;
import org.apache.wicket.core.util.string.CssUtils;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.MarkupStream;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.CheckBox;
import org.apache.wicket.markup.html.form.IFormSubmittingComponent;
import org.apache.wicket.markup.html.form.TextArea;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.util.string.AppendingStringBuffer;
import org.apache.wicket.util.time.Duration;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -425,18 +431,7 @@ public boolean isVisible(){
protected void onUpdate(AjaxRequestTarget target) {
}
});
fullTextInput.add(new Behavior() {

private static final long serialVersionUID = 1L;

@Override
public void bind(Component component) {
super.bind( component );

component.add( AttributeModifier.replace( "onkeydown",
Model.of("if(event.keyCode == 13) {$('[about=\"searchSimple\"]').click();}") ) );
}
});
fullTextInput.add(WebComponentUtil.getSubmitOnEnterKeyDownBehavior("searchSimple"));
fullTextInput.setOutputMarkupId(true);
fullTextInput.add(new AttributeAppender("placeholder",
createStringResource("SearchPanel.fullTextSearch")));
Expand Down Expand Up @@ -511,6 +506,10 @@ private void debugPerformed() {
SearchPanel.this.setResponsePage(pageQuery);
}

private Component getSimpleSearchButton(){
return get(createComponentPath(ID_FORM, ID_SEARCH_CONTAINER, ID_SEARCH_SIMPLE));
}

private IModel<String> createAdvancedGroupLabelStyle() {
return new IModel<String>() {

Expand Down
Expand Up @@ -13,6 +13,7 @@
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.util.DisplayableValue;
import com.evolveum.midpoint.web.model.LookupPropertyModel;
import com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnBlurAjaxFormUpdatingBehaviour;
import com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType;
import org.apache.commons.lang.StringUtils;
Expand All @@ -23,6 +24,7 @@
import org.apache.wicket.behavior.Behavior;
import org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteSettings;
import org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField;
import org.apache.wicket.markup.html.form.FormComponent;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
Expand Down Expand Up @@ -56,27 +58,7 @@ public TextPopupPanel(String id, IModel<DisplayableValue<T>> model, PrismObject<
private void initLayout() {
final TextField input = initTextField();

input.add(new AjaxFormComponentUpdatingBehavior("blur") {

private static final long serialVersionUID = 1L;

@Override
protected void onUpdate(AjaxRequestTarget target) {
//nothing to do, just update model data
}
});
input.add(new Behavior() {

private static final long serialVersionUID = 1L;

@Override
public void bind(Component component) {
super.bind(component);

component.add(AttributeModifier.replace("onkeydown",
Model.of("if(event.keyCode == 13) {event.preventDefault();}")));
}
});
input.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
input.setOutputMarkupId(true);
add(input);
}
Expand All @@ -103,7 +85,7 @@ private TextField initTextField() {
settings.setShowListOnEmptyInput(true);


return new AutoCompleteTextField<String>(ID_TEXT_INPUT, new PropertyModel<>(getModel(), SearchValue.F_VALUE), settings) {
AutoCompleteTextField<String> textField = new AutoCompleteTextField<String>(ID_TEXT_INPUT, new PropertyModel<>(getModel(), SearchValue.F_VALUE), settings) {

private static final long serialVersionUID = 1L;
@Override
Expand All @@ -130,8 +112,12 @@ public Object convertToObject(String value, Locale locale) throws ConversionExce
}

};
return textField;
}

public FormComponent getTextField(){
return (FormComponent) get(ID_TEXT_INPUT);
}

private List<String> prepareAutoCompleteList(String input) {
List<String> values = new ArrayList<>();
Expand Down

0 comments on commit c5b32ed

Please sign in to comment.