1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.client.console.wizards;
20
21 import java.util.ArrayList;
22 import org.apache.syncope.client.console.panels.search.AnySelectionDirectoryPanel;
23 import org.apache.syncope.client.console.panels.search.SearchClausePanel;
24 import org.apache.syncope.client.console.panels.search.SearchUtils;
25 import org.apache.syncope.client.console.panels.search.UserSearchPanel;
26 import org.apache.syncope.client.console.panels.search.UserSelectionDirectoryPanel;
27 import org.apache.syncope.client.console.rest.AnyTypeClassRestClient;
28 import org.apache.syncope.client.console.rest.AnyTypeRestClient;
29 import org.apache.syncope.client.console.rest.UserRestClient;
30 import org.apache.syncope.client.lib.SyncopeClient;
31 import org.apache.syncope.common.lib.to.AnyTypeTO;
32 import org.apache.syncope.common.lib.to.UserTO;
33 import org.apache.syncope.common.lib.types.AnyTypeKind;
34 import org.apache.wicket.Component;
35 import org.apache.wicket.PageReference;
36 import org.apache.wicket.ajax.AjaxRequestTarget;
37 import org.apache.wicket.event.IEvent;
38 import org.apache.wicket.extensions.wizard.WizardStep;
39 import org.apache.wicket.model.IModel;
40 import org.apache.wicket.model.util.ListModel;
41 import org.apache.wicket.spring.injection.annot.SpringBean;
42
43 public class UserSelectionWizardStep extends WizardStep {
44
45 private static final long serialVersionUID = 36221031226727L;
46
47 @SpringBean
48 protected AnyTypeRestClient anyTypeRestClient;
49
50 @SpringBean
51 protected AnyTypeClassRestClient anyTypeClassRestClient;
52
53 @SpringBean
54 protected UserRestClient userRestClient;
55
56 protected final IModel<String> model;
57
58 protected final UserSearchPanel userSearchPanel;
59
60 protected final UserSelectionDirectoryPanel userDirectoryPanel;
61
62 public UserSelectionWizardStep(
63 final IModel<String> title, final IModel<String> model, final PageReference pageRef) {
64
65 super();
66 setOutputMarkupId(true);
67
68 this.model = model;
69 setTitleModel(title);
70
71 userSearchPanel = UserSearchPanel.class.cast(new UserSearchPanel.Builder(
72 new ListModel<>(new ArrayList<>()), pageRef).required(false).enableSearch(UserSelectionWizardStep.this).
73 build("usersearch"));
74 add(userSearchPanel);
75
76 AnyTypeTO anyTypeTO = anyTypeRestClient.read(AnyTypeKind.USER.name());
77 userDirectoryPanel = UserSelectionDirectoryPanel.class.cast(new UserSelectionDirectoryPanel.Builder(
78 anyTypeClassRestClient.list(anyTypeTO.getClasses()), userRestClient, anyTypeTO.getKey(), pageRef).
79 build("searchResult"));
80 add(userDirectoryPanel);
81 }
82
83 @Override
84 public void onEvent(final IEvent<?> event) {
85 if (event.getPayload() instanceof SearchClausePanel.SearchEvent) {
86 AjaxRequestTarget target = SearchClausePanel.SearchEvent.class.cast(event.getPayload()).getTarget();
87 String fiql = SearchUtils.buildFIQL(
88 userSearchPanel.getModel().getObject(), SyncopeClient.getUserSearchConditionBuilder());
89 userDirectoryPanel.search(fiql, target);
90 } else if (event.getPayload() instanceof AnySelectionDirectoryPanel.ItemSelection) {
91 @SuppressWarnings("unchecked")
92 AnySelectionDirectoryPanel.ItemSelection<UserTO> payload =
93 (AnySelectionDirectoryPanel.ItemSelection<UserTO>) event.getPayload();
94
95 UserTO selected = payload.getSelection();
96 this.model.setObject(selected.getKey());
97
98 String tableId = ((Component) event.getSource()).
99 get("container:content:searchContainer:resultTable:tablePanel:groupForm:checkgroup:dataTable").
100 getMarkupId();
101 String js = "$('#" + tableId + " tr').removeClass('active');";
102 js += "$('#" + tableId + " td[title=" + selected.getKey() + "]').parent().addClass('active');";
103 payload.getTarget().prependJavaScript(js);
104 }
105 }
106 }