]> source.dussan.org Git - gitblit.git/commitdiff
Replace key feedback with label instead of FeedbackMessage
authorFlorian Zschocke <f.zschocke+git@gmail.com>
Tue, 1 Nov 2022 18:31:45 +0000 (19:31 +0100)
committerFlorian Zschocke <f.zschocke+git@gmail.com>
Tue, 1 Nov 2022 18:31:45 +0000 (19:31 +0100)
Since it is a pest to get rid of a Wicket FeedbackMessage in an AJAX target,
change the code to use an extra label that can provide feedback if the
key could not be parsed or was empty.

src/main/java/com/gitblit/wicket/pages/BasePage.java
src/main/java/com/gitblit/wicket/panels/SshKeysPanel.html
src/main/java/com/gitblit/wicket/panels/SshKeysPanel.java

index bb97ee8ccecda779693bf748c0ba43eebd97c88b..0d99f5e52956f865290f630b25252ca2f962e028 100644 (file)
@@ -251,7 +251,7 @@ public abstract class BasePage extends SessionPage {
                add(rootLink);\r
 \r
                // Feedback panel for info, warning, and non-fatal error messages\r
-               add(new FeedbackPanel("feedback").setOutputMarkupId(true));\r
+               add(new FeedbackPanel("feedback"));\r
 \r
                add(new Label("gbVersion", "v" + Constants.getVersion()));\r
                if (app().settings().getBoolean(Keys.web.aggressiveHeapManagement, false)) {\r
index d67b704aa43455065c589e73ff88dc4f6a3eef54..b6ae3ea10536125ff34c5398fc02b25d4764d56f 100644 (file)
@@ -37,7 +37,8 @@
                        <div wicket:id="addKeyData"></div>\r
                        <div wicket:id="addKeyPermission"></div>\r
                        <div wicket:id="addKeyComment"></div>\r
-               \r
+                       <div wicket:id="addKeyFeedback"></div>\r
+\r
                        <div class="form-actions"><input class="btn btn-appmenu" type="submit" value="Add" wicket:message="value:gb.add" wicket:id="addKeyButton" /></div>\r
                </form>\r
        </div>\r
index 9bcb212704dd4ade287a4f6bae7e5f7a3c14d8e5..e653a64fb97e08b5e89fd65b48ff6af317c3482e 100644 (file)
@@ -19,6 +19,8 @@ import java.util.ArrayList;
 import java.util.Arrays;\r
 import java.util.List;\r
 \r
+import com.gitblit.wicket.WicketUtils;\r
+import org.apache.wicket.Component;\r
 import org.apache.wicket.ajax.AjaxRequestTarget;\r
 import org.apache.wicket.ajax.markup.html.AjaxLink;\r
 import org.apache.wicket.ajax.markup.html.form.AjaxButton;\r
@@ -63,6 +65,7 @@ public class SshKeysPanel extends BasePanel {
 \r
                setOutputMarkupId(true);\r
 \r
+               final IModel<String> keyFeedback = Model.of("");\r
                final List<SshKey> keys = new ArrayList<SshKey>(app().keys().getKeys(user.username));\r
                final ListDataProvider<SshKey> dp = new ListDataProvider<SshKey>(keys);\r
                final DataView<SshKey> keysView = new DataView<SshKey>("keys", dp) {\r
@@ -90,6 +93,7 @@ public class SshKeysPanel extends BasePanel {
                                                        // update the panel\r
                                                        target.addComponent(SshKeysPanel.this);\r
                                                }\r
+                                               keyFeedback.setObject("");\r
                                        }\r
                                };\r
                                if (!canWriteKeys) {\r
@@ -123,6 +127,10 @@ public class SshKeysPanel extends BasePanel {
                                "span5",\r
                                keyComment));\r
 \r
+               Component addKeyFeedback = new Label("addKeyFeedback", keyFeedback).setOutputMarkupId(true);\r
+               WicketUtils.setCssStyle(addKeyFeedback, "color: red; font-weight: bold;");\r
+               addKeyForm.add(addKeyFeedback);\r
+\r
                addKeyForm.add(new AjaxButton("addKeyButton") {\r
 \r
                        private static final long serialVersionUID = 1L;\r
@@ -134,8 +142,8 @@ public class SshKeysPanel extends BasePanel {
                                String data = keyData.getObject();\r
                                if (StringUtils.isEmpty(data)) {\r
                                        // do not submit empty key\r
-                                       error(getString("gb.addSshKeyErrorEmpty"));\r
-                                       target.addComponent(getPage().get("feedback"));\r
+                                       keyFeedback.setObject(getString("gb.addSshKeyErrorEmpty"));\r
+                                       target.addComponent(addKeyFeedback);\r
                                        return;\r
                                }\r
 \r
@@ -144,8 +152,8 @@ public class SshKeysPanel extends BasePanel {
                                        key.getPublicKey();\r
                                } catch (Exception e) {\r
                                        // failed to parse the key\r
-                                       error(getString("gb.addSshKeyErrorFormat"));\r
-                                       target.addComponent(getPage().get("feedback"));\r
+                                       keyFeedback.setObject(getString("gb.addSshKeyErrorFormat"));\r
+                                       target.addComponent(addKeyFeedback);\r
                                        return;\r
                                }\r
 \r
@@ -167,9 +175,12 @@ public class SshKeysPanel extends BasePanel {
                                        keys.clear();\r
                                        keys.addAll(app().keys().getKeys(user.username));\r
 \r
+                                       keyFeedback.setObject("");\r
+\r
                                        // update the panel\r
                                        target.addComponent(SshKeysPanel.this);\r
                                }\r
+                               else keyFeedback.setObject("Key not added.");\r
                        }\r
                });\r
 \r