This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/master by this push:
     new fc5b5c1  ISIS-2093: fixes dialog ok button not receiving 'btn-danger' 
style
fc5b5c1 is described below

commit fc5b5c1d9286b4aaafb617f4585485e65cc1bb72
Author: Andi Huber <ahu...@apache.org>
AuthorDate: Tue Mar 24 11:15:26 2020 +0100

    ISIS-2093: fixes dialog ok button not receiving 'btn-danger' style
---
 .../entityactions/AdditionalLinksPanel.java        | 15 +++--
 .../components/actions/ActionParametersForm.java   | 14 ++---
 .../viewer/wicket/ui/panels/PanelAbstract.java     | 10 +---
 .../isis/viewer/wicket/ui/panels/PanelUtil.java    | 33 -----------
 .../isis/viewer/wicket/ui/util/Confirmations.java  | 64 ++++++++++++++++++++++
 5 files changed, 83 insertions(+), 53 deletions(-)

diff --git 
a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/actionmenu/entityactions/AdditionalLinksPanel.java
 
b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/actionmenu/entityactions/AdditionalLinksPanel.java
index 3b49945..a9dc733 100644
--- 
a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/actionmenu/entityactions/AdditionalLinksPanel.java
+++ 
b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/actionmenu/entityactions/AdditionalLinksPanel.java
@@ -21,6 +21,7 @@ package 
org.apache.isis.viewer.wicket.ui.components.actionmenu.entityactions;
 
 import java.util.List;
 
+import org.apache.wicket.Component;
 import org.apache.wicket.MarkupContainer;
 import org.apache.wicket.markup.html.WebMarkupContainer;
 import org.apache.wicket.markup.html.basic.Label;
@@ -37,6 +38,7 @@ import 
org.apache.isis.viewer.wicket.ui.components.actionmenu.CssClassFaBehavior
 import 
org.apache.isis.viewer.wicket.ui.components.widgets.linkandlabel.ActionLink;
 import org.apache.isis.viewer.wicket.ui.panels.PanelAbstract;
 import org.apache.isis.viewer.wicket.ui.util.Components;
+import org.apache.isis.viewer.wicket.ui.util.Confirmations;
 import org.apache.isis.viewer.wicket.ui.util.CssClassAppender;
 import org.apache.isis.viewer.wicket.ui.util.Tooltips;
 
@@ -111,7 +113,7 @@ public class AdditionalLinksPanel extends 
PanelAbstract<ListOfLinksModel> {
         container.setOutputMarkupId(true);
 
         setOutputMarkupId(true);
-
+        
         final ListView<LinkAndLabel> listView = new 
ListView<LinkAndLabel>(ID_ADDITIONAL_LINK_ITEM, linkAndLabels) {
 
             private static final long serialVersionUID = 1L;
@@ -144,13 +146,14 @@ public class AdditionalLinksPanel extends 
PanelAbstract<ListOfLinksModel> {
                 }
                 link.add(new 
CssClassAppender(linkAndLabel.getActionIdentifier()));
 
-                val semantics = linkAndLabel.getSemantics();
-                if (linkAndLabel.getParameters().isNoParameters()) {
+                if (linkAndLabel.getSemantics().isAreYouSure() 
+                        && linkAndLabel.getParameters().isNoParameters()) {
+                    
                     val hasDisabledReason = link instanceof ActionLink 
                             ? 
_Strings.isNotEmpty(((ActionLink)link).getReasonDisabledIfAny()) 
                             : false;
                     if (!hasDisabledReason) {
-                        addConfirmationDialogIfAreYouSureSemantics(link, 
semantics);
+                        addConfirmationDialog(link);
                     }
                 }
 
@@ -173,6 +176,10 @@ public class AdditionalLinksPanel extends 
PanelAbstract<ListOfLinksModel> {
 
         container.addOrReplace(listView);
     }
+    
+    private void addConfirmationDialog(final Component component) {
+        Confirmations.addConfirmationDialog(super.getTranslationService(), 
component);
+    }
 
     private static String first(String... str) {
         for (String s : str) {
diff --git 
a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/actions/ActionParametersForm.java
 
b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/actions/ActionParametersForm.java
index 7d9e683..40464d4 100644
--- 
a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/actions/ActionParametersForm.java
+++ 
b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/actions/ActionParametersForm.java
@@ -29,7 +29,6 @@ import org.apache.wicket.markup.html.WebMarkupContainer;
 import org.apache.wicket.markup.html.form.Form;
 import org.apache.wicket.markup.repeater.RepeatingView;
 
-import org.apache.isis.applib.annotation.SemanticsOf;
 import org.apache.isis.core.commons.internal.exceptions._Exceptions;
 import org.apache.isis.core.metamodel.consent.InteractionInitiatedBy;
 import org.apache.isis.core.metamodel.spec.feature.ObjectAction;
@@ -41,8 +40,8 @@ import org.apache.isis.viewer.wicket.model.models.ActionModel;
 import org.apache.isis.viewer.wicket.ui.ComponentType;
 import 
org.apache.isis.viewer.wicket.ui.components.scalars.ScalarPanelAbstract2;
 import org.apache.isis.viewer.wicket.ui.panels.FormExecutorStrategy;
-import org.apache.isis.viewer.wicket.ui.panels.PanelUtil;
 import org.apache.isis.viewer.wicket.ui.panels.PromptFormAbstract;
+import org.apache.isis.viewer.wicket.ui.util.Confirmations;
 import org.apache.isis.viewer.wicket.ui.util.CssClassAppender;
 
 import lombok.val;
@@ -151,11 +150,12 @@ class ActionParametersForm extends 
PromptFormAbstract<ActionModel> {
      * @param button The button which action should be confirmed
      */
     private void applyAreYouSure(AjaxButton button) {
-        ActionModel actionModel = getActionModel();
-        final ObjectAction action = 
actionModel.getActionMemento().getAction(getSpecificationLoader());
-        SemanticsOf semanticsOf = action.getSemantics();
-
-        
PanelUtil.addConfirmationDialogIfAreYouSureSemantics(super.getTranslationService(),
 button, semanticsOf);
+        val actionModel = getActionModel();
+        val action = 
actionModel.getActionMemento().getAction(getSpecificationLoader());
+        
+        if (action.getSemantics().isAreYouSure()) {
+            Confirmations.addConfirmationDialog(super.getTranslationService(), 
button);
+        }
     }
 
     @Override
diff --git 
a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/panels/PanelAbstract.java
 
b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/panels/PanelAbstract.java
index 271935e..4f22aa0 100644
--- 
a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/panels/PanelAbstract.java
+++ 
b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/panels/PanelAbstract.java
@@ -28,6 +28,7 @@ import org.apache.wicket.model.IModel;
 import org.apache.isis.applib.annotation.SemanticsOf;
 import org.apache.isis.viewer.wicket.ui.ComponentType;
 import org.apache.isis.viewer.wicket.ui.util.Components;
+import org.apache.isis.viewer.wicket.ui.util.Confirmations;
 
 /**
  * Convenience adapter for {@link Panel}s built up using {@link 
ComponentType}s.
@@ -103,14 +104,5 @@ extends PanelBase/*<IModel<X>>*/ {
         }
         component.setVisible(visible);
     }
-    
-    protected void addConfirmationDialogIfAreYouSureSemantics(
-            Component component, 
-            SemanticsOf semanticsOf) {
-        
-        PanelUtil.addConfirmationDialogIfAreYouSureSemantics(
-                super.getTranslationService(), component, semanticsOf);
-    }
-
 
 }
diff --git 
a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/panels/PanelUtil.java
 
b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/panels/PanelUtil.java
index 8e164bd..07d0c8c 100644
--- 
a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/panels/PanelUtil.java
+++ 
b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/panels/PanelUtil.java
@@ -26,14 +26,7 @@ import org.apache.wicket.markup.head.CssReferenceHeaderItem;
 import org.apache.wicket.markup.head.IHeaderResponse;
 import org.apache.wicket.request.resource.CssResourceReference;
 
-import org.apache.isis.applib.annotation.SemanticsOf;
-import org.apache.isis.applib.services.i18n.TranslationService;
 import org.apache.isis.core.commons.internal.base._Strings;
-import org.apache.isis.core.config.messages.MessageRegistry;
-
-import 
de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipConfig;
-import 
de.agilecoders.wicket.extensions.markup.html.bootstrap.confirmation.ConfirmationBehavior;
-import 
de.agilecoders.wicket.extensions.markup.html.bootstrap.confirmation.ConfirmationConfig;
 
 public final class PanelUtil {
 
@@ -87,30 +80,4 @@ public final class PanelUtil {
                 .onComplete("$('#" + ajaxButtonOrLink.getMarkupId() + 
"').prop('disabled',false);"));
     }
 
-    public static void addConfirmationDialogIfAreYouSureSemantics(
-            TranslationService translationService,
-            Component component,
-            SemanticsOf semanticsOf) {
-
-        if (!semanticsOf.isAreYouSure()) {
-            return;
-        }
-
-        ConfirmationConfig confirmationConfig = new ConfirmationConfig();
-
-        final String context = MessageRegistry.class.getName();
-        final String areYouSure = translationService.translate(context, 
MessageRegistry.MSG_ARE_YOU_SURE);
-        final String confirm = translationService.translate(context, 
MessageRegistry.MSG_CONFIRM);
-        final String cancel = translationService.translate(context, 
MessageRegistry.MSG_CANCEL);
-
-        confirmationConfig
-        .withTitle(areYouSure)
-        .withBtnOkLabel(confirm)
-        .withBtnCancelLabel(cancel)
-        .withPlacement(TooltipConfig.Placement.right)
-        .withBtnOkClass("btn btn-danger")
-        .withBtnCancelClass("btn btn-default");
-
-        component.add(new ConfirmationBehavior(confirmationConfig));
-    }
 }
diff --git 
a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/util/Confirmations.java
 
b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/util/Confirmations.java
new file mode 100644
index 0000000..f9378bb
--- /dev/null
+++ 
b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/util/Confirmations.java
@@ -0,0 +1,64 @@
+/*
+ *  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.isis.viewer.wicket.ui.util;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.markup.html.form.Button;
+
+import org.apache.isis.applib.services.i18n.TranslationService;
+import org.apache.isis.core.config.messages.MessageRegistry;
+
+import lombok.val;
+
+import 
de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipConfig;
+import 
de.agilecoders.wicket.extensions.markup.html.bootstrap.confirmation.ConfirmationBehavior;
+import 
de.agilecoders.wicket.extensions.markup.html.bootstrap.confirmation.ConfirmationConfig;
+
+public class Confirmations {
+
+    public static void addConfirmationDialog(
+            final TranslationService translationService,
+            final Component component) {
+
+        val confirmationConfig = new ConfirmationConfig();
+
+        final String context = MessageRegistry.class.getName();
+        final String areYouSure = translationService.translate(context, 
MessageRegistry.MSG_ARE_YOU_SURE);
+        final String confirm = translationService.translate(context, 
MessageRegistry.MSG_CONFIRM);
+        final String cancel = translationService.translate(context, 
MessageRegistry.MSG_CANCEL);
+
+        confirmationConfig
+        .withTitle(areYouSure)
+        .withBtnOkLabel(confirm)
+        .withBtnCancelLabel(cancel)
+        .withPlacement(TooltipConfig.Placement.right)
+        .withBtnOkClass("btn btn-danger")
+        .withBtnCancelClass("btn btn-default");
+
+        component.add(new ConfirmationBehavior(confirmationConfig));
+        
+        if(component instanceof Button) {
+            // ensure dialog ok buttons receive the danger style as well
+            // don't care if expressed twice
+            component.add(new CssClassAppender("btn-danger"));
+        }
+        
+    }
+    
+}

Reply via email to