Skip to content

Commit

Permalink
create toast component as PoC
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Jun 1, 2022
1 parent f44919e commit 3a1093f
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected List<WizardPanel> createSteps() {
}

private List<WizardPanel> createSteps(WizardBorder border) {
PersonOfInterestPanel personOfInterest = new PersonOfInterestPanel(ID_PERSON_OF_INTEREST) {
PersonOfInterestPanel personOfInterest = new PersonOfInterestPanel(ID_PERSON_OF_INTEREST, border.getModel(), model) {

@Override
protected void onNextPerformed(AjaxRequestTarget target) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.apache.wicket.model.IModel;

import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.gui.api.component.wizard.Wizard;
import com.evolveum.midpoint.gui.api.component.wizard.WizardPanel;
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.web.component.util.VisibleBehaviour;
Expand Down Expand Up @@ -58,15 +59,28 @@ public String getIcon() {
private static final String ID_NEXT = "next";
private static final String ID_NEXT_LABEL = "nextLabel";

private IModel<Wizard> wizard;

private IModel<RequestAccess> model;
private IModel<List<Tile>> tiles;

public PersonOfInterestPanel(String id) {
public PersonOfInterestPanel(String id, IModel<Wizard> wizard, IModel<RequestAccess> model) {
super(id);

this.wizard = wizard;
this.model = model;

initModels();
initLayout();
}

// @Override
// protected void onBeforeRender() {
// super.onBeforeRender();
//
// wizard.getObject().nextStep();
// }

@Override
public VisibleEnableBehaviour getHeaderBehaviour() {
return new VisibleEnableBehaviour(() -> false);
Expand Down Expand Up @@ -156,6 +170,11 @@ protected IModel<String> createNextStepLabel() {
}

protected void onBackPerformed(AjaxRequestTarget target) {

new Toast()
.title("some title")
.body("example body " + 1000 * Math.random())
.cssClass("bg-success")
.autohide(true)
.show(target);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* Copyright (c) 2022 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.gui.impl.page.self.requestAccess;

import java.io.Serializable;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.jetbrains.annotations.NotNull;

import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;

/**
* Created by Viliam Repan (lazyman).
*/
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Toast implements Serializable {

private static final Trace LOGGER = TraceManager.getTrace(Toast.class);

private String icon;

private String title;

private String subtitle;

private Boolean close;

private String body;

private Boolean autohide;

private Integer delay;

@JsonProperty("class")
private String cssClass;

public String icon() {
return icon;
}

public String title() {
return title;
}

public String subtitle() {
return subtitle;
}

public Boolean close() {
return close;
}

public String body() {
return body;
}

public String cssClass() {
return cssClass;
}

public Boolean autohide() {
return autohide;
}

public Integer delay() {
return delay;
}

public Toast icon(String icon) {
this.icon = icon;
return this;
}

public Toast title(String title) {
this.title = title;
return this;
}

public Toast subtitle(String subtitle) {
this.subtitle = subtitle;
return this;
}

public Toast close(Boolean close) {
this.close = close;
return this;
}

public Toast body(String body) {
this.body = body;
return this;
}

public Toast cssClass(String cssClass) {
this.cssClass = cssClass;
return this;
}

public Toast autohide(Boolean autohide) {
this.autohide = autohide;
return this;
}

public Toast delay(Integer delay) {
this.delay = delay;
return this;
}

public void show(@NotNull AjaxRequestTarget target) {
try {
ObjectMapper mapper = new ObjectMapper();
String toast = mapper.writeValueAsString(this);

target.appendJavaScript("$(document).Toasts('create', " + toast + ");");
} catch (Exception ex) {
target.appendJavaScript("console.error('Couldn't create toast, reason: " + ex.getMessage() + "');");
LOGGER.debug("Couldn't create toast", ex);
}
}
}

0 comments on commit 3a1093f

Please sign in to comment.