Search in sources :

Example 1 with DelegationTargetLimitationDialog

use of com.evolveum.midpoint.web.page.admin.users.component.DelegationTargetLimitationDialog in project midpoint by Evolveum.

the class DelegationEditorPanel method initBodyLayout.

protected void initBodyLayout(WebMarkupContainer body) {
    DateInput validFrom = new DateInput(ID_DELEGATION_VALID_FROM, AssignmentsUtil.createDateModel(new PropertyModel<>(getModel(), AssignmentEditorDto.F_ACTIVATION + ".validFrom")));
    validFrom.setEnabled(getModel().getObject().isEditable());
    body.add(validFrom);
    DateInput validTo = new DateInput(ID_DELEGATION_VALID_TO, AssignmentsUtil.createDateModel(new PropertyModel<>(getModel(), AssignmentEditorDto.F_ACTIVATION + ".validTo")));
    validTo.setEnabled(getModel().getObject().isEditable());
    body.add(validTo);
    TextArea<String> description = new TextArea<>(ID_DESCRIPTION, new PropertyModel<String>(getModel(), AssignmentEditorDto.F_DESCRIPTION));
    description.setEnabled(getModel().getObject().isEditable());
    body.add(description);
    WebMarkupContainer assignmentPrivilegesContainer = new WebMarkupContainer(ID_ASSIGNMENT_PRIVILEGES_CONTAINER);
    assignmentPrivilegesContainer.setOutputMarkupId(true);
    assignmentPrivilegesContainer.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            List<AssignmentInfoDto> privilegesList = privilegesListModel.getObject();
            return privilegesList != null && privilegesList.size() > 0;
        }
    });
    body.add(assignmentPrivilegesContainer);
    AjaxCheckBox assignmentPrivilegesCheckbox = new AjaxCheckBox(ID_ASSIGNMENT_PRIVILEGES_CHECKBOX, new IModel<Boolean>() {

        private static final long serialVersionUID = 1L;

        @Override
        public Boolean getObject() {
            return getModelObject().getPrivilegeLimitationList() != null && getModelObject().getPrivilegeLimitationList().size() > 0;
        }

        @Override
        public void setObject(Boolean value) {
            if (value) {
                getModelObject().setPrivilegeLimitationList(privilegesListModel.getObject());
            } else {
                getModelObject().setPrivilegeLimitationList(new ArrayList<>());
            }
        }

        @Override
        public void detach() {
        }
    }) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.add(DelegationEditorPanel.this.get(ID_BODY).get(ID_ASSIGNMENT_PRIVILEGES_CONTAINER));
        }
    };
    assignmentPrivilegesCheckbox.setOutputMarkupId(true);
    assignmentPrivilegesCheckbox.add(new AjaxFormComponentUpdatingBehavior("blur") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
        }
    });
    assignmentPrivilegesCheckbox.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isEnabled() {
            return getModel().getObject().isEditable();
        }
    });
    assignmentPrivilegesContainer.add(assignmentPrivilegesCheckbox);
    WebMarkupContainer labelContainer = new WebMarkupContainer(ID_ASSIGNMENT_PRIVILEGES_LABEL_CONTAINER);
    labelContainer.setOutputMarkupId(true);
    assignmentPrivilegesContainer.add(labelContainer);
    Label assignmentPrivilegesLabel = new Label(ID_ASSIGNMENT_PRIVILEGES_LABEL, createStringResource("DelegationEditorPanel.allPrivilegesLabel"));
    assignmentPrivilegesLabel.setOutputMarkupId(true);
    labelContainer.add(assignmentPrivilegesLabel);
    addPrivilegesPanel(assignmentPrivilegesContainer);
    AjaxButton limitPrivilegesButton = new AjaxButton(ID_LIMIT_PRIVILEGES_BUTTON, createStringResource("DelegationEditorPanel.limitPrivilegesButton")) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            DelegationTargetLimitationDialog assignmentsDialog = new DelegationTargetLimitationDialog(getPageBase().getMainPopupBodyId(), selectExistingPrivileges(privilegesListModel.getObject()), getPageBase()) {

                @Override
                protected void addButtonClicked(AjaxRequestTarget target, List<AssignmentInfoDto> dtoList) {
                    DelegationEditorPanel.this.getModelObject().setPrivilegeLimitationList(dtoList);
                    getPageBase().hideMainPopup(target);
                }
            };
            getPageBase().showMainPopup(assignmentsDialog, target);
        }
    };
    limitPrivilegesButton.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return getModel().getObject().isEditable() && assignmentPrivilegesCheckbox.getModelObject();
        }
    });
    labelContainer.add(limitPrivilegesButton);
    AjaxCheckBox approvalRights = new AjaxCheckBox(ID_DELEGATE_APPROVAL_WI, new IModel<Boolean>() {

        private static final long serialVersionUID = 1L;

        @Override
        public Boolean getObject() {
            AssignmentEditorDto dto = getModelObject();
            if (dto.getPrivilegesLimitation() == null || dto.getPrivilegesLimitation().getApprovalWorkItems() == null || dto.getPrivilegesLimitation().getApprovalWorkItems().isAll() == null) {
                return false;
            }
            return dto.getPrivilegesLimitation().getApprovalWorkItems().isAll();
        }

        @Override
        public void setObject(Boolean value) {
            AssignmentEditorDto dto = getModelObject();
            OtherPrivilegesLimitationType limitations = dto.getPrivilegesLimitation();
            if (limitations == null) {
                limitations = new OtherPrivilegesLimitationType();
                dto.setPrivilegesLimitation(limitations);
            }
            WorkItemSelectorType workItemSelector = new WorkItemSelectorType();
            workItemSelector.all(value);
            limitations.setApprovalWorkItems(workItemSelector);
        }

        @Override
        public void detach() {
        }
    }) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
        }
    };
    approvalRights.setOutputMarkupId(true);
    approvalRights.add(new AjaxFormComponentUpdatingBehavior("blur") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
        }
    });
    approvalRights.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isEnabled() {
            return getModel().getObject().isEditable();
        }
    });
    body.add(approvalRights);
    AjaxCheckBox certificationRights = new AjaxCheckBox(ID_DELEGATE_CERTIFICATION_WI, new IModel<Boolean>() {

        private static final long serialVersionUID = 1L;

        @Override
        public Boolean getObject() {
            AssignmentEditorDto dto = getModelObject();
            if (dto.getPrivilegesLimitation() == null || dto.getPrivilegesLimitation().getCertificationWorkItems() == null || dto.getPrivilegesLimitation().getCertificationWorkItems().isAll() == null) {
                return false;
            }
            return dto.getPrivilegesLimitation().getCertificationWorkItems().isAll();
        }

        @Override
        public void setObject(Boolean value) {
            AssignmentEditorDto dto = getModelObject();
            OtherPrivilegesLimitationType limitations = dto.getPrivilegesLimitation();
            if (limitations == null) {
                limitations = new OtherPrivilegesLimitationType();
                dto.setPrivilegesLimitation(limitations);
            }
            WorkItemSelectorType workItemSelector = new WorkItemSelectorType();
            workItemSelector.all(value);
            limitations.setCertificationWorkItems(workItemSelector);
        }

        @Override
        public void detach() {
        }
    }) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
        }
    };
    certificationRights.add(new AjaxFormComponentUpdatingBehavior("blur") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
        }
    });
    certificationRights.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isEnabled() {
            return getModel().getObject().isEditable();
        }
    });
    certificationRights.setOutputMarkupId(true);
    body.add(certificationRights);
    AjaxCheckBox managementWorkItems = new AjaxCheckBox(ID_DELEGATE_MANAGEMENT_WI, new Model<>(false)) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
        }
    };
    managementWorkItems.setOutputMarkupId(true);
    managementWorkItems.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            // TODO not implemented yet
            return false;
        }
    });
    body.add(managementWorkItems);
    AjaxCheckBox allowTransitive = new AjaxCheckBox(ID_ALLOW_TRANSITIVE, new IModel<Boolean>() {

        private static final long serialVersionUID = 1L;

        @Override
        public Boolean getObject() {
            return getModelObject().isLimitTargetAllowTransitive();
        }

        @Override
        public void setObject(Boolean value) {
            getModelObject().setLimitTargetAllowTransitive(value);
        }

        @Override
        public void detach() {
        }
    }) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
        }
    };
    allowTransitive.add(new AjaxFormComponentUpdatingBehavior("blur") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
        }
    });
    allowTransitive.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isEnabled() {
            return getModel().getObject().isEditable();
        }
    });
    allowTransitive.setOutputMarkupId(true);
    body.add(allowTransitive);
    addAjaxOnUpdateBehavior(body);
}
Also used : AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) DelegationTargetLimitationDialog(com.evolveum.midpoint.web.page.admin.users.component.DelegationTargetLimitationDialog) TextArea(org.apache.wicket.markup.html.form.TextArea) ArrayList(java.util.ArrayList) Label(org.apache.wicket.markup.html.basic.Label) AjaxCheckBox(org.apache.wicket.ajax.markup.html.form.AjaxCheckBox) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) WorkItemSelectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemSelectorType) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxButton(com.evolveum.midpoint.web.component.AjaxButton) OtherPrivilegesLimitationType(com.evolveum.midpoint.xml.ns._public.common.common_3.OtherPrivilegesLimitationType) DateInput(com.evolveum.midpoint.web.component.DateInput) ArrayList(java.util.ArrayList) List(java.util.List) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)

Aggregations

AjaxButton (com.evolveum.midpoint.web.component.AjaxButton)1 DateInput (com.evolveum.midpoint.web.component.DateInput)1 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)1 DelegationTargetLimitationDialog (com.evolveum.midpoint.web.page.admin.users.component.DelegationTargetLimitationDialog)1 OtherPrivilegesLimitationType (com.evolveum.midpoint.xml.ns._public.common.common_3.OtherPrivilegesLimitationType)1 WorkItemSelectorType (com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemSelectorType)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)1 AjaxFormComponentUpdatingBehavior (org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior)1 AjaxCheckBox (org.apache.wicket.ajax.markup.html.form.AjaxCheckBox)1 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)1 Label (org.apache.wicket.markup.html.basic.Label)1 TextArea (org.apache.wicket.markup.html.form.TextArea)1