syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject [1/2] syncope git commit: [SYNCOPE-819] Delete confirmation now works everywhere
Date Thu, 07 Apr 2016 08:40:36 GMT
Repository: syncope
Updated Branches:
  refs/heads/master 7300ccdf3 -> 0016d10c9


[SYNCOPE-819] Delete confirmation now works everywhere


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/27dae836
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/27dae836
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/27dae836

Branch: refs/heads/master
Commit: 27dae836f910977a640d9a1506dc0971dc1cb745
Parents: 7300ccd
Author: Francesco Chicchiriccò <ilgrosso@apache.org>
Authored: Thu Apr 7 10:08:03 2016 +0200
Committer: Francesco Chicchiriccò <ilgrosso@apache.org>
Committed: Thu Apr 7 10:08:03 2016 +0200

----------------------------------------------------------------------
 .../console/topology/TopologyTogglePanel.java   | 50 ++++++--------
 .../confirmation/ConfirmationModalBehavior.java | 70 --------------------
 .../html/form/IndicatingOnConfirmAjaxLink.java  | 37 ++++++++++-
 .../syncope/client/console/pages/BasePage.html  |  4 ++
 4 files changed, 60 insertions(+), 101 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/27dae836/client/console/src/main/java/org/apache/syncope/client/console/topology/TopologyTogglePanel.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/topology/TopologyTogglePanel.java
b/client/console/src/main/java/org/apache/syncope/client/console/topology/TopologyTogglePanel.java
index 30df39b..22ec34b 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/topology/TopologyTogglePanel.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/topology/TopologyTogglePanel.java
@@ -33,8 +33,8 @@ import org.apache.syncope.client.console.tasks.PropagationTasks;
 import org.apache.syncope.client.console.tasks.PushTasks;
 import org.apache.syncope.client.console.tasks.SchedTasks;
 import org.apache.syncope.client.console.tasks.PullTasks;
-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.client.console.wicket.markup.html.form.IndicatingOnConfirmAjaxLink;
 import org.apache.syncope.common.lib.SyncopeClientException;
 import org.apache.syncope.common.lib.to.ConnInstanceTO;
 import org.apache.syncope.common.lib.to.ResourceTO;
@@ -173,9 +173,9 @@ public class TopologyTogglePanel extends TogglePanel<Serializable>
{
     }
 
     private Fragment getConnectorFragment(final TopologyNode node, final PageReference pageRef)
{
-        final Fragment fragment = new Fragment("actions", "connectorActions", this);
+        Fragment fragment = new Fragment("actions", "connectorActions", this);
 
-        final AjaxLink<String> delete = new IndicatingAjaxLink<String>("delete")
{
+        AjaxLink<String> delete = new IndicatingOnConfirmAjaxLink<String>("delete",
true) {
 
             private static final long serialVersionUID = 3776750333491622263L;
 
@@ -186,19 +186,16 @@ public class TopologyTogglePanel extends TogglePanel<Serializable>
{
                     target.appendJavaScript(String.format("jsPlumb.remove('%s');", node.getKey()));
                     info(getString(Constants.OPERATION_SUCCEEDED));
                 } catch (SyncopeClientException e) {
-                    error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() :
e.getMessage());
                     LOG.error("While deleting resource {}", node.getKey(), e);
+                    error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() :
e.getMessage());
                 }
                 SyncopeConsoleSession.get().getNotificationPanel().refresh(target);
             }
         };
-
-        fragment.add(delete);
-        delete.add(new ConfirmationModalBehavior());
-
         MetaDataRoleAuthorizationStrategy.authorize(delete, ENABLE, StandardEntitlement.CONNECTOR_DELETE);
+        fragment.add(delete);
 
-        final AjaxLink<String> create = new IndicatingAjaxLink<String>("create")
{
+        AjaxLink<String> create = new IndicatingAjaxLink<String>("create") {
 
             private static final long serialVersionUID = 3776750333491622263L;
 
@@ -221,11 +218,10 @@ public class TopologyTogglePanel extends TogglePanel<Serializable>
{
                 resourceModal.show(true);
             }
         };
-        fragment.add(create);
-
         MetaDataRoleAuthorizationStrategy.authorize(create, ENABLE, StandardEntitlement.RESOURCE_CREATE);
+        fragment.add(create);
 
-        final AjaxLink<String> edit = new IndicatingAjaxLink<String>("edit")
{
+        AjaxLink<String> edit = new IndicatingAjaxLink<String>("edit") {
 
             private static final long serialVersionUID = 3776750333491622263L;
 
@@ -246,17 +242,16 @@ public class TopologyTogglePanel extends TogglePanel<Serializable>
{
                 resourceModal.show(true);
             }
         };
-        fragment.add(edit);
-
         MetaDataRoleAuthorizationStrategy.authorize(edit, ENABLE, StandardEntitlement.CONNECTOR_UPDATE);
+        fragment.add(edit);
 
         return fragment;
     }
 
     private Fragment getResurceFragment(final TopologyNode node, final PageReference pageRef)
{
-        final Fragment fragment = new Fragment("actions", "resourceActions", this);
+        Fragment fragment = new Fragment("actions", "resourceActions", this);
 
-        final AjaxLink<String> delete = new IndicatingAjaxLink<String>("delete")
{
+        AjaxLink<String> delete = new IndicatingOnConfirmAjaxLink<String>("delete",
true) {
 
             private static final long serialVersionUID = 3776750333491622263L;
 
@@ -267,19 +262,16 @@ public class TopologyTogglePanel extends TogglePanel<Serializable>
{
                     target.appendJavaScript(String.format("jsPlumb.remove('%s');", node.getKey()));
                     info(getString(Constants.OPERATION_SUCCEEDED));
                 } catch (SyncopeClientException e) {
-                    error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() :
e.getMessage());
                     LOG.error("While deleting resource {}", node.getKey(), e);
+                    error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() :
e.getMessage());
                 }
                 SyncopeConsoleSession.get().getNotificationPanel().refresh(target);
             }
         };
-        fragment.add(delete);
-
-        delete.add(new ConfirmationModalBehavior());
-
         MetaDataRoleAuthorizationStrategy.authorize(delete, ENABLE, StandardEntitlement.RESOURCE_DELETE);
+        fragment.add(delete);
 
-        final AjaxLink<String> edit = new IndicatingAjaxLink<String>("edit")
{
+        AjaxLink<String> edit = new IndicatingAjaxLink<String>("edit") {
 
             private static final long serialVersionUID = 3776750333491622263L;
 
@@ -300,10 +292,10 @@ public class TopologyTogglePanel extends TogglePanel<Serializable>
{
                 resourceModal.show(true);
             }
         };
-        fragment.add(edit);
         MetaDataRoleAuthorizationStrategy.authorize(edit, ENABLE, StandardEntitlement.RESOURCE_UPDATE);
+        fragment.add(edit);
 
-        final AjaxLink<String> propagation = new IndicatingAjaxLink<String>("propagation")
{
+        AjaxLink<String> propagation = new IndicatingAjaxLink<String>("propagation")
{
 
             private static final long serialVersionUID = 3776750333491622263L;
 
@@ -315,10 +307,10 @@ public class TopologyTogglePanel extends TogglePanel<Serializable>
{
                 taskModal.show(true);
             }
         };
-        fragment.add(propagation);
         MetaDataRoleAuthorizationStrategy.authorize(propagation, ENABLE, StandardEntitlement.TASK_LIST);
+        fragment.add(propagation);
 
-        final AjaxLink<String> pull = new IndicatingAjaxLink<String>("pull")
{
+        AjaxLink<String> pull = new IndicatingAjaxLink<String>("pull") {
 
             private static final long serialVersionUID = 3776750333491622263L;
 
@@ -329,10 +321,10 @@ public class TopologyTogglePanel extends TogglePanel<Serializable>
{
                 taskModal.show(true);
             }
         };
-        fragment.add(pull);
         MetaDataRoleAuthorizationStrategy.authorize(pull, ENABLE, StandardEntitlement.TASK_LIST);
+        fragment.add(pull);
 
-        final AjaxLink<String> push = new IndicatingAjaxLink<String>("push")
{
+        AjaxLink<String> push = new IndicatingAjaxLink<String>("push") {
 
             private static final long serialVersionUID = 3776750333491622263L;
 
@@ -343,8 +335,8 @@ public class TopologyTogglePanel extends TogglePanel<Serializable>
{
                 taskModal.show(true);
             }
         };
-        fragment.add(push);
         MetaDataRoleAuthorizationStrategy.authorize(push, ENABLE, StandardEntitlement.TASK_LIST);
+        fragment.add(push);
 
         return fragment;
     }

http://git-wip-us.apache.org/repos/asf/syncope/blob/27dae836/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
deleted file mode 100644
index 7996766..0000000
--- a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/bootstrap/confirmation/ConfirmationModalBehavior.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * 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/27dae836/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 98b3541..53ab39c 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
@@ -18,8 +18,13 @@
  */
 package org.apache.syncope.client.console.wicket.markup.html.form;
 
-import org.apache.syncope.client.console.wicket.markup.html.bootstrap.confirmation.ConfirmationModalBehavior;
+import static de.agilecoders.wicket.jquery.JQuery.$;
+
+import de.agilecoders.wicket.jquery.function.JavaScriptInlineFunction;
 import org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxLink;
+import org.apache.wicket.markup.head.IHeaderResponse;
+import org.apache.wicket.markup.head.JavaScriptHeaderItem;
+import org.apache.wicket.model.ResourceModel;
 
 public abstract class IndicatingOnConfirmAjaxLink<T> extends IndicatingAjaxLink<T>
{
 
@@ -27,6 +32,8 @@ public abstract class IndicatingOnConfirmAjaxLink<T> extends IndicatingAjaxLink<
 
     private final String msg;
 
+    private final boolean enabled;
+
     public IndicatingOnConfirmAjaxLink(final String id, final boolean enabled) {
         this(id, "confirmDelete", enabled);
     }
@@ -34,8 +41,34 @@ public abstract class IndicatingOnConfirmAjaxLink<T> extends IndicatingAjaxLink<
     public IndicatingOnConfirmAjaxLink(final String id, final String msg, final boolean enabled)
{
         super(id);
         this.msg = msg;
+        this.enabled = enabled;
+    }
+
+    @Override
+    public void renderHead(final IHeaderResponse response) {
+        super.renderHead(response);
+
         if (enabled) {
-            this.add(new ConfirmationModalBehavior(msg));
+            response.render(JavaScriptHeaderItem.forScript("proceed = false;", null));
+            response.render($(this).on("click",
+                    new JavaScriptInlineFunction(""
+                            + "var element = $(this);"
+                            + "evt.preventDefault();"
+                            + "if (proceed == false) {"
+                            + "  evt.stopImmediatePropagation();"
+                            + "  bootbox.confirm('" + new ResourceModel(msg).getObject()
+ "', function(result) {"
+                            + "    if (result == true) {"
+                            + "      proceed = true;"
+                            + "      element.click();"
+                            + "    } else {"
+                            + "      proceed = false;"
+                            + "    }"
+                            + "  return true;"
+                            + "  })"
+                            + "} else {"
+                            + "  proceed = false;"
+                            + "};"
+                    )).asDomReadyScript());
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/27dae836/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 c05cd68..39ab5ca 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
@@ -34,6 +34,10 @@ under the License.
 
     <script type="text/javascript" src="webjars/bootbox/${bootbox.version}/bootbox.js"></script>
     <script type="text/javascript" src="webjars/jQuery-slimScroll/${jquery-slimscroll.version}/jquery.slimscroll.min.js"></script>
+    <script type="text/javascript">
+      // global variable for IndicatingOnConfirmAjaxLink
+      var proceed = false;
+    </script>
   </head>
   <body class="skin-green-light hold-transition sidebar-mini" wicket:id="body">
 


Mime
View raw message