Repository: syncope Updated Branches: refs/heads/SYNCOPE-156 af8f263bf -> 21262a6f3
[SYNCOPE-156] Add confirm dialog Project: http://git-wip-us.apache.org/repos/asf/syncope/repo Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/21262a6f Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/21262a6f Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/21262a6f Branch: refs/heads/SYNCOPE-156 Commit: 21262a6f3c87bd4c4aebe07400ed8bac78b06239 Parents: af8f263 Author: Marco Di Sabatino Di Diodoro <[email protected]> Authored: Wed Sep 30 11:14:46 2015 +0200 Committer: Marco Di Sabatino Di Diodoro <[email protected]> Committed: Wed Sep 30 11:14:46 2015 +0200 ---------------------------------------------------------------------- client/console/pom.xml | 4 ++ .../syncope/client/console/pages/Realms.java | 10 ++- .../confirmation/ConfirmationModalBehavior.java | 70 ++++++++++++++++++++ .../markup/html/form/ActionLinksPanel.java | 1 - .../html/form/IndicatingOnConfirmAjaxLink.java | 26 ++------ .../syncope/client/console/pages/BasePage.html | 2 + .../syncope/client/console/pages/Realms.html | 8 +-- pom.xml | 6 ++ 8 files changed, 97 insertions(+), 30 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/syncope/blob/21262a6f/client/console/pom.xml ---------------------------------------------------------------------- diff --git a/client/console/pom.xml b/client/console/pom.xml index 759ba78..fb78280 100644 --- a/client/console/pom.xml +++ b/client/console/pom.xml @@ -108,6 +108,10 @@ under the License. </dependency> <dependency> <groupId>org.webjars</groupId> + <artifactId>bootbox</artifactId> + </dependency> + <dependency> + <groupId>org.webjars</groupId> <artifactId>highlightjs</artifactId> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/syncope/blob/21262a6f/client/console/src/main/java/org/apache/syncope/client/console/pages/Realms.java ---------------------------------------------------------------------- diff --git a/client/console/src/main/java/org/apache/syncope/client/console/pages/Realms.java b/client/console/src/main/java/org/apache/syncope/client/console/pages/Realms.java index 3c5f0ea..300db13 100644 --- a/client/console/src/main/java/org/apache/syncope/client/console/pages/Realms.java +++ b/client/console/src/main/java/org/apache/syncope/client/console/pages/Realms.java @@ -28,6 +28,7 @@ import org.apache.syncope.client.console.panels.RealmSidebarPanel; import org.apache.syncope.client.console.panels.RealmSidebarPanel.ControlSidebarClick; import org.apache.syncope.client.console.rest.RealmRestClient; import org.apache.syncope.client.console.wicket.ajax.markup.html.ClearIndicatingAjaxLink; +import org.apache.syncope.client.console.wicket.markup.html.bootstrap.confirmation.ConfirmationModalBehavior; import org.apache.syncope.client.console.wicket.markup.html.bootstrap.dialog.BaseModal; import org.apache.syncope.common.lib.to.RealmTO; import org.apache.syncope.common.lib.types.Entitlement; @@ -119,12 +120,13 @@ public class Realms extends BasePage { private void setupDeleteLink() { - final AjaxLink<Void> deleteLink = new ClearIndicatingAjaxLink<Void>("deleteLink", getPageReference()) { + @SuppressWarnings("unchecked") + final AjaxLink<Void> deleteLink = new AjaxLink("deleteLink", Model.of("deleteLink")) { - private static final long serialVersionUID = -7978723352517770644L; + private static final long serialVersionUID = 3776750333491622263L; @Override - protected void onClickInternal(final AjaxRequestTarget target) { + public void onClick(final AjaxRequestTarget target) { try { final RealmTO toBeDeleted = realmSidebarPanel.getCurrentRealm(); @@ -147,6 +149,8 @@ public class Realms extends BasePage { } }; + deleteLink.add(new ConfirmationModalBehavior()); + if (SyncopeConsoleSession.get().owns(Entitlement.REALM_DELETE)) { MetaDataRoleAuthorizationStrategy.authorize(deleteLink, ENABLE, Entitlement.REALM_DELETE); } http://git-wip-us.apache.org/repos/asf/syncope/blob/21262a6f/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/bootstrap/confirmation/ConfirmationModalBehavior.java ---------------------------------------------------------------------- diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/bootstrap/confirmation/ConfirmationModalBehavior.java b/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/bootstrap/confirmation/ConfirmationModalBehavior.java new file mode 100644 index 0000000..7996766 --- /dev/null +++ b/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/bootstrap/confirmation/ConfirmationModalBehavior.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.console.wicket.markup.html.bootstrap.confirmation; + +import static de.agilecoders.wicket.jquery.JQuery.$; + +import de.agilecoders.wicket.jquery.function.JavaScriptInlineFunction; +import org.apache.wicket.Component; +import org.apache.wicket.behavior.Behavior; +import org.apache.wicket.markup.head.IHeaderResponse; +import org.apache.wicket.markup.head.JavaScriptHeaderItem; +import org.apache.wicket.model.ResourceModel; + +/** + * A behavior that shows a modal with OK/Cancel buttons to confirm an action. + * + */ +public class ConfirmationModalBehavior extends Behavior { + + private static final long serialVersionUID = 1741536820040325586L; + + private final String message; + + public ConfirmationModalBehavior() { + this("confirmDelete"); + } + + public ConfirmationModalBehavior(final String msg) { + message = new ResourceModel(msg, "Are you sure?").getObject(); + } + + @Override + public void renderHead(final Component component, final IHeaderResponse response) { + super.renderHead(component, response); + + response.render(JavaScriptHeaderItem.forScript("var confirm = false;", null)); + response.render($(component).on("click", + new JavaScriptInlineFunction("" + + "var element = $(this);" + + "evt.preventDefault();" + + "if(confirm == false){" + + "evt.stopImmediatePropagation();" + + "bootbox.confirm(\"" + message + "\", function(result){" + + "if(result == true){" + + "confirm = true;" + + "element.click();" + + "}" + + "else{confirm = false;}" + + "return true;" + + "})} " + + "else {confirm = false;};" + )).asDomReadyScript()); + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/21262a6f/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/ActionLinksPanel.java ---------------------------------------------------------------------- diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/ActionLinksPanel.java b/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/ActionLinksPanel.java index 3986090..8ad55f6 100644 --- a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/ActionLinksPanel.java +++ b/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/ActionLinksPanel.java @@ -25,7 +25,6 @@ import java.util.Map.Entry; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Triple; import org.apache.syncope.client.console.wicket.ajax.markup.html.ClearIndicatingAjaxLink; -import org.apache.syncope.client.console.wicket.ajax.markup.html.IndicatingOnConfirmAjaxLink; import org.apache.wicket.PageReference; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.authroles.authorization.strategies.role.metadata.MetaDataRoleAuthorizationStrategy; http://git-wip-us.apache.org/repos/asf/syncope/blob/21262a6f/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/IndicatingOnConfirmAjaxLink.java ---------------------------------------------------------------------- diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/IndicatingOnConfirmAjaxLink.java b/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/IndicatingOnConfirmAjaxLink.java index 86db915..4aea243 100644 --- a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/IndicatingOnConfirmAjaxLink.java +++ b/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/IndicatingOnConfirmAjaxLink.java @@ -16,12 +16,11 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.syncope.client.console.wicket.ajax.markup.html; +package org.apache.syncope.client.console.wicket.markup.html.form; -import org.apache.wicket.Component; +import org.apache.syncope.client.console.wicket.ajax.markup.html.ClearIndicatingAjaxLink; +import org.apache.syncope.client.console.wicket.markup.html.bootstrap.confirmation.ConfirmationModalBehavior; import org.apache.wicket.PageReference; -import org.apache.wicket.ajax.attributes.AjaxCallListener; -import org.apache.wicket.ajax.attributes.AjaxRequestAttributes; public abstract class IndicatingOnConfirmAjaxLink<T> extends ClearIndicatingAjaxLink<T> { @@ -36,23 +35,6 @@ public abstract class IndicatingOnConfirmAjaxLink<T> extends ClearIndicatingAjax public IndicatingOnConfirmAjaxLink(final String id, final PageReference pageRef, final String msg) { super(id, pageRef); this.msg = msg; - } - - @Override - protected void updateAjaxAttributes(final AjaxRequestAttributes attributes) { - super.updateAjaxAttributes(attributes); - - final AjaxCallListener ajaxCallListener = new AjaxCallListener() { - - private static final long serialVersionUID = 7160235486520935153L; - - @Override - public CharSequence getPrecondition(final Component component) { - return "if (!confirm('" - + getString(IndicatingOnConfirmAjaxLink.this.msg) - + "')) {return false;} else {return true;}"; - } - }; - attributes.getAjaxCallListeners().add(ajaxCallListener); + this.add(new ConfirmationModalBehavior(msg)); } } http://git-wip-us.apache.org/repos/asf/syncope/blob/21262a6f/client/console/src/main/resources/org/apache/syncope/client/console/pages/BasePage.html ---------------------------------------------------------------------- diff --git a/client/console/src/main/resources/org/apache/syncope/client/console/pages/BasePage.html b/client/console/src/main/resources/org/apache/syncope/client/console/pages/BasePage.html index 790c201..e74af55 100644 --- a/client/console/src/main/resources/org/apache/syncope/client/console/pages/BasePage.html +++ b/client/console/src/main/resources/org/apache/syncope/client/console/pages/BasePage.html @@ -32,6 +32,8 @@ under the License. <link href="css/AdminLTE_skins/skin-green.css" rel="stylesheet" type="text/css" /> <link href="css/syncopeConsole.css" rel="stylesheet" type="text/css" /> <link href="css/fieldstyle.css" rel="stylesheet" type="text/css" /> + + <script type="text/javascript" src="webjars/bootbox/${bootbox.version}/bootbox.js"></script> <script type="text/javascript"> var notificationShownTimes = 0; http://git-wip-us.apache.org/repos/asf/syncope/blob/21262a6f/client/console/src/main/resources/org/apache/syncope/client/console/pages/Realms.html ---------------------------------------------------------------------- diff --git a/client/console/src/main/resources/org/apache/syncope/client/console/pages/Realms.html b/client/console/src/main/resources/org/apache/syncope/client/console/pages/Realms.html index 890db34..47c136e 100644 --- a/client/console/src/main/resources/org/apache/syncope/client/console/pages/Realms.html +++ b/client/console/src/main/resources/org/apache/syncope/client/console/pages/Realms.html @@ -29,19 +29,19 @@ under the License. <div class="box-tools pull-right"> <ul class="nav navbar-nav actions"> <li> - <a href="#" wicket:id="editLink"> + <a wicket:id="editLink"> <i class="fa fa-pencil-square-o"></i> </a> </li> <li> - <a href="#" wicket:id="createLink"> + <a wicket:id="createLink"> <i class="fa fa-plus"></i> </a> </li> <li> - <a href="#" wicket:id="deleteLink"> + <a wicket:id="deleteLink" data-bb="confirm"> <i class="fa fa-minus"></i> - </a> + </a> </li> </ul> </div><!-- /.box-tools --> http://git-wip-us.apache.org/repos/asf/syncope/blob/21262a6f/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index df64cc1..495ce10 100644 --- a/pom.xml +++ b/pom.xml @@ -377,6 +377,7 @@ under the License. <bootstrap.version>3.3.5</bootstrap.version> <wicket-bootstrap.version>0.10.4-SNAPSHOT</wicket-bootstrap.version> + <bootbox.version>4.4.0</bootbox.version> <font-awesome.version>4.4.0</font-awesome.version> <ionicons.version>2.0.1</ionicons.version> @@ -953,6 +954,11 @@ under the License. </dependency> <dependency> <groupId>org.webjars</groupId> + <artifactId>bootbox</artifactId> + <version>${bootbox.version}</version> + </dependency> + <dependency> + <groupId>org.webjars</groupId> <artifactId>ionicons</artifactId> <version>${ionicons.version}</version> </dependency>
