Search in sources :

Example 1 with UserSelectionButton

use of com.evolveum.midpoint.web.component.assignment.UserSelectionButton in project midpoint by Evolveum.

the class PageAssignmentsList method initLayout.

public void initLayout() {
    setOutputMarkupId(true);
    MidpointForm mainForm = new MidpointForm(ID_FORM);
    mainForm.setOutputMarkupId(true);
    add(mainForm);
    AssignmentTablePanel panel = new AssignmentTablePanel<UserType>(ID_ASSIGNMENT_TABLE_PANEL, assignmentsModel) {

        private static final long serialVersionUID = 1L;

        @Override
        protected List<InlineMenuItem> createAssignmentMenu() {
            List<InlineMenuItem> items = new ArrayList<>();
            InlineMenuItem item = new InlineMenuItem(createStringResource("PageAssignmentsList.deleteAllItemsFromShoppingCart")) {

                private static final long serialVersionUID = 1L;

                @Override
                public InlineMenuItemAction initAction() {
                    return new InlineMenuItemAction() {

                        private static final long serialVersionUID = 1L;

                        @Override
                        public void onClick(AjaxRequestTarget target) {
                            getModelObject().forEach(assignmentEditorDto -> assignmentEditorDto.setSelected(true));
                            deleteAssignmentPerformed(target, null);
                        }
                    };
                }
            };
            items.add(item);
            return items;
        }

        @Override
        public IModel<String> getLabel() {
            return createStringResource("PageAssignmentsList.assignmentsToRequest");
        }

        @Override
        protected boolean isRelationEditable() {
            return false;
        }

        @Override
        protected void reloadMainFormButtons(AjaxRequestTarget target) {
            Component requestButton = PageAssignmentsList.this.get(createComponentPath(ID_FORM, ID_REQUEST_BUTTON));
            if (requestButton != null) {
                refreshRequestButton(requestButton);
            }
            target.add(getFeedbackPanel());
            target.add(requestButton);
        }
    };
    mainForm.add(panel);
    UserSelectionButton targetUserPanel = new UserSelectionButton(ID_TARGET_USER_PANEL, new IModel<List<UserType>>() {

        @Override
        public List<UserType> getObject() {
            return WebComponentUtil.loadTargetUsersListForShoppingCart(OPERATION_LOAD_ASSIGNMENT_TARGET_USER_OBJECT, PageAssignmentsList.this);
        }
    }, true, createStringResource("AssignmentCatalogPanel.selectTargetUser")) {

        private static final long serialVersionUID = 1L;

        @Override
        protected String getUserButtonLabel() {
            return getTargetUserSelectionButtonLabel(getModelObject());
        }

        @Override
        protected void onDeleteSelectedUsersPerformed(AjaxRequestTarget target) {
            super.onDeleteSelectedUsersPerformed(target);
            getSessionStorage().getRoleCatalog().setTargetUserOidsList(new ArrayList<>());
            targetUserChangePerformed(target);
        }

        @Override
        protected void multipleUsersSelectionPerformed(AjaxRequestTarget target, List<UserType> usersList) {
            if (CollectionUtils.isNotEmpty(usersList)) {
                List<String> usersOidsList = new ArrayList<>();
                usersList.forEach(user -> usersOidsList.add(user.getOid()));
                getSessionStorage().getRoleCatalog().setTargetUserOidsList(usersOidsList);
            }
            targetUserChangePerformed(target);
        }
    };
    targetUserPanel.setOutputMarkupId(true);
    mainForm.add(targetUserPanel);
    TextArea<String> descriptionInput = new TextArea<>(ID_DESCRIPTION, descriptionModel);
    descriptionInput.add(new AjaxFormComponentUpdatingBehavior("blur") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            getSessionStorage().getRoleCatalog().setRequestDescription(getDescriptionComponent().getValue());
        }
    });
    mainForm.add(descriptionInput);
    AjaxButton back = new AjaxButton(ID_BACK, createStringResource("PageAssignmentDetails.backButton")) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            redirectBack();
        }
    };
    mainForm.add(back);
    AjaxButton requestAssignments = new AjaxButton(ID_REQUEST_BUTTON, createStringResource("PageAssignmentsList.requestButton")) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            if (getSessionStorage().getRoleCatalog().getTargetUserOidsList() == null || getSessionStorage().getRoleCatalog().getTargetUserOidsList().size() <= 1) {
                onSingleUserRequestPerformed(target);
            } else {
                onMultiUserRequestPerformed(target);
            }
        }
    };
    requestAssignments.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isEnabled() {
            return isRequestButtonEnabled();
        }
    });
    mainForm.add(requestAssignments);
    refreshRequestButton(requestAssignments);
    AjaxSubmitButton resolveAssignments = new AjaxSubmitButton(ID_RESOLVE_CONFLICTS_BUTTON, createStringResource("PageAssignmentsList.resolveConflicts")) {

        @Override
        protected void onError(AjaxRequestTarget target) {
            target.add(getFeedbackPanel());
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            PageAssignmentsList.this.navigateToNext(PageAssignmentConflicts.class);
        }
    };
    resolveAssignments.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return !getSessionStorage().getRoleCatalog().isMultiUserRequest() && !areConflictsResolved();
        }
    });
    mainForm.add(resolveAssignments);
}
Also used : AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) AjaxSubmitButton(com.evolveum.midpoint.web.component.AjaxSubmitButton) UserSelectionButton(com.evolveum.midpoint.web.component.assignment.UserSelectionButton) TextArea(org.apache.wicket.markup.html.form.TextArea) MidpointForm(com.evolveum.midpoint.web.component.form.MidpointForm) AssignmentTablePanel(com.evolveum.midpoint.web.component.assignment.AssignmentTablePanel) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxButton(com.evolveum.midpoint.web.component.AjaxButton) InlineMenuItemAction(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItemAction) InlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) Component(org.apache.wicket.Component)

Example 2 with UserSelectionButton

use of com.evolveum.midpoint.web.component.assignment.UserSelectionButton in project midpoint by Evolveum.

the class UserViewTabPanel method initSourceUserSelectionPanel.

private void initSourceUserSelectionPanel(WebMarkupContainer sourceUserPanel) {
    UserSelectionButton sourceUserButton = new UserSelectionButton(ID_SOURCE_USER_BUTTON, new IModel<List<UserType>>() {

        @Override
        public List<UserType> getObject() {
            List<UserType> usersList = new ArrayList<>();
            if (getRoleCatalogStorage().getAssignmentsUserOwner() != null) {
                usersList.add(getRoleCatalogStorage().getAssignmentsUserOwner());
            }
            return usersList;
        }
    }, false, createStringResource("AssignmentCatalogPanel.selectSourceUser")) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void singleUserSelectionPerformed(AjaxRequestTarget target, UserType user) {
            super.singleUserSelectionPerformed(target, user);
            getRoleCatalogStorage().setAssignmentsUserOwner(user);
            target.add(UserViewTabPanel.this);
        }

        @Override
        protected String getUserButtonLabel() {
            return getSourceUserSelectionButtonLabel();
        }

        @Override
        protected boolean isDeleteButtonVisible() {
            return false;
        }
    };
    sourceUserButton.setOutputMarkupId(true);
    sourceUserPanel.add(sourceUserButton);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) UserSelectionButton(com.evolveum.midpoint.web.component.assignment.UserSelectionButton) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

UserSelectionButton (com.evolveum.midpoint.web.component.assignment.UserSelectionButton)2 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)2 AjaxButton (com.evolveum.midpoint.web.component.AjaxButton)1 AjaxSubmitButton (com.evolveum.midpoint.web.component.AjaxSubmitButton)1 AssignmentTablePanel (com.evolveum.midpoint.web.component.assignment.AssignmentTablePanel)1 MidpointForm (com.evolveum.midpoint.web.component.form.MidpointForm)1 InlineMenuItem (com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem)1 InlineMenuItemAction (com.evolveum.midpoint.web.component.menu.cog.InlineMenuItemAction)1 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Component (org.apache.wicket.Component)1 AjaxFormComponentUpdatingBehavior (org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior)1 TextArea (org.apache.wicket.markup.html.form.TextArea)1