Search in sources :

Example 1 with BasePage

use of org.apache.syncope.client.console.pages.BasePage in project syncope by apache.

the class WizardMgtPanel method onEvent.

@Override
@SuppressWarnings("unchecked")
public void onEvent(final IEvent<?> event) {
    if (event.getPayload() instanceof ExitEvent && modal != null) {
        final AjaxRequestTarget target = ExitEvent.class.cast(event.getPayload()).getTarget();
        // default behaviour: change it catching the event if needed
        modal.close(target);
    } else if (event.getPayload() instanceof AjaxWizard.NewItemEvent) {
        final AjaxWizard.NewItemEvent<T> newItemEvent = AjaxWizard.NewItemEvent.class.cast(event.getPayload());
        final AjaxRequestTarget target = newItemEvent.getTarget();
        final T item = newItemEvent.getItem();
        final boolean modalPanelAvailable = newItemEvent.getModalPanel() != null || newItemPanelBuilder != null;
        if (event.getPayload() instanceof AjaxWizard.NewItemActionEvent && modalPanelAvailable) {
            final WizardModalPanel<?> modalPanel;
            if (newItemEvent.getModalPanel() == null) {
                newItemPanelBuilder.setItem(item);
                modalPanel = newItemPanelBuilder.build(actualId, ((AjaxWizard.NewItemActionEvent<T>) newItemEvent).getIndex(), item != null ? isReadOnly() ? AjaxWizard.Mode.READONLY : AjaxWizard.Mode.EDIT : AjaxWizard.Mode.CREATE);
            } else {
                modalPanel = newItemEvent.getModalPanel();
            }
            if (wizardInModal) {
                final IModel<T> model = new CompoundPropertyModel<>(item);
                modal.setFormModel(model);
                target.add(modal.setContent(modalPanel));
                modal.header(new StringResourceModel(String.format("any.%s", newItemEvent.getEventDescription()), this, new Model<>(modalPanel.getItem())));
                modal.show(true);
            } else {
                final Fragment fragment = new Fragment("content", "wizard", WizardMgtPanel.this);
                fragment.add(new Label("title", newItemEvent.getResourceModel() == null ? Model.of(StringUtils.EMPTY) : newItemEvent.getResourceModel()));
                fragment.add(Component.class.cast(modalPanel));
                container.addOrReplace(fragment);
            }
            customActionCallback(target);
        } else if (event.getPayload() instanceof AjaxWizard.NewItemCancelEvent) {
            if (wizardInModal) {
                modal.close(target);
            } else {
                container.addOrReplace(initialFragment);
            }
            customActionOnCancelCallback(target);
        } else if (event.getPayload() instanceof AjaxWizard.NewItemFinishEvent) {
            SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
            ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
            if (wizardInModal && showResultPage) {
                modal.setContent(new ResultPage<T>(item, AjaxWizard.NewItemFinishEvent.class.cast(newItemEvent).getResult()) {

                    private static final long serialVersionUID = -2630573849050255233L;

                    @Override
                    protected void closeAction(final AjaxRequestTarget target) {
                        modal.close(target);
                    }

                    @Override
                    protected Panel customResultBody(final String id, final T item, final Serializable result) {
                        return WizardMgtPanel.this.customResultBody(id, item, result);
                    }
                });
                target.add(modal.getForm());
            } else if (wizardInModal) {
                modal.close(target);
            } else {
                container.addOrReplace(initialFragment);
            }
            customActionOnFinishCallback(target);
        }
        if (containerAutoRefresh) {
            target.add(container);
        }
    }
    super.onEvent(event);
}
Also used : IModel(org.apache.wicket.model.IModel) Serializable(java.io.Serializable) Label(org.apache.wicket.markup.html.basic.Label) WizardModalPanel(org.apache.syncope.client.console.panels.WizardModalPanel) Fragment(org.apache.wicket.markup.html.panel.Fragment) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ResultPage(org.apache.syncope.client.console.wizards.any.ResultPage) BasePage(org.apache.syncope.client.console.pages.BasePage) StringResourceModel(org.apache.wicket.model.StringResourceModel)

Example 2 with BasePage

use of org.apache.syncope.client.console.pages.BasePage in project syncope by apache.

the class ApprovalDirectoryPanel method getActions.

@Override
public ActionsPanel<WorkflowFormTO> getActions(final IModel<WorkflowFormTO> model) {
    final ActionsPanel<WorkflowFormTO> panel = super.getActions(model);
    panel.add(new ActionLink<WorkflowFormTO>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final WorkflowFormTO ignore) {
            claimForm(model.getObject().getTaskId());
            SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
            ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
            target.add(container);
        }
    }, ActionLink.ActionType.CLAIM, StandardEntitlement.WORKFLOW_FORM_CLAIM);
    panel.add(new ActionLink<WorkflowFormTO>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final WorkflowFormTO ignore) {
            manageApprovalModal.setFormModel(new CompoundPropertyModel<>(model.getObject()));
            target.add(manageApprovalModal.setContent(new ApprovalModal(manageApprovalModal, pageRef, model.getObject()) {

                private static final long serialVersionUID = 5546519445061007248L;

                @Override
                public void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
                    try {
                        super.onSubmit(target, form);
                        ApprovalDirectoryPanel.this.getTogglePanel().close(target);
                    } catch (SyncopeClientException e) {
                        SyncopeConsoleSession.get().error(getString(Constants.ERROR) + ": " + e.getMessage());
                    }
                    ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
                }
            }));
            manageApprovalModal.header(new Model<>(getString("approval.manage", new Model<>(model.getObject()))));
            manageApprovalModal.show(true);
        }

        @Override
        protected boolean statusCondition(final WorkflowFormTO modelObject) {
            return SyncopeConsoleSession.get().getSelfTO().getUsername().equals(model.getObject().getOwner());
        }
    }, ActionLink.ActionType.MANAGE_APPROVAL, StandardEntitlement.WORKFLOW_FORM_READ);
    // SYNCOPE-1200 edit user while in approval state
    panel.add(new ActionLink<WorkflowFormTO>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final WorkflowFormTO ignore) {
            modal.setFormModel(new CompoundPropertyModel<>(model.getObject()));
            WorkflowFormTO formTO = model.getObject();
            UserTO newUserTO;
            UserTO previousUserTO;
            if (formTO.getUserPatch() == null) {
                newUserTO = formTO.getUserTO();
                previousUserTO = null;
            } else if (formTO.getUserTO() == null) {
                // make it stronger by handling possible NPE
                previousUserTO = new UserTO();
                previousUserTO.setKey(formTO.getUserPatch().getKey());
                newUserTO = AnyOperations.patch(previousUserTO, formTO.getUserPatch());
            } else {
                previousUserTO = formTO.getUserTO();
                formTO.getUserTO().setKey(formTO.getUserPatch().getKey());
                formTO.getUserTO().setPassword(null);
                newUserTO = AnyOperations.patch(formTO.getUserTO(), formTO.getUserPatch());
            }
            AjaxWizard.EditItemActionEvent<UserTO> editItemActionEvent = new AjaxWizard.EditItemActionEvent<>(newUserTO, target);
            editItemActionEvent.forceModalPanel(new ApprovalUserWizardBuilder(model.getObject(), previousUserTO, newUserTO, new AnyTypeRestClient().read(AnyTypeKind.USER.name()).getClasses(), FormLayoutInfoUtils.fetch(Collections.singletonList(AnyTypeKind.USER.name())).getLeft(), pageRef).build(BaseModal.CONTENT_ID, AjaxWizard.Mode.EDIT));
            send(ApprovalDirectoryPanel.this, Broadcast.EXACT, editItemActionEvent);
        }

        @Override
        protected boolean statusCondition(final WorkflowFormTO modelObject) {
            return SyncopeConsoleSession.get().getSelfTO().getUsername().equals(model.getObject().getOwner());
        }
    }, ActionLink.ActionType.EDIT_APPROVAL, StandardEntitlement.WORKFLOW_FORM_SUBMIT);
    return panel;
}
Also used : CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) AjaxWizard(org.apache.syncope.client.console.wizards.AjaxWizard) AnyTypeRestClient(org.apache.syncope.client.console.rest.AnyTypeRestClient) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) WorkflowFormTO(org.apache.syncope.common.lib.to.WorkflowFormTO) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) UserTO(org.apache.syncope.common.lib.to.UserTO) IModel(org.apache.wicket.model.IModel) AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) Model(org.apache.wicket.model.Model) ResourceModel(org.apache.wicket.model.ResourceModel) CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) BasePage(org.apache.syncope.client.console.pages.BasePage)

Example 3 with BasePage

use of org.apache.syncope.client.console.pages.BasePage in project syncope by apache.

the class ExecutionsDirectoryPanel method getActions.

@Override
public ActionsPanel<ExecTO> getActions(final IModel<ExecTO> model) {
    final ActionsPanel<ExecTO> panel = super.getActions(model);
    final ExecTO taskExecutionTO = model.getObject();
    panel.add(new ActionLink<ExecTO>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final ExecTO ignore) {
            ExecutionsDirectoryPanel.this.getTogglePanel().close(target);
            next(new StringResourceModel("execution.view", ExecutionsDirectoryPanel.this, model).getObject(), new ExecMessage(model.getObject().getMessage()), target);
        }
    }, ActionLink.ActionType.VIEW, StandardEntitlement.TASK_READ);
    panel.add(new ActionLink<ExecTO>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final ExecTO ignore) {
            ExecutionsDirectoryPanel.this.getTogglePanel().close(target);
            try {
                restClient.deleteExecution(taskExecutionTO.getKey());
                SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                target.add(container);
            } catch (SyncopeClientException scce) {
                SyncopeConsoleSession.get().error(scce.getMessage());
            }
            ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
        }
    }, ActionLink.ActionType.DELETE, StandardEntitlement.TASK_DELETE, true);
    addFurtherAcions(panel, model);
    return panel;
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ExecTO(org.apache.syncope.common.lib.to.ExecTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) BasePage(org.apache.syncope.client.console.pages.BasePage) StringResourceModel(org.apache.wicket.model.StringResourceModel)

Example 4 with BasePage

use of org.apache.syncope.client.console.pages.BasePage in project syncope by apache.

the class NotificationTaskDirectoryPanel method getActions.

@Override
public ActionsPanel<NotificationTaskTO> getActions(final IModel<NotificationTaskTO> model) {
    final ActionsPanel<NotificationTaskTO> panel = super.getActions(model);
    final NotificationTaskTO taskTO = model.getObject();
    panel.add(new ActionLink<NotificationTaskTO>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final NotificationTaskTO modelObject) {
            viewTask(taskTO, target);
        }
    }, ActionLink.ActionType.VIEW, StandardEntitlement.TASK_READ);
    panel.add(new ActionLink<NotificationTaskTO>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final NotificationTaskTO modelObject) {
            viewMailBody(MailTemplateFormat.TEXT, taskTO.getTextBody(), target);
        }
    }, ActionLink.ActionType.TEXT, StandardEntitlement.TASK_READ);
    panel.add(new ActionLink<NotificationTaskTO>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final NotificationTaskTO modelObject) {
            viewMailBody(MailTemplateFormat.HTML, taskTO.getHtmlBody(), target);
        }
    }, ActionLink.ActionType.HTML, StandardEntitlement.TASK_READ);
    panel.add(new ActionLink<NotificationTaskTO>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final NotificationTaskTO modelObject) {
            try {
                restClient.startExecution(taskTO.getKey(), null);
                SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                target.add(container);
            } catch (SyncopeClientException e) {
                SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
                LOG.error("While running {}", taskTO.getKey(), e);
            }
            ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
        }
    }, ActionLink.ActionType.EXECUTE, StandardEntitlement.TASK_EXECUTE);
    panel.add(new ActionLink<NotificationTaskTO>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final NotificationTaskTO modelObject) {
            try {
                restClient.delete(TaskType.NOTIFICATION, taskTO.getKey());
                updateResultTable(target);
                SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                target.add(container);
            } catch (SyncopeClientException e) {
                LOG.error("While deleting {}", taskTO.getKey(), e);
                SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
            }
            ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
        }
    }, ActionLink.ActionType.DELETE, StandardEntitlement.TASK_DELETE, true);
    return panel;
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) BasePage(org.apache.syncope.client.console.pages.BasePage) NotificationTaskTO(org.apache.syncope.common.lib.to.NotificationTaskTO)

Example 5 with BasePage

use of org.apache.syncope.client.console.pages.BasePage in project syncope by apache.

the class SchedTaskDirectoryPanel method getActions.

@Override
public ActionsPanel<T> getActions(final IModel<T> model) {
    final ActionsPanel<T> panel = super.getActions(model);
    final T taskTO = model.getObject();
    panel.add(new ActionLink<T>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final T ignore) {
            SchedTaskDirectoryPanel.this.getTogglePanel().close(target);
            viewTask(taskTO, target);
        }
    }, ActionLink.ActionType.VIEW, StandardEntitlement.TASK_READ);
    panel.add(new ActionLink<T>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final T ignore) {
            SchedTaskDirectoryPanel.this.getTogglePanel().close(target);
            send(SchedTaskDirectoryPanel.this, Broadcast.EXACT, new AjaxWizard.EditItemActionEvent<>(restClient.readTask(taskType, model.getObject().getKey()), target).setResourceModel(new StringResourceModel("inner.task.edit", SchedTaskDirectoryPanel.this, Model.of(Pair.of(ActionLink.ActionType.EDIT, model.getObject())))));
        }
    }, ActionLink.ActionType.EDIT, StandardEntitlement.TASK_UPDATE);
    panel.add(new ActionLink<T>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final T ignore) {
            SchedTaskDirectoryPanel.this.getTogglePanel().close(target);
            final T clone = SerializationUtils.clone(model.getObject());
            clone.setKey(null);
            send(SchedTaskDirectoryPanel.this, Broadcast.EXACT, new AjaxWizard.EditItemActionEvent<>(clone, target).setResourceModel(new StringResourceModel("inner.task.clone", SchedTaskDirectoryPanel.this, Model.of(Pair.of(ActionLink.ActionType.CLONE, model.getObject())))));
        }
    }, ActionLink.ActionType.CLONE, StandardEntitlement.TASK_CREATE);
    panel.add(new ActionLink<T>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final T ignore) {
            SchedTaskDirectoryPanel.this.getTogglePanel().close(target);
            startAt.setExecutionDetail(model.getObject().getKey(), model.getObject().getName(), target);
            startAt.toggle(target, true);
        }
    }, ActionLink.ActionType.EXECUTE, StandardEntitlement.TASK_EXECUTE);
    addFurtherActions(panel, model);
    panel.add(new ActionLink<T>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        public void onClick(final AjaxRequestTarget target, final T ignore) {
            try {
                restClient.delete(taskType, taskTO.getKey());
                SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                target.add(container);
                SchedTaskDirectoryPanel.this.getTogglePanel().close(target);
            } catch (SyncopeClientException e) {
                SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
                LOG.error("While deleting propagation task {}", taskTO.getKey(), e);
            }
            ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
        }
    }, ActionLink.ActionType.DELETE, StandardEntitlement.TASK_DELETE, true);
    return panel;
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxWizard(org.apache.syncope.client.console.wizards.AjaxWizard) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) BasePage(org.apache.syncope.client.console.pages.BasePage) StringResourceModel(org.apache.wicket.model.StringResourceModel)

Aggregations

BasePage (org.apache.syncope.client.console.pages.BasePage)15 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)14 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)13 StringResourceModel (org.apache.wicket.model.StringResourceModel)8 AnyTypeRestClient (org.apache.syncope.client.console.rest.AnyTypeRestClient)4 AjaxWizard (org.apache.syncope.client.console.wizards.AjaxWizard)4 UserTO (org.apache.syncope.common.lib.to.UserTO)4 IModel (org.apache.wicket.model.IModel)3 ResourceModel (org.apache.wicket.model.ResourceModel)3 Serializable (java.io.Serializable)2 XMLEditorPanel (org.apache.syncope.client.console.wicket.markup.html.form.XMLEditorPanel)2 GroupTO (org.apache.syncope.common.lib.to.GroupTO)2 Form (org.apache.wicket.markup.html.form.Form)2 CompoundPropertyModel (org.apache.wicket.model.CompoundPropertyModel)2 IOException (java.io.IOException)1 ExtPage (org.apache.syncope.client.console.annotations.ExtPage)1 ExtWidget (org.apache.syncope.client.console.annotations.ExtWidget)1 ConsoleLayoutInfo (org.apache.syncope.client.console.layout.ConsoleLayoutInfo)1 UserFormLayoutInfo (org.apache.syncope.client.console.layout.UserFormLayoutInfo)1 NotificationTasks (org.apache.syncope.client.console.notifications.NotificationTasks)1