Search in sources :

Example 16 with AjaxSubmitLink

use of org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink in project midpoint by Evolveum.

the class DashboardSearchPanel method initLayout.

@Override
protected void initLayout() {
    final Form searchForm = new Form(ID_SEARCH_FORM);
    add(searchForm);
    searchForm.setOutputMarkupId(true);
    final List<String> accessibleSearchTypes = new ArrayList<>();
    if (WebComponentUtil.isAuthorized(AuthorizationConstants.AUTZ_UI_USERS_ALL_URL, AuthorizationConstants.AUTZ_UI_USERS_URL)) {
        accessibleSearchTypes.add(SEARCH_TYPES.get(USER_INDEX));
    }
    if (WebComponentUtil.isAuthorized(AuthorizationConstants.AUTZ_UI_RESOURCES_ALL_URL, AuthorizationConstants.AUTZ_UI_RESOURCES_URL)) {
        accessibleSearchTypes.add(SEARCH_TYPES.get(RESOURCE_INDEX));
    }
    if (WebComponentUtil.isAuthorized(AuthorizationConstants.AUTZ_UI_TASKS_ALL_URL, AuthorizationConstants.AUTZ_UI_TASKS_URL)) {
        accessibleSearchTypes.add(SEARCH_TYPES.get(TASK_INDEX));
    }
    if (accessibleSearchTypes.size() == 0) {
        searchForm.setVisible(false);
    } else {
        final TextField searchInput = new TextField(ID_SEARCH_INPUT, Model.of("")) {

            @Override
            protected void onComponentTag(final ComponentTag tag) {
                super.onComponentTag(tag);
                tag.put("placeholder", createStringResource("SearchPanel.searchByName").getString());
            }
        };
        searchForm.add(searchInput);
        final Label buttonLabel = new Label(ID_BUTTON_LABEL, new Model<String>() {

            public String getObject() {
                return accessibleSearchTypes.get(selectedSearchType);
            }
        });
        buttonLabel.setOutputMarkupId(true);
        final AjaxSubmitLink searchButton = new AjaxSubmitLink(ID_SEARCH_BUTTON) {

            @Override
            protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                String searchType = buttonLabel.getDefaultModel().getObject().toString();
                String searchText = searchInput.getValue();
                performSearch(searchType, searchText == null ? "" : searchText);
            }
        };
        searchButton.setOutputMarkupId(true);
        searchButton.add(buttonLabel);
        searchForm.add(searchButton);
        searchForm.setDefaultButton(searchButton);
        //            final WebMarkupContainer list = new WebMarkupContainer(ID_SEARCH_TYPES);
        //            list.setOutputMarkupId(true);
        ListView<String> li = new ListView<String>(ID_SEARCH_TYPES, new IModel<List<String>>() {

            @Override
            public void detach() {
            }

            @Override
            public List<String> getObject() {
                return accessibleSearchTypes;
            }

            @Override
            public void setObject(List<String> list) {
            }
        }) {

            @Override
            protected void populateItem(final ListItem<String> item) {
                final AjaxLink searchTypeLink = new AjaxLink(ID_SEARCH_TYPE_ITEM) {

                    @Override
                    public IModel<?> getBody() {
                        return new Model<String>(item.getModel().getObject());
                    }

                    @Override
                    public void onClick(AjaxRequestTarget target) {
                        selectedSearchType = accessibleSearchTypes.indexOf(item.getModelObject());
                        target.add(DashboardSearchPanel.this.get(createComponentPath(ID_SEARCH_FORM, ID_SEARCH_BUTTON)));
                    }

                    @Override
                    protected void onComponentTag(final ComponentTag tag) {
                        super.onComponentTag(tag);
                        tag.put("value", item.getModelObject());
                    }
                };
                searchTypeLink.setOutputMarkupId(true);
                item.add(searchTypeLink);
            }
        };
        li.setOutputMarkupId(true);
        searchForm.add(li);
    //            final RepeatingView searchTypes = new RepeatingView(ID_SEARCH_TYPE_ITEM);
    //            searchTypes.setOutputMarkupId(true);
    //            if (accessibleSearchTypes.size() > 1) {
    //                for (int i = 0; i < accessibleSearchTypes.size(); i++) {
    //                    if (i == selectedSearchType){
    //                        continue;
    //                    }
    //                    final String searchTypeItem = accessibleSearchTypes.get(i);
    //                    final AjaxSubmitLink searchTypeLink = new AjaxSubmitLink(searchTypes.newChildId()) {
    //                        @Override
    //                        public void onSubmit(AjaxRequestTarget target, Form<?> form) {
    //                                selectedSearchType = accessibleSearchTypes.indexOf(searchTypeItem);
    //                                target.add(DashboardSearchPanel.this.get(createComponentPath(ID_SEARCH_FORM, ID_SEARCH_BUTTON)));
    //                                target.add(DashboardSearchPanel.this.get(createComponentPath(ID_SEARCH_FORM, ID_SEARCH_TYPES)));
    ////                                target.add(DashboardSearchPanel.this.get(createComponentPath(ID_SEARCH_FORM, ID_SEARCH_TYPES, ID_SEARCH_TYPE_ITEM)));
    //                        }
    //
    //                        @Override
    //                        protected void onComponentTag(final ComponentTag tag) {
    //                            super.onComponentTag(tag);
    //                            tag.put("value", searchTypeItem);
    //                        }
    //
    //                    };
    //                    searchTypeLink.setOutputMarkupId(true);
    //                    Label linkLabel = new Label(ID_LINK_LABEL, new Model<String>() {
    //                        public String getObject() {
    //                            return searchTypeItem;
    //                        }
    //                    });
    //                    linkLabel.setOutputMarkupId(true);
    //                    searchTypeLink.add(linkLabel);
    //                    searchTypes.add(searchTypeLink);
    //                }
    //            }
    //            list.add(searchTypes);
    //            if (accessibleSearchTypes.size() == 1){
    //                list.setVisible(false);
    //            }
    //            searchForm.add(list);
    }
}
Also used : Form(org.apache.wicket.markup.html.form.Form) ArrayList(java.util.ArrayList) Label(org.apache.wicket.markup.html.basic.Label) AjaxSubmitLink(org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ListView(org.apache.wicket.markup.html.list.ListView) ComponentTag(org.apache.wicket.markup.ComponentTag) Model(org.apache.wicket.model.Model) IModel(org.apache.wicket.model.IModel) TextField(org.apache.wicket.markup.html.form.TextField) ArrayList(java.util.ArrayList) List(java.util.List) ListItem(org.apache.wicket.markup.html.list.ListItem) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink)

Aggregations

AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)16 AjaxSubmitLink (org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink)16 Label (org.apache.wicket.markup.html.basic.Label)13 AjaxLink (org.apache.wicket.ajax.markup.html.AjaxLink)10 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)9 List (java.util.List)8 Form (org.apache.wicket.markup.html.form.Form)8 ListItem (org.apache.wicket.markup.html.list.ListItem)8 AbstractReadOnlyModel (org.apache.wicket.model.AbstractReadOnlyModel)8 InfoTooltipBehavior (com.evolveum.midpoint.web.util.InfoTooltipBehavior)7 ArrayList (java.util.ArrayList)6 MultiValueTextEditPanel (com.evolveum.midpoint.web.component.form.multivalue.MultiValueTextEditPanel)5 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)5 QName (javax.xml.namespace.QName)4 IModel (org.apache.wicket.model.IModel)4 Model (org.apache.wicket.model.Model)4 NonEmptyModel (com.evolveum.midpoint.gui.api.model.NonEmptyModel)3 EmptyOnChangeAjaxFormUpdatingBehavior (com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnChangeAjaxFormUpdatingBehavior)3 PageResourceWizard (com.evolveum.midpoint.web.page.admin.resources.PageResourceWizard)3 DropDownChoice (org.apache.wicket.markup.html.form.DropDownChoice)3