Skip to content

The Unified and Autonomous Development Platform

Add simplified version of modal panel

robin shine48d695e4e98f
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/common.js b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/common.js
index 8efc484566..0032691fc6 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/common.js
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/common.js
@@ -6,85 +6,10 @@
var pmease = {};
pmease.commons = {
- modal: {
- setupTrigger: function(triggerId, modalId, contentLoader) {
- var trigger = $("#" + triggerId);
- var modal = $("#" + modalId);
-
- // This script can still be called if CollapseBehavior is added to a
- // a component enclosed in an invisible wicket:enclosure. So we
- // should check if relevant element exists.
- if (!trigger[0] || !modal[0])
- return;
-
- $("#" + triggerId).click(function() {
- pmease.commons.modal.show(modalId, contentLoader);
- });
- },
-
- setup: function(modalId, contentUnloader, showImmediately) {
- var $modal = $("#" + modalId);
-
- // This script can still be called if CollapseBehavior is added to a
- // a component enclosed in an invisible wicket:enclosure. So we
- // should check if relevant element exists.
- if ($modal.length == 0)
- return;
-
- $modal[0].contentUnloader = contentUnloader;
-
- if (!document.getElementById(modalId + "-placeholder"))
- $modal.before("<div id='" + modalId + "-placeholder' class='hide'></div>");
- $modal.modal({backdrop: "static", keyboard: false, show: false});
- if (showImmediately)
- pmease.commons.modal.show(modalId, undefined);
- },
-
- show: function(modalId, contentLoader) {
- var modal = $("#" + modalId);
- $("body").append(modal);
-
- modal.modal("show");
-
- pmease.commons.modal.afterShow(modal);
-
- if (contentLoader && !modal.find(">.modal-dialog>.content")[0])
- contentLoader();
- else
- modal.find("input[type=text], input[type=textarea]").filter(":visible:first").focus();
- },
-
- afterShow: function(modal) {
- var backdrop = $(".modal-backdrop:last");
- var prevPopup = modal.prevAll(".popup:visible");
-
- if (prevPopup[0]) {
- var prevPopupZIndex = parseInt(prevPopup.css("z-index"));
- var backdropZIndex = prevPopupZIndex + 10;
- backdrop.css("z-index", backdropZIndex);
- modal.css("z-index", backdropZIndex + 10);
- }
- },
-
- loaded: function(modalId) {
- $("#" + modalId).find("input[type=text], input[type=textarea]").filter(":visible:first").focus();
- },
-
- hide: function(modalId, callFromServerSide) {
- var $modal = $("#" + modalId);
- $modal.modal("hide");
- $("#" + modalId + "-placeholder").after($modal);
-
- if (callFromServerSide !== true && $modal[0].contentUnloader)
- $modal[0].contentUnloader();
- }
-
- },
-
confirm: {
show: function(trigger, message, callback) {
var html =
- "<div class='modal popup'><div class='modal-dialog'><div class='modal-content'>" +
+ "<div class='modal'><div class='modal-dialog'><div class='modal-content'>" +
" <div class='modal-body'>" +
" <p>" + message + "</p>" +
" </div>" +
@@ -97,6 +22,7 @@ pmease.commons = {
var modal = $(html);
$("body").append(modal);
+
modal[0].confirm = {};
modal[0].confirm.trigger= trigger[0];
modal[0].confirm.callback = callback;
@@ -109,8 +35,6 @@ pmease.commons = {
trigger.blur();
modal.modal({keyboard: false, backdrop: "static"});
-
- pmease.commons.modal.afterShow(modal);
},
setup: function(triggerId, message) {
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/floating/FloatingPanel.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/floating/FloatingPanel.java
index dd4e6f50ff..f411c7304a 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/floating/FloatingPanel.java
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/floating/FloatingPanel.java
@@ -9,7 +9,6 @@ import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.head.JavaScriptHeaderItem;
import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
import org.apache.wicket.markup.html.panel.Panel;
-import org.apache.wicket.model.IModel;
import org.apache.wicket.request.resource.CssResourceReference;
import org.apache.wicket.request.resource.JavaScriptResourceReference;
@@ -29,12 +28,7 @@ public abstract class FloatingPanel extends Panel {
private final Alignment alignment;
public FloatingPanel(AjaxRequestTarget target, AlignWith alignWith, Alignment alignment) {
- this(target, null, alignWith, alignment);
- }
-
- public FloatingPanel(AjaxRequestTarget target, IModel<?> model,
- AlignWith alignWith, Alignment alignment) {
- super(((CommonPage)target.getPage()).getStandalones().newChildId(), model);
+ super(((CommonPage)target.getPage()).getStandalones().newChildId());
CommonPage page = (CommonPage) target.getPage();
page.getStandalones().add(this);
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/modal/ModalPanel.html b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/modal/ModalPanel.html
new file mode 100644
index 0000000000..5a44fe42a6
--- /dev/null
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/modal/ModalPanel.html
@@ -0,0 +1,7 @@
+<wicket:panel>
+ <div class="modal">
+ <div wicket:id="dialog" class="modal-dialog">
+ <div wicket:id="content" class="modal-content"></div>
+ </div>
+ </div>
+</wicket:panel>
\ No newline at end of file
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/modal/ModalPanel.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/modal/ModalPanel.java
new file mode 100644
index 0000000000..f80ae19a06
--- /dev/null
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/modal/ModalPanel.java
@@ -0,0 +1,98 @@
+package com.pmease.commons.wicket.component.modal;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.behavior.AttributeAppender;
+import org.apache.wicket.markup.head.IHeaderResponse;
+import org.apache.wicket.markup.head.JavaScriptHeaderItem;
+import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.panel.Panel;
+import org.apache.wicket.request.resource.JavaScriptResourceReference;
+
+import com.pmease.commons.wicket.CommonPage;
+
+@SuppressWarnings("serial")
+public abstract class ModalPanel extends Panel {
+
+ public enum Size {SMALL, MEDIUM, LARGE}
+
+ private static final String CONTENT_ID = "content";
+
+ private final Size size;
+
+ public ModalPanel(AjaxRequestTarget target) {
+ this(target, Size.MEDIUM);
+ }
+
+ public ModalPanel(AjaxRequestTarget target, Size size) {
+ super(((CommonPage)target.getPage()).getStandalones().newChildId());
+
+ this.size = size;
+
+ CommonPage page = (CommonPage) target.getPage();
+ page.getStandalones().add(this);
+ target.prependJavaScript(String.format("$('body').append(\"<div id='%s'></div>\");", getMarkupId()));
+ target.add(this);
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ WebMarkupContainer dialog = new WebMarkupContainer("dialog");
+ add(dialog);
+
+ dialog.add(newContent(CONTENT_ID));
+
+ if (size == Size.LARGE)
+ dialog.add(AttributeAppender.append("class", "modal-lg"));
+ else if (size == Size.SMALL)
+ dialog.add(AttributeAppender.append("class", "modal-sm"));
+
+ add(new AbstractDefaultAjaxBehavior() {
+
+ @Override
+ protected void respond(AjaxRequestTarget target) {
+ ModalPanel.this.remove();
+ onClosed(target);
+ }
+
+ @Override
+ public void renderHead(Component component, IHeaderResponse response) {
+ super.renderHead(component, response);
+
+ response.render(JavaScriptHeaderItem.forReference(
+ new JavaScriptResourceReference(ModalPanel.class, "modal.js")));
+
+ String script = String.format("pmease.commons.modal.init('%s', %s);",
+ getMarkupId(true), getCallbackFunction());
+ response.render(OnDomReadyHeaderItem.forScript(script));
+ }
+
+ });
+
+ setOutputMarkupId(true);
+ }
+
+ protected abstract Component newContent(String id);
+
+ public Component getContent() {
+ return get(CONTENT_ID);
+ }
+
+ public final void close(AjaxRequestTarget target) {
+ String script = String.format("pmease.commons.modal.close($('#%s>.modal'), false);", getMarkupId(true));
+ target.appendJavaScript(script);
+
+ remove();
+
+ onClosed(target);
+ }
+
+ protected void onClosed(AjaxRequestTarget target) {
+
+ }
+
+}
\ No newline at end of file
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/modal/modal.js b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/modal/modal.js
new file mode 100644
index 0000000000..344ca68e2c
--- /dev/null
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/modal/modal.js
@@ -0,0 +1,26 @@
+pmease.commons.modal = {
+ init: function(containerId, closeCallback) {
+ var $modal = $("#" + containerId + ">.modal");
+ $modal.data("closeCallback", closeCallback);
+
+ $modal.data("keydown", function(e) {
+ if (e.keyCode == 27 && $(".select2-drop:visible").length == 0 && $("body>.floating").length == 0)
+ pmease.commons.modal.close($modal, true);
+ });
+
+ // use keydown as keypress does not work in chrome/safari
+ $(document).on("keydown", $modal.data("keydown"));
+
+ $modal.modal({backdrop: "static"});
+ },
+
+ close: function($modal, callCloseCallback) {
+ if (callCloseCallback)
+ $modal.data("closeCallback")();
+
+ $(document).off("keydown", $modal.data("keydown"));
+
+ $modal.modal("hide").parent().remove();
+ }
+
+}
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/base/base.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/base/base.css
index 7fc12a93b2..2bf7fb060d 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/base/base.css
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/base/base.css
@@ -97,4 +97,4 @@ img.avatar {
border-radius: 3px;
height: 24px;
width: 24px;
-}
\ No newline at end of file
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.html
index ca786c0f28..96a43fadda 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.html
@@ -1,7 +1,14 @@
<wicket:extend>
- <a wicket:id="test" style="position: absolute; left: 400px; top: 200px;">test</a>
+ <a wicket:id="test">test</a>
<wicket:fragment wicket:id="contentFrag">
- <a wicket:id="more">more</a>
- <div wicket:id="lines"></div>
+ <div class="modal-header">
+ <h4>Title</h4>
+ </div>
+ <div class="modal-body">
+ hello world
+ </div>
+ <div class="modal-footer">
+ <a wicket:id="close" class="btn btn-default">Close</a>
+ </div>
</wicket:fragment>
</wicket:extend>
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.java
index d5c9e627de..c04e24dbe0 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.java
@@ -1,5 +1,11 @@
package com.pmease.gitplex.web.page.test;
+import org.apache.wicket.Component;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.markup.html.AjaxLink;
+import org.apache.wicket.markup.html.panel.Fragment;
+
+import com.pmease.commons.wicket.component.modal.ModalPanel;
import com.pmease.gitplex.web.page.base.BasePage;
@SuppressWarnings("serial")
@@ -9,6 +15,30 @@ public class TestPage extends BasePage {
protected void onInitialize() {
super.onInitialize();
+ add(new AjaxLink<Void>("test") {
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ new ModalPanel(target, ModalPanel.Size.SMALL) {
+
+ @Override
+ protected Component newContent(String id) {
+ Fragment fragment = new Fragment(id, "contentFrag", TestPage.this);
+ fragment.add(new AjaxLink<Void>("close") {
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ close(target);
+ }
+
+ });
+ return fragment;
+ }
+
+ };
+ }
+
+ });
}
}